class Bestsellers::List

Constants

BOOKS_URL

Public Class Methods

new() click to toggle source
# File lib/nytimes_bestsellers/client.rb, line 15
def initialize
  reset
end

Public Instance Methods

age_groups() click to toggle source
# File lib/nytimes_bestsellers/client.rb, line 88
def age_groups
  HTTParty.get(BOOKS_URL + "/age-groups?api-key=#{api_key}")
end
bestseller_lists_overview(o = {}) click to toggle source
# File lib/nytimes_bestsellers/client.rb, line 63
def bestseller_lists_overview(o = {})
  date = (Date.parse o[:date] || Date.today).strftime('%Y-%m-%e')

  HTTParty.get(BOOKS_URL + "/overview?published_date=#{date}&api-key=#{api_key}")
end
find_list_names() click to toggle source
# File lib/nytimes_bestsellers/client.rb, line 84
def find_list_names
  HTTParty.get(BOOKS_URL + "/names?api-key=#{api_key}")
end
get_list(list_name, o = {}) click to toggle source
# File lib/nytimes_bestsellers/client.rb, line 24
def get_list(list_name, o = {})
  url = BOOKS_URL.clone

  if o[:date]
    date = o[:date]
    url << "/#{date}"
  end
  
  url << "/#{list_name.gsub(/ /, '-')}?"

  [:offset, :sort_by, :sort_order].each do |thing|
    set_urlparam(url, thing, o)
  end

  url << "&api-key=#{api_key}"

  HTTParty.get(url)
end
search_list(list_name, o = {}) click to toggle source
# File lib/nytimes_bestsellers/client.rb, line 43
def search_list(list_name, o = {})

  url = BOOKS_URL.clone + "?list-name=#{list_name.gsub(/ /, '-')}"

  date = if o[:date]
    Date.parse(o[:date]) 
  else
    Date.today
  end.strftime('%Y-%m-%e')
  url << "&date=#{date}"

  [:isbn, :published_date, :rank, :rank_last_week, :weeks_on_list, :offset, :sort_by, :sort_order].each do |thing|
    set_urlparam(url, thing, o)
  end

  url << "&api-key=#{api_key}"

 HTTParty.get(url)
end
set_urlparam(url, name, options) click to toggle source
# File lib/nytimes_bestsellers/client.rb, line 19
def set_urlparam(url, name, options)
  return unless options[name]
  url << "&#{name.to_s.gsub('_','-')}=#{options[name].gsub(/ /, '-')}"
 end
single_history(o = {}) click to toggle source
# File lib/nytimes_bestsellers/client.rb, line 69
def single_history(o = {})

  url = BOOKS_URL.clone + "/best-sellers/history"

  url << "?"

  [:author, :publisher, :title, :age_group, :contributor, :isbn, :price, :sort_by, :sort_order].each do |thing|
    set_urlparam(url, thing, o)
  end

  url << "&api-key=#{api_key}"

  HTTParty.get(url)
end