Module: GoogleBooks

Includes:
HTTParty
Defined in:
lib/version.rb,
lib/book/item.rb,
lib/googlebooks.rb,
lib/book/response.rb

Defined Under Namespace

Classes: Item, Response

Constant Summary collapse

VERSION =
"0.0.9"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.parametersObject

Returns the value of attribute parameters.



14
15
16
# File 'lib/googlebooks.rb', line 14

def parameters
  @parameters
end

Class Method Details

.search(query, options = {}, remote_ip = nil) ⇒ Object

3rd parameter optionally passes user’s IP address



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/googlebooks.rb', line 30

def search(query, options = {}, remote_ip = nil)
  (headers 'X-Forwarded-For' => remote_ip.to_s) unless remote_ip.nil?
  self.parameters = { 'q' => query }
  options[:page] ||= 1
  options[:count] ||= 5
  parameters['filter'] = options[:filter] if options[:filter]
  parameters['startIndex'] = options[:count] * (options[:page] - 1)
  parameters['maxResults'] = options[:count]
  parameters['key'] = options[:api_key] if options[:api_key]
  parameters['orderBy'] = 'newest' if options[:order_by].eql?('newest')
  parameters['country'] = options[:country]

  Response.new(get(url.to_s))
end