Class: Grobi::Books
- Inherits:
-
Object
- Object
- Grobi::Books
- Defined in:
- lib/grobi/books.rb
Instance Method Summary collapse
-
#initialize(client) ⇒ Books
constructor
A new instance of Books.
- #parse(s) ⇒ Object
- #retrieve(string_or_book) ⇒ Object
- #search(string) ⇒ Object
Constructor Details
#initialize(client) ⇒ Books
Returns a new instance of Books.
3 4 5 6 7 8 9 10 11 12 |
# File 'lib/grobi/books.rb', line 3 def initialize(client) @client = client begin @book = @client.google.discovered_api('books') if @client rescue => the_error @error = the_error. puts "Error #{the_error.}" return nil end end |
Instance Method Details
#parse(s) ⇒ Object
37 38 39 40 |
# File 'lib/grobi/books.rb', line 37 def parse(s) volumes = JSON.parse(s) volumes['items'].collect { |v| Book.new(v) } if volumes['items'] end |
#retrieve(string_or_book) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/grobi/books.rb', line 22 def retrieve(string_or_book) if string_or_book.is_a?(String) identifier = string_or_book book = Book.new elsif string_or_book.is_a?(Book) identifier = string_or_book.id book = string_or_book else return nil end response = @client.google.execute(@book.volumes.get, {:volumeId => identifier, :key => @client.simple_api_key}) book.update(JSON.parse(response.body)) book end |
#search(string) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/grobi/books.rb', line 14 def search(string) return nil if @client.nil? || @client.simple_api_key.nil? # disable OAuth2 @client.google. = nil if @client.simple_api_key response = @client.google.execute(@book.volumes.list, {:q => string, :key => @client.simple_api_key}) parse(response.body) end |