Class: GoogleBooks::Response
- Inherits:
-
Object
- Object
- GoogleBooks::Response
- Includes:
- Enumerable
- Defined in:
- lib/book/response.rb
Instance Method Summary collapse
-
#each(&block) ⇒ Object
Returns nil if no records are returned.
-
#initialize(response) ⇒ Response
constructor
A new instance of Response.
-
#total_items ⇒ Object
Total items returnable based on query, not total items in response (which is throttled by maxResults).
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_items ⇒ Object
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 |