Class: OmniAuth::Strategies::Goodreads
- Defined in:
- lib/omniauth/strategies/goodreads.rb
Instance Attribute Summary
Attributes inherited from OAuth
#consumer_key, #consumer_options, #consumer_secret, #name
Instance Method Summary collapse
- #auth_hash ⇒ Object
-
#initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block) ⇒ Goodreads
constructor
A new instance of Goodreads.
- #user_hash(access_token) ⇒ Object
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.
8 9 10 11 12 13 14 |
# File 'lib/omniauth/strategies/goodreads.rb', line 8 def initialize(app, consumer_key = nil, consumer_secret = nil, = {}, &block) = { :site => 'http://www.goodreads.com', } @consumer_key = consumer_key super(app, :goodreads, consumer_key, consumer_secret, , , &block) end |
Instance Method Details
#auth_hash ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/omniauth/strategies/goodreads.rb', line 16 def auth_hash hash = user_hash(@access_token) OmniAuth::Utils.deep_merge(super, { 'uid' => hash.delete('id'), 'user_info' => hash }) end |
#user_hash(access_token) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/omniauth/strategies/goodreads.rb', line 25 def user_hash(access_token) authenticated_user = MultiXml.parse(@access_token.get('/api/auth_user').body) id = authenticated_user.xpath('GoodreadsResponse/user').attribute('id').value.to_i response_doc = MultiXml.parse(open("http://www.goodreads.com/user/show/#{id}.xml?key=#{@consumer_key}").read) user = response_doc.xpath('GoodreadsResponse/user') hash = { 'id' => id, 'name' => user.xpath('name').text, 'user_name' => user.xpath('user_name').text, 'image_url' => user.xpath('image_url').text, 'about' => user.xpath('about').text, 'location' => user.xpath('location').text, 'website' => user.xpath('website').text, } end |