nytimes-bestsellers 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +21 -0
- data/README.md +108 -0
- data/Rakefile +8 -0
- data/lib/nytimes_bestsellers.rb +19 -0
- data/lib/nytimes_bestsellers/client.rb +93 -0
- data/lib/nytimes_bestsellers/configuration.rb +15 -0
- data/lib/nytimes_bestsellers/version.rb +3 -0
- data/spec/nytimes_bestsellers_spec.rb +19 -0
- data/spec/spec_helper.rb +30 -0
- metadata +52 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 62ef4d25e237bdc6d28445e742d51e8b80d5c8b8
|
4
|
+
data.tar.gz: ba50cdb4811ecf0083b7cb15090b3a75dca96020
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6875cd69164943cbdf426bdcf6b8ee703f323678357c30e0764de2f49a5684ffb008330f820c33092125801c56c285516fd1f872770eee40b536b7594331cc94
|
7
|
+
data.tar.gz: 9aa2f1360be38010167758a6a5e7b9b0ba354c928962978e90730913cd5ea3f80bf99ca21f1fee5959deb401226a72dfdafacebe3986a1791fe68eabade75d70
|
data/Gemfile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
gem 'httparty'
|
4
|
+
gem 'dotenv'
|
5
|
+
gem 'rake'
|
6
|
+
|
7
|
+
group :development do
|
8
|
+
gem "shoulda", ">= 0"
|
9
|
+
gem "pry"
|
10
|
+
gem "rdoc", "~> 3.12"
|
11
|
+
gem "bundler", "~> 1.0"
|
12
|
+
gem "simplecov"
|
13
|
+
end
|
14
|
+
|
15
|
+
group :test do
|
16
|
+
gem 'rspec'
|
17
|
+
gem 'shoulda-matchers'
|
18
|
+
gem 'webmock'
|
19
|
+
gem 'simplecov'
|
20
|
+
gem 'coveralls', require: false
|
21
|
+
end
|
data/README.md
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
[![Build Status](https://travis-ci.org/enspencer/nytimes-bestsellers.png?branch=master)](https://travis-ci.org/enspencer/nytimes-bestsellers) [![Coverage Status](https://coveralls.io/repos/enspencer/nytimes-bestsellers/badge.png)](https://coveralls.io/r/enspencer/nytimes-bestsellers)
|
2
|
+
|
3
|
+
# New York Times Bestsellers
|
4
|
+
|
5
|
+
A Ruby gem for accessing the [New York Times Bestsellers API](http://developer.nytimes.com/docs/best_sellers_api).
|
6
|
+
|
7
|
+
## Install
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'nytimes-bestsellers'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install nytimes-bestsellers
|
20
|
+
|
21
|
+
## Getting Started
|
22
|
+
|
23
|
+
You'll want to sign up for an [API key](http://developer.nytimes.com/apps/register) to start.
|
24
|
+
|
25
|
+
Setup a new instance:
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
@client = Bestsellers.new
|
29
|
+
@client.configure do |config|
|
30
|
+
config.api_key = "YOUR_API_KEY"
|
31
|
+
end
|
32
|
+
```
|
33
|
+
|
34
|
+
and do your thing!
|
35
|
+
|
36
|
+
## Methods
|
37
|
+
|
38
|
+
Six requests are available: get a bestseller list, get an overview of all of the best-seller lists for a given week, search a bestseller list, get the history of a single bestseller, get the names of all Times best-seller lists, and get the age group options that can be used as a parameter in the `single history` method.
|
39
|
+
|
40
|
+
### get_list(list_name, o = {})
|
41
|
+
|
42
|
+
This method has a required parameter of list name(see lists below or call the find_list_names method to find them for yourself) and takes an optional parameter of date, as a string in YYYY-MM-DD format. It also takes an optional parameter of response format and if none is specified it defaults to json.
|
43
|
+
|
44
|
+
with no optional parameters it gets the most recent list
|
45
|
+
`@client.get_list('hardcover-nonfiction')`
|
46
|
+
|
47
|
+
it can take optional parameters
|
48
|
+
`@client.get_list('hardcover-nonfiction', date: '2012-04-12', response: 'xml')`
|
49
|
+
|
50
|
+
### bestseller_lists_overview()
|
51
|
+
|
52
|
+
Returns an overview of Times best-seller lists for a single week. Takes an optional parameter of date in YYYY-MM-DD format. If you do not specify a published_date the most recent week's best-seller list will be returned.
|
53
|
+
|
54
|
+
`@client.bestseller_lists_overview`
|
55
|
+
`@client.bestseller_lists_overview(date: '2012-04-12')`
|
56
|
+
|
57
|
+
|
58
|
+
### search_list(list_name, o = {})
|
59
|
+
|
60
|
+
Allows for a filtered search of a specific list. Optional parameters are date, isbn, published_date, rank, rank_last_week, and weeks_on_list.
|
61
|
+
|
62
|
+
`@client.search_list('hardcover-nonfiction', published_date: "2013-04-12")`
|
63
|
+
|
64
|
+
### single_history()
|
65
|
+
|
66
|
+
Returns up to 20 weeks of history for a bestseller (its rank and number of weeks on the various Times best-seller lists). Takes one or more of the following parameters: , author, contributor, isbn, price, publisher, title, age_group(see below for age group options).
|
67
|
+
|
68
|
+
`@client.single_history(author: 'rachel maddow')`
|
69
|
+
|
70
|
+
|
71
|
+
### find_list_names
|
72
|
+
|
73
|
+
This method takes no parameters and returns all available list names which you can use to query the get_list method. These names can be used as the required list_name parameter for get_list and single_history.
|
74
|
+
|
75
|
+
`@client.find_list_names`
|
76
|
+
|
77
|
+
### age_groups
|
78
|
+
|
79
|
+
This method takes no parameters and returns all available age groups which you can use to query the single_history method. In most cases the age group will be null, so it's not a great search method on the data. I've listen the age groups below but you can see these available age groups for yourself using the `age_groups` method.
|
80
|
+
|
81
|
+
`@client.age_groups`
|
82
|
+
|
83
|
+
|
84
|
+
## Lists
|
85
|
+
|
86
|
+
The list names to search from are:
|
87
|
+
|
88
|
+
Combined Print and E-Book Fiction, Combined Print and E-Book Nonfiction, Hardcover Fiction, Hardcover Nonfiction, Trade Fiction Paperback, Mass Market Paperback, Paperback Nonfiction, E-Book Fiction, E-Book Nonfiction, Hardcover Advice, Paperback Advice, Advice How-To and Miscellaneous, Picture Books, Chapter Books, Childrens Middle Grade, Young Adult, Paperback Books, Series Books, Hardcover Graphic Books, Paperback Graphic Books, Manga, Combined Print Fiction, Combined Print Nonfiction, Hardcover Business Books, Paperback Business Books, Business Books, Hardcover Political Books, Science Times, Dining
|
89
|
+
|
90
|
+
You can pass these names with spaces or replace spaces with hyphens, either works. The parameter is not case sensitive.
|
91
|
+
|
92
|
+
## Age Groups
|
93
|
+
|
94
|
+
The age group parameter can be used as an optional parameter in the `single_history` method. In most cases the age group will be null, so it's not a great search method on the data. But you can use the age groups below to search, or see these available age groups for yourself using the `age_groups` method.
|
95
|
+
|
96
|
+
Valid age groups: "Ages 1 to 5", "Ages 10 and up", "Ages 10 to 13", "Ages 10 to 14", "Ages 10 to 15", "Ages 10 to 18", "Ages 11 and up", "Ages 11 to 14", "Ages 11 to 15", "Ages 12 and up", "Ages 12 and up", "Ages 12 to 14", "Ages 12 to 17", "Ages 12 to 18", "Ages 13 and up", "Ages 13 to 16", "Ages 13 to 17", "Ages 13 to 18", "Ages 14 and up", "Ages 14 to 17", "Ages 14 to 18", "Ages 15 and up", "Ages 15 to 17", "Ages 15 to 18", "Ages 16 and up", "Ages 17 and up", "Ages 18 and up", "Ages 2 and up", "Ages 2 to 5", "Ages 2 to 6", "Ages 2 to 7", "Ages 3 and up", "Ages 3 to 5", "Ages 3 to 6", "Ages 3 to 7", "Ages 3 to 8, "Ages 4 and up", "Ages 4 to 7", "Ages 4 to 8", "Ages 5 and up", "Ages 5 to 10"}, "Ages 5 to 7", "Ages 5 to 8", "Ages 5 to 9", "Ages 6 and up", "Ages 6 to 10"}, "Ages 6 to 12"}, "Ages 6 to 14", "Ages 6 to 8", "Ages 6 to 9", "Ages 7 and up", "Ages 7 to 10", "Ages 7 to 12", "Ages 7 to 17", "Ages 7 to 9", "Ages 8 and up", "Ages 8 to 12", "Ages 8 to 14", "Ages 9 and up", "Ages 9 to 11", "Ages 9 to 12", "Ages 9 to 13", "All ages"
|
97
|
+
|
98
|
+
## Contributing
|
99
|
+
|
100
|
+
1. Fork it
|
101
|
+
2. Create your feature branch (`git checkout -b feature`)
|
102
|
+
3. Commit your changes (`git commit -m 'Add this feature'`)
|
103
|
+
4. Push to the branch (`git push origin feature`)
|
104
|
+
5. Create new Pull Request
|
105
|
+
|
106
|
+
## License
|
107
|
+
|
108
|
+
Copyright © 2013 Emma Spencer. See LICENSE.txt for further details.
|
data/Rakefile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'nytimes_bestsellers/client'
|
2
|
+
|
3
|
+
module Bestsellers
|
4
|
+
class << self
|
5
|
+
|
6
|
+
def new
|
7
|
+
@list ||= Bestsellers::List.new
|
8
|
+
end
|
9
|
+
|
10
|
+
def method_missing(method, *args, &block)
|
11
|
+
return super unless new.respond_to?(method)
|
12
|
+
new.send(method, *args, &block)
|
13
|
+
end
|
14
|
+
|
15
|
+
def respond_to?(method, include_private=false)
|
16
|
+
new.respond_to?(method, include_private) || super(method, include_private)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'httparty'
|
3
|
+
require 'nytimes_bestsellers/configuration'
|
4
|
+
|
5
|
+
module Bestsellers
|
6
|
+
|
7
|
+
class List
|
8
|
+
|
9
|
+
include Bestsellers::Configuration
|
10
|
+
include HTTParty
|
11
|
+
|
12
|
+
BOOKS_URL = "http://api.nytimes.com/svc/books/v2/lists"
|
13
|
+
BOOKS_URL
|
14
|
+
|
15
|
+
def initialize
|
16
|
+
reset
|
17
|
+
end
|
18
|
+
|
19
|
+
def set_urlparam(url, name, options)
|
20
|
+
return unless options[name]
|
21
|
+
url << "&#{name.to_s.gsub('_','-')}=#{options[name]}"
|
22
|
+
end
|
23
|
+
|
24
|
+
def get_list(list_name, o = {})
|
25
|
+
url = BOOKS_URL.clone
|
26
|
+
|
27
|
+
if o[:date]
|
28
|
+
date = o[:date]
|
29
|
+
url << "/#{date}"
|
30
|
+
end
|
31
|
+
|
32
|
+
url << "/#{list_name}?"
|
33
|
+
|
34
|
+
[:offset, :sort_by, :sort_order].each do |thing|
|
35
|
+
set_urlparam(url, thing, o)
|
36
|
+
end
|
37
|
+
|
38
|
+
url << "&api-key=#{api_key}"
|
39
|
+
|
40
|
+
HTTParty.get(url)
|
41
|
+
end
|
42
|
+
|
43
|
+
def search_list(list_name, o = {})
|
44
|
+
|
45
|
+
url = BOOKS_URL.clone + "?list-name=#{list_name}"
|
46
|
+
|
47
|
+
date = if o[:date]
|
48
|
+
Date.parse(o[:date])
|
49
|
+
else
|
50
|
+
Date.today
|
51
|
+
end.strftime('%Y-%m-%e')
|
52
|
+
url << "&date=#{date}"
|
53
|
+
|
54
|
+
[:isbn, :published_date, :rank, :rank_last_week, :weeks_on_list].each do |thing|
|
55
|
+
set_urlparam(url, thing, o)
|
56
|
+
end
|
57
|
+
|
58
|
+
url << "&api-key=#{api_key}"
|
59
|
+
|
60
|
+
HTTParty.get(url)
|
61
|
+
end
|
62
|
+
|
63
|
+
def bestseller_lists_overview(o = {})
|
64
|
+
date = (Date.parse o[:date] || Date.today).strftime('%Y-%m-%e')
|
65
|
+
|
66
|
+
HTTParty.get(BOOKS_URL + "/overview?published_date=#{date}&api-key=#{api_key}")
|
67
|
+
end
|
68
|
+
|
69
|
+
def single_history(o = {})
|
70
|
+
|
71
|
+
url = BOOKS_URL.clone + "/best-sellers/history"
|
72
|
+
|
73
|
+
url << "?"
|
74
|
+
|
75
|
+
[:author, :publisher, :title, :age_group, :contributor, :isbn, :price].each do |thing|
|
76
|
+
set_urlparam(url, thing, o)
|
77
|
+
end
|
78
|
+
|
79
|
+
url << "&api-key=#{api_key}"
|
80
|
+
|
81
|
+
HTTParty.get(url)
|
82
|
+
end
|
83
|
+
|
84
|
+
def find_list_names
|
85
|
+
HTTParty.get(BOOKS_URL + "/names?api-key=#{api_key}")
|
86
|
+
end
|
87
|
+
|
88
|
+
def age_groups
|
89
|
+
HTTParty.get(BOOKS_URL + "/age-groups?api-key=#{api_key}")
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Bestsellers do
|
4
|
+
describe '.new' do
|
5
|
+
it "returns a Bestsellers::List" do
|
6
|
+
expect(Bestsellers.new).to be_a Bestsellers::List
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
describe ".configure" do
|
11
|
+
it "sets api_key" do
|
12
|
+
Bestsellers.configure do |config|
|
13
|
+
config.api_key = "secret"
|
14
|
+
end
|
15
|
+
|
16
|
+
expect(Bestsellers.api_key).to eq "secret"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
require 'coveralls'
|
3
|
+
|
4
|
+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
5
|
+
SimpleCov::Formatter::HTMLFormatter,
|
6
|
+
Coveralls::SimpleCov::Formatter
|
7
|
+
]
|
8
|
+
SimpleCov.start
|
9
|
+
|
10
|
+
require 'nytimes_bestsellers'
|
11
|
+
require 'rspec'
|
12
|
+
require 'webmock/rspec'
|
13
|
+
require 'json'
|
14
|
+
|
15
|
+
RSpec.configure do |config|
|
16
|
+
config.order = 'random'
|
17
|
+
config.expect_with :rspec do |c|
|
18
|
+
c.syntax = :expect
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def fixture_path
|
23
|
+
File.expand_path('../fixtures', __FILE__)
|
24
|
+
end
|
25
|
+
|
26
|
+
def fixture(file)
|
27
|
+
File.new(fixture_path + '/' + file)
|
28
|
+
end
|
29
|
+
|
30
|
+
Coveralls.wear!
|
metadata
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nytimes-bestsellers
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.4
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Emma
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-11-25 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Gem for accessing the NYTimes Bestsellers API
|
14
|
+
email: emma.n.spencer@gmail.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- README.md
|
20
|
+
- Gemfile
|
21
|
+
- Rakefile
|
22
|
+
- spec/nytimes_bestsellers_spec.rb
|
23
|
+
- spec/spec_helper.rb
|
24
|
+
- lib/nytimes_bestsellers/client.rb
|
25
|
+
- lib/nytimes_bestsellers/configuration.rb
|
26
|
+
- lib/nytimes_bestsellers/version.rb
|
27
|
+
- lib/nytimes_bestsellers.rb
|
28
|
+
homepage: http://github.com/enspencer/nytimes-bestsellers
|
29
|
+
licenses:
|
30
|
+
- MIT
|
31
|
+
metadata: {}
|
32
|
+
post_install_message:
|
33
|
+
rdoc_options: []
|
34
|
+
require_paths:
|
35
|
+
- lib
|
36
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
42
|
+
requirements:
|
43
|
+
- - '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
requirements: []
|
47
|
+
rubyforge_project:
|
48
|
+
rubygems_version: 2.0.6
|
49
|
+
signing_key:
|
50
|
+
specification_version: 4
|
51
|
+
summary: Gem for accessing the NYTimes Bestsellers API
|
52
|
+
test_files: []
|