Class: OmniAuth::Strategies::Mailchimp

Inherits:
OAuth2
  • Object
show all
Defined in:
lib/omniauth/strategies/oauth2/mailchimp.rb

Instance Attribute Summary

Attributes inherited from OAuth2

#client_id, #client_options, #client_secret, #options

Instance Method Summary collapse

Methods inherited from OAuth2

#callback_url, #client

Constructor Details

#initialize(app, client_id = nil, client_secret = nil, options = {}, &block) ⇒ Mailchimp

Returns a new instance of Mailchimp.



8
9
10
11
12
13
14
# File 'lib/omniauth/strategies/oauth2/mailchimp.rb', line 8

def initialize(app, client_id=nil, client_secret=nil, options={}, &block)
  client_options = {
    :authorize_url => 'https://login.mailchimp.com/oauth2/authorize',
    :token_url => 'https://login.mailchimp.com/oauth2/token',
  }
  super(app, :mailchimp, client_id, client_secret, client_options, options, &block)
end

Instance Method Details

#auth_hashObject



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/omniauth/strategies/oauth2/mailchimp.rb', line 16

def auth_hash
  data = user_data
  OmniAuth::Utils.deep_merge(
    super, {
      'uid' => @access_token.client.id,
      'extra'=> {
        'user_hash' => data
      }
    }
  )
end

#user_dataObject



28
29
30
31
32
33
34
35
36
# File 'lib/omniauth/strategies/oauth2/mailchimp.rb', line 28

def user_data
  @data ||=  MultiJson.decode(@access_token.get("https://login.mailchimp.com/oauth2/metadata").body)
rescue ::OAuth2::Error => e
  if e.response.status == 302
    @data ||= MultiJson.decode(@access_token.get(e.response.headers['location']))
  else
    raise e
  end
end