Module: GoogleBook
- Includes:
- HTTParty
- Defined in:
- lib/googlebook/finder.rb,
lib/googlebook/book.rb,
lib/googlebook/images.rb,
lib/googlebook/version.rb
Overview
A classy finder
Defined Under Namespace
Constant Summary collapse
- VERSION =
'0.1.5'
Class Attribute Summary collapse
-
.parameters ⇒ Object
Query parameters passed on to Google.
-
.response ⇒ Object
The query response.
-
.total_results ⇒ Object
Total results for query.
Class Method Summary collapse
-
.find(query, opts = {}) ⇒ Object
Queries the Google Book Search Data API.
Class Attribute Details
.parameters ⇒ Object
Query parameters passed on to Google
12 13 14 |
# File 'lib/googlebook/finder.rb', line 12 def parameters @parameters end |
.response ⇒ Object
The query response
18 19 20 |
# File 'lib/googlebook/finder.rb', line 18 def response @response end |
.total_results ⇒ Object
Total results for query
15 16 17 |
# File 'lib/googlebook/finder.rb', line 15 def total_results @total_results end |
Class Method Details
.find(query, opts = {}) ⇒ Object
Queries the Google Book Search Data API.
Optionally, specify a page and count to paginate through the result set.
GoogleBook.find('deleuze', :page => 2, :count => 20)
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/googlebook/finder.rb', line 27 def find(query, opts={}) self.parameters = { 'q' => query } if opts[:page] && opts[:page].to_i > 0 parameters['start-index'] = opts[:page] end if opts[:count] && (10..20).include?(opts[:count].to_i) parameters['max-results'] = opts[:count] end self.response = self.get(uri.to_s) self.total_results = response['feed']['openSearch:totalResults'].to_i response['feed']['entry'].map do |book| Book.new( Images.new(book['link'][0]['href']), book['link'][1]['href'], book['link'][2]['href'], [book['dc:creator']].flatten.join(', '), book['dc:date'], book['dc:description'], [book['dc:format']].flatten.reject { |format| format == 'book' }.join(', '), book['dc:identifier'], book['dc:publisher'], book['dc:subject'], [book['dc:title']].flatten.join(': ')) end end |