times_books 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +7 -0
- data/LICENSE.txt +21 -0
- data/README.md +39 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/times_books/client.rb +13 -0
- data/lib/times_books/list.rb +53 -0
- data/lib/times_books/request.rb +20 -0
- data/lib/times_books/version.rb +3 -0
- data/lib/times_books.rb +26 -0
- data/times_books.gemspec +28 -0
- metadata +115 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 245e66767919d710c63abe121e42770ac8f1f7af
|
4
|
+
data.tar.gz: 8f5a7a2519696d4688b60c2ccac002fc216bddd1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7904bb6d7d80beff5db153066304e3edc26ad92ab67d0d55d68aca91d624d70f5bffaee108b84247ed38fdda3dd3da629b5c7a08bf87166cde5ea911c31b62b1
|
7
|
+
data.tar.gz: 13955281a879132817fad61f7bacdc6a25d011f3f6ff58e6338738d232dbd7ac5b7f90b57e4b8881e0063bed60ec4389fed343ab614b3b8d0c462f2a57f76eb0
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Ashley Livingston
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# TimesBooks
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/times_books`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'times_books'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install times_books
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/times_books.
|
36
|
+
|
37
|
+
## License
|
38
|
+
|
39
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "times_books"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
module TimesBooks
|
2
|
+
class Client
|
3
|
+
include TimesBooks::Request
|
4
|
+
include TimesBooks::List
|
5
|
+
|
6
|
+
attr_reader :api_key
|
7
|
+
|
8
|
+
def initialize(options = {})
|
9
|
+
fail(ArgumentError, "Options hash required.") unless options.is_a?(Hash)
|
10
|
+
@api_key = options[:api_key] || TimesBooks.configuration[:api_key]
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module TimesBooks
|
2
|
+
module List
|
3
|
+
|
4
|
+
# gets individual list by name, results more recent published
|
5
|
+
def getListByName(name)
|
6
|
+
url = "https://api.nytimes.com/svc/books/v3/lists.json"
|
7
|
+
params = {
|
8
|
+
list: name
|
9
|
+
}
|
10
|
+
|
11
|
+
self.request(url, params)
|
12
|
+
end
|
13
|
+
|
14
|
+
# gets a summary of all lists (no book results)
|
15
|
+
def getLists()
|
16
|
+
url = "https://api.nytimes.com/svc/books/v3/lists/names.json"
|
17
|
+
params = {}
|
18
|
+
self.request(url, params)
|
19
|
+
end
|
20
|
+
|
21
|
+
# search for a list that contains a book with a certain author, title, or publisher
|
22
|
+
def searchLists(author = '', title = '', publisher = '')
|
23
|
+
url = "https://api.nytimes.com/svc/books/v3/lists/best-sellers/history.json"
|
24
|
+
params = {
|
25
|
+
author: author,
|
26
|
+
title: title,
|
27
|
+
publisher: publisher
|
28
|
+
}
|
29
|
+
|
30
|
+
self.request(url, params)
|
31
|
+
end
|
32
|
+
|
33
|
+
# returns complete set of published lists, including book results, for provided date
|
34
|
+
def getListsByDate(date)
|
35
|
+
url = "https://api.nytimes.com/svc/books/v3/lists/overview.json"
|
36
|
+
params = {
|
37
|
+
published_date: date
|
38
|
+
}
|
39
|
+
self.request(url, params)
|
40
|
+
end
|
41
|
+
|
42
|
+
# search for a review by book title, author, or isbn
|
43
|
+
def searchReviews(isbn = '', title = '', author = '')
|
44
|
+
url = "https://api.nytimes.com/svc/books/v3/reviews.json"
|
45
|
+
params = {
|
46
|
+
author: author,
|
47
|
+
title: title,
|
48
|
+
isbn: isbn
|
49
|
+
}
|
50
|
+
self.request(url, params)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'rest-client'
|
2
|
+
|
3
|
+
module TimesBooks
|
4
|
+
module Request
|
5
|
+
|
6
|
+
def request(path, params)
|
7
|
+
api_key = TimesBooks.configuration[:api_key]
|
8
|
+
params = params.merge(:api_key=>api_key).to_query
|
9
|
+
url = "#{path}?#{params}"
|
10
|
+
result = RestClient.get(url)
|
11
|
+
|
12
|
+
parse(result)
|
13
|
+
end
|
14
|
+
|
15
|
+
def parse(result)
|
16
|
+
hash = JSON.parse(result)
|
17
|
+
return hash
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/times_books.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require "times_books/version"
|
2
|
+
require "times_books/request"
|
3
|
+
require "times_books/client"
|
4
|
+
|
5
|
+
module TimesBooks
|
6
|
+
class << self
|
7
|
+
attr_accessor :options
|
8
|
+
end
|
9
|
+
|
10
|
+
self.options = {}
|
11
|
+
|
12
|
+
def self.new(params = {})
|
13
|
+
TimesBooks::Client.new(params)
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.configure(params = {})
|
17
|
+
fail(ArgumentError, "Options hash required.") unless params.is_a?(Hash)
|
18
|
+
|
19
|
+
options[:api_key] = params[:api_key]
|
20
|
+
options
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.configuration
|
24
|
+
options
|
25
|
+
end
|
26
|
+
end
|
data/times_books.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "times_books/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "times_books"
|
8
|
+
spec.version = TimesBooks::VERSION
|
9
|
+
spec.authors = ["Ashley Livingston"]
|
10
|
+
spec.email = ["ashleyhlivingston@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Simple ruby client for Time's Books API}
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.15"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
27
|
+
spec.add_runtime_dependency "rest-client"
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: times_books
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ashley Livingston
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-07-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.15'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.15'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rest-client
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description:
|
70
|
+
email:
|
71
|
+
- ashleyhlivingston@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rspec"
|
78
|
+
- ".travis.yml"
|
79
|
+
- Gemfile
|
80
|
+
- LICENSE.txt
|
81
|
+
- README.md
|
82
|
+
- Rakefile
|
83
|
+
- bin/console
|
84
|
+
- bin/setup
|
85
|
+
- lib/times_books.rb
|
86
|
+
- lib/times_books/client.rb
|
87
|
+
- lib/times_books/list.rb
|
88
|
+
- lib/times_books/request.rb
|
89
|
+
- lib/times_books/version.rb
|
90
|
+
- times_books.gemspec
|
91
|
+
homepage:
|
92
|
+
licenses:
|
93
|
+
- MIT
|
94
|
+
metadata: {}
|
95
|
+
post_install_message:
|
96
|
+
rdoc_options: []
|
97
|
+
require_paths:
|
98
|
+
- lib
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
requirements: []
|
110
|
+
rubyforge_project:
|
111
|
+
rubygems_version: 2.6.12
|
112
|
+
signing_key:
|
113
|
+
specification_version: 4
|
114
|
+
summary: Simple ruby client for Time's Books API
|
115
|
+
test_files: []
|