Class: UsaTodayBooks::BestSellers

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/usa_today_books/best_sellers.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ BestSellers

Returns a new instance of BestSellers.



9
10
11
# File 'lib/usa_today_books/best_sellers.rb', line 9

def initialize(options={})
  @api_key = options[:api_key] || UsaTodayBooks.api_key
end

Instance Attribute Details

#api_keyObject (readonly)

Returns the value of attribute api_key.



7
8
9
# File 'lib/usa_today_books/best_sellers.rb', line 7

def api_key
  @api_key
end

Instance Method Details

#booklists(options = {}) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/usa_today_books/best_sellers.rb', line 32

def booklists(options={}) 
  year = options.delete(:year)
  month = options.delete(:month)     
  date = options.delete(:date)
  
  if year && month && date
    endpoint = "/booklists/#{year}/#{month}/#{date}"
  elsif year && month.nil? && date.nil?
    endpoint = "/booklists/#{year}"
  elsif month && year && date.nil?
    endpoint = "/booklists/#{year}/#{month}"
  else
    endpoint = "/booklists"
  end
    
  mashup(self.class.get(endpoint, :query => options.merge(self.default_options)))
end

#categories(options = {}) ⇒ Object



50
51
52
# File 'lib/usa_today_books/best_sellers.rb', line 50

def categories(options={})        
  mashup(self.class.get("/categories", :query => options.merge(self.default_options)))
end

#classes(options = {}) ⇒ Object



54
55
56
# File 'lib/usa_today_books/best_sellers.rb', line 54

def classes(options={})        
  mashup(self.class.get("/classes", :query => options.merge(self.default_options)))
end

#dates(options = {}) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/usa_today_books/best_sellers.rb', line 13

def dates(options={})
  year = options.delete(:year)
  month = options.delete(:month)      
  minyear = options.delete(:minyear)
  maxyear = options.delete(:maxyear)
  
  options = {:minyear => minyear, :maxyear => maxyear}
  
  if year && month
    endpoint = "/dates/#{year}/#{month}"
  elsif year && month.nil?
    endpoint = "/dates/#{year}"
  else
    endpoint = "/dates"
  end
    
  mashup(self.class.get(endpoint, :query => options.merge(self.default_options)))
end

#titles(options = {}) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/usa_today_books/best_sellers.rb', line 58

def titles(options={})        
  title = options.delete(:title)
  isbn = options.delete(:isbn)
  
  if title
    endpoint = "/titles/#{title}"
  elsif isbn
    endpoint = "/titles/#{isbn}"
  else
    endpoint = "/titles"
  end
  
  mashup(self.class.get(endpoint, :query => options.merge(self.default_options)))
end