Class: GoogleBooks::Response

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/book/response.rb

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Response

Returns a new instance of Response.



7
8
9
# File 'lib/book/response.rb', line 7

def initialize(response)
  @response = response
end

Instance Method Details

#each(&block) ⇒ Object

Returns nil if no records are returned. Otherwise, response returns hash of generally unusable Google API specific data.



13
14
15
16
17
18
# File 'lib/book/response.rb', line 13

def each(&block)
  return [] if total_items == 0
  @response['items'].each do |item|
    block.call(Item.new(item))
  end
end

#total_itemsObject

Total items returnable based on query, not total items in response (which is throttled by maxResults)



22
23
24
# File 'lib/book/response.rb', line 22

def total_items
  @response['totalItems'].to_i
end