Skip to content

Commit

Permalink
Using v2 account/info endpoint to fetch account data
Browse files Browse the repository at this point in the history
  • Loading branch information
djellesma committed Sep 20, 2014
1 parent 3222701 commit 3e71cff
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
2 changes: 1 addition & 1 deletion lib/omniauth-constantcontact2/version.rb
@@ -1,5 +1,5 @@
module Omniauth
module ConstantContact2
VERSION = "1.0.4"
VERSION = "1.0.5"
end
end
20 changes: 9 additions & 11 deletions lib/omniauth/strategies/constantcontact2.rb
Expand Up @@ -8,6 +8,7 @@ class ConstantContact2 < OmniAuth::Strategies::OAuth2

DEFAULT_RESPONSE_TYPE = 'code'
DEFAULT_GRANT = 'authorization_code'
API_PATH = 'https://api.constantcontact.com/v2'

option :name, "constantcontact"

Expand Down Expand Up @@ -37,24 +38,21 @@ def token_params
end

info do
entries = raw_info['feed']['entry']
if entries.kind_of?(Array)
{
:email_entries => entries.map{|x|x["content"]["Email"]["EmailAddress"]}
}
else
{
:email => entries["content"]["Email"]["EmailAddress"]
}
end
{
email: raw_info['email']
}
end

extra do
{ 'raw_info' => raw_info }
end

def raw_info
@raw_info ||= MultiXml.parse(access_token.get("https://api.constantcontact.com/ws/customers/" + request.params['username'] + "/settings/emailaddresses").body)
options = {
params: {api_key: client.id},
headers: {'Authorization' => "Bearer #{access_token.token}"}
}
@raw_info ||= JSON.parse(access_token.get("#{API_PATH}/account/info", options).body)
end
end
end
Expand Down

0 comments on commit 3e71cff

Please sign in to comment.