Class: OmniAuth::Strategies::Goodreads

Inherits:
OAuth
  • Object
show all
Defined in:
lib/omniauth/strategies/oauth/goodreads.rb

Instance Attribute Summary

Attributes inherited from OAuth

#consumer_key, #consumer_options, #consumer_secret, #name

Instance Method Summary collapse

Methods inherited from OAuth

#callback_phase, #consumer, #request_phase, #unique_id

Constructor Details

#initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block) ⇒ Goodreads

Returns a new instance of Goodreads.



7
8
9
10
11
12
13
# File 'lib/omniauth/strategies/oauth/goodreads.rb', line 7

def initialize(app, consumer_key=nil, consumer_secret=nil, options={}, &block)
  client_options = {
    :site => 'http://www.goodreads.com',
  }
  @consumer_key = consumer_key
  super(app, :goodreads, consumer_key, consumer_secret, client_options, options, &block)
end

Instance Method Details

#auth_hashObject



15
16
17
18
19
20
21
22
23
24
# File 'lib/omniauth/strategies/oauth/goodreads.rb', line 15

def auth_hash
  hash = (@access_token)

  OmniAuth::Utils.deep_merge(
    super, {
      'uid' => hash.delete('id'),
      'user_info' => hash,
    }
  )
end

#user_info(access_token) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/omniauth/strategies/oauth/goodreads.rb', line 26

def (access_token)
  authenticated_user = MultiXml.parse(access_token.get('/api/auth_user').body)
  id = authenticated_user['GoodreadsResponse']['user']['id'].to_i
  response_doc = MultiXml.parse(access_token.get("/user/show/#{id}.xml?key=#{@consumer_key}").body)
  user = response_doc['GoodreadsResponse']['user']

  hash = {
    'id' => id,
    'name' => user['name'],
    'user_name' => user['user_name'],
    'image_url' => user['image_url'],
    'about' => user['about'],
    'location' => user['location'],
    'website' => user['website'],
  }
end