Class: Goodreads::Client

Inherits:
Object
  • Object
show all
Includes:
Authorized, Authors, Books, Friends, Groups, Request, Reviews, Shelves, Users
Defined in:
lib/goodreads/client.rb

Constant Summary

Constants included from Request

Request::API_FORMAT, Request::API_URL

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Friends

#friends

Methods included from Groups

#group, #group_list

Methods included from Authorized

#user_id

Methods included from Shelves

#add_to_shelf, #shelf, #shelves

Methods included from Users

#user

Methods included from Authors

#author, #author_by_name

Methods included from Reviews

#create_review, #edit_review, #recent_reviews, #review, #reviews, #user_review

Methods included from Books

#book, #book_by_isbn, #book_by_title, #search_books

Constructor Details

#initialize(options = {}) ⇒ Client

Initialize a Goodreads::Client instance

options - Account API key options - Account API secret options - OAuth access token (optional, required for some calls)



31
32
33
34
35
36
37
# File 'lib/goodreads/client.rb', line 31

def initialize(options = {})
  fail(ArgumentError, "Options hash required.") unless options.is_a?(Hash)

  @api_key     = options[:api_key] || Goodreads.configuration[:api_key]
  @api_secret  = options[:api_secret] || Goodreads.configuration[:api_secret]
  @oauth_token = options[:oauth_token]
end

Instance Attribute Details

#api_keyObject (readonly)

Returns the value of attribute api_key.



23
24
25
# File 'lib/goodreads/client.rb', line 23

def api_key
  @api_key
end

#api_secretObject (readonly)

Returns the value of attribute api_secret.



23
24
25
# File 'lib/goodreads/client.rb', line 23

def api_secret
  @api_secret
end

#oauth_tokenObject (readonly)

Returns the value of attribute oauth_token.



23
24
25
# File 'lib/goodreads/client.rb', line 23

def oauth_token
  @oauth_token
end

Instance Method Details

#oauth_configured?Boolean

Return if this client is configured with OAuth credentials for a single user

False when client is instantiated with an api_key and secret, true when client is instantiated with an oauth_token

Returns:

  • (Boolean)


44
45
46
# File 'lib/goodreads/client.rb', line 44

def oauth_configured?
  !oauth_token.nil?
end