goodreads 0.4.3 → 0.5.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 +4 -4
- data/.rubocop.yml +6 -0
- data/.travis.yml +2 -2
- data/Gemfile +2 -2
- data/README.md +18 -18
- data/Rakefile +5 -5
- data/examples/oauth.md +3 -3
- data/goodreads.gemspec +14 -14
- data/lib/goodreads.rb +22 -21
- data/lib/goodreads/client.rb +11 -13
- data/lib/goodreads/client/authorized.rb +1 -3
- data/lib/goodreads/client/authors.rb +5 -5
- data/lib/goodreads/client/books.rb +9 -9
- data/lib/goodreads/client/friends.rb +2 -2
- data/lib/goodreads/client/groups.rb +5 -5
- data/lib/goodreads/client/reviews.rb +12 -13
- data/lib/goodreads/client/shelves.rb +11 -13
- data/lib/goodreads/client/users.rb +3 -3
- data/lib/goodreads/errors.rb +5 -5
- data/lib/goodreads/request.rb +30 -29
- data/lib/goodreads/version.rb +1 -1
- data/spec/authentication_spec.rb +16 -16
- data/spec/client_spec.rb +205 -201
- data/spec/goodreads_spec.rb +31 -31
- data/spec/spec_helper.rb +13 -13
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0bf2079b03cdc4a3630504bab0adf6fceb39116d
|
4
|
+
data.tar.gz: 41ffa08e6b041c58d284a94489a55926d8be22aa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 76523d2373dc284161ba63dd8b914028a17bbbc09bb943984f4b8610e766d2f2e9fec30be23c76fae2b633e452d389d523e34fbaa9b0d18b44020a1b4d83a91d
|
7
|
+
data.tar.gz: be44f0721b36dcb13f97dba807dc34b81de66612179a82b878aa9f143f05bb9aefba5a0e7b174e74c3e7cd212e2e83e5486be86cd9aeb0fa0ac06460f4dcd736
|
data/.rubocop.yml
ADDED
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
source
|
1
|
+
source "https://rubygems.org"
|
2
2
|
|
3
|
-
gemspec
|
3
|
+
gemspec
|
data/README.md
CHANGED
@@ -27,8 +27,8 @@ Before using Goodreads API you must create a new application. Visit [signup form
|
|
27
27
|
Setup client:
|
28
28
|
|
29
29
|
``` ruby
|
30
|
-
client = Goodreads::Client.new(:
|
31
|
-
client = Goodreads.new(:
|
30
|
+
client = Goodreads::Client.new(api_key: "KEY", api_secret: "SECRET")
|
31
|
+
client = Goodreads.new(api_key: "KEY") # short version
|
32
32
|
```
|
33
33
|
|
34
34
|
### Global configuration
|
@@ -38,15 +38,15 @@ You can define client credentials on global level. Just create an initializer fi
|
|
38
38
|
|
39
39
|
``` ruby
|
40
40
|
Goodreads.configure(
|
41
|
-
:
|
42
|
-
:
|
41
|
+
api_key: "KEY",
|
42
|
+
api_secret: "SECRET"
|
43
43
|
)
|
44
44
|
```
|
45
45
|
|
46
46
|
Get global configuration:
|
47
47
|
|
48
48
|
``` ruby
|
49
|
-
Goodreads.configuration # => {:
|
49
|
+
Goodreads.configuration # => { api_key: "YOUR_KEY" }
|
50
50
|
```
|
51
51
|
|
52
52
|
In case you need to reset options:
|
@@ -62,15 +62,15 @@ Goodreads.reset_configuration
|
|
62
62
|
You can lookup a book by ISBN, ID or Title:
|
63
63
|
|
64
64
|
```ruby
|
65
|
-
client.book(
|
66
|
-
client.book_by_isbn(
|
67
|
-
client.book_by_title(
|
65
|
+
client.book("id")
|
66
|
+
client.book_by_isbn("ISBN")
|
67
|
+
client.book_by_title("Book title")
|
68
68
|
```
|
69
69
|
|
70
70
|
Search for books (by title, isbn, genre):
|
71
71
|
|
72
72
|
```ruby
|
73
|
-
search = client.search_books(
|
73
|
+
search = client.search_books("The Lord Of The Rings")
|
74
74
|
|
75
75
|
search.results.work.each do |book|
|
76
76
|
book.id # => book id
|
@@ -79,11 +79,11 @@ end
|
|
79
79
|
```
|
80
80
|
|
81
81
|
### Authors
|
82
|
-
|
82
|
+
|
83
83
|
Look up an author by their Goodreads Author ID:
|
84
84
|
|
85
85
|
```ruby
|
86
|
-
author = client.author(
|
86
|
+
author = client.author("id")
|
87
87
|
|
88
88
|
author.id # => author id
|
89
89
|
author.name # => author's name
|
@@ -103,7 +103,7 @@ author.died_at # => date of author's death
|
|
103
103
|
Look up an author by name:
|
104
104
|
|
105
105
|
```ruby
|
106
|
-
author = client.author_by_name(
|
106
|
+
author = client.author_by_name("Author Name")
|
107
107
|
|
108
108
|
author.id # => author id
|
109
109
|
author.name # => author name
|
@@ -126,7 +126,7 @@ end
|
|
126
126
|
Get review details:
|
127
127
|
|
128
128
|
```ruby
|
129
|
-
review = client.review(
|
129
|
+
review = client.review("id")
|
130
130
|
|
131
131
|
review.id # => review id
|
132
132
|
review.user # => user information
|
@@ -152,7 +152,7 @@ shelf.total # total number of books on this shelf
|
|
152
152
|
Get group details:
|
153
153
|
|
154
154
|
```ruby
|
155
|
-
group = client.group(
|
155
|
+
group = client.group("id")
|
156
156
|
|
157
157
|
group.id # => group id
|
158
158
|
group.title # => group title
|
@@ -164,7 +164,7 @@ group.group_users_count # => number of users in the group
|
|
164
164
|
List the groups a given user is a member of:
|
165
165
|
|
166
166
|
```ruby
|
167
|
-
group_list = client.group_list(
|
167
|
+
group_list = client.group_list("user_id", "sort")
|
168
168
|
|
169
169
|
group_list.total # => total number of groups
|
170
170
|
group_list.group.count # => number of groups returned in the request
|
@@ -181,12 +181,12 @@ group_list.group.each do |g|
|
|
181
181
|
end
|
182
182
|
```
|
183
183
|
|
184
|
-
The `sort` parameter is optional, and defaults to `my_activity`.
|
184
|
+
The `sort` parameter is optional, and defaults to `my_activity`.
|
185
185
|
For other sorting options, [see here](http://www.goodreads.com/api#group.list).
|
186
186
|
|
187
187
|
### OAuth
|
188
188
|
|
189
|
-
For API calls requiring permission, such as write operations or browsing friends,
|
189
|
+
For API calls requiring permission, such as write operations or browsing friends,
|
190
190
|
see our [OAuth tutorial](examples/oauth.md).
|
191
191
|
|
192
192
|
## Testing
|
@@ -210,4 +210,4 @@ You're welcome to submit patches and new features.
|
|
210
210
|
|
211
211
|
The MIT License (MIT)
|
212
212
|
|
213
|
-
Copyright (c) 2011-2015 Dan Sosedoff, <dan.sosedoff@gmail.com>
|
213
|
+
Copyright (c) 2011-2015 Dan Sosedoff, <dan.sosedoff@gmail.com>
|
data/Rakefile
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require "bundler"
|
2
|
+
require "bundler/gem_tasks"
|
3
|
+
require "rspec/core/rake_task"
|
4
4
|
|
5
5
|
RSpec::Core::RakeTask.new(:test) do |t|
|
6
|
-
t.pattern =
|
6
|
+
t.pattern = "spec/*_spec.rb"
|
7
7
|
t.verbose = false
|
8
8
|
end
|
9
9
|
|
10
|
-
task :
|
10
|
+
task default: :test
|
data/examples/oauth.md
CHANGED
@@ -10,7 +10,7 @@ First, get an OAuth *request* token:
|
|
10
10
|
request_token = OAuth::Consumer.new(
|
11
11
|
Goodreads.configuration[:api_key],
|
12
12
|
Goodreads.configuration[:api_secret],
|
13
|
-
:
|
13
|
+
site: "http://www.goodreads.com"
|
14
14
|
).get_request_token
|
15
15
|
```
|
16
16
|
|
@@ -29,7 +29,7 @@ access_token = request_token.get_access_token
|
|
29
29
|
Finally, initialize a Goodreads client with it:
|
30
30
|
|
31
31
|
```ruby
|
32
|
-
goodreads_client = Goodreads.new
|
32
|
+
goodreads_client = Goodreads.new(oauth_token: access_token)
|
33
33
|
```
|
34
34
|
|
35
35
|
For more info, see the [Goodreads documentation](http://www.goodreads.com/api/oauth_example).
|
@@ -54,4 +54,4 @@ Get a list of their names:
|
|
54
54
|
|
55
55
|
```ruby
|
56
56
|
friends_hash.user.map{ |u| u.name }
|
57
|
-
```
|
57
|
+
```
|
data/goodreads.gemspec
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require File.expand_path(
|
1
|
+
require File.expand_path("../lib/goodreads/version", __FILE__)
|
2
2
|
|
3
3
|
Gem::Specification.new do |spec|
|
4
4
|
spec.name = "goodreads"
|
@@ -9,21 +9,21 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.authors = ["Dan Sosedoff"]
|
10
10
|
spec.email = ["dan.sosedoff@gmail.com"]
|
11
11
|
spec.license = "MIT"
|
12
|
-
|
13
|
-
spec.add_development_dependency
|
14
|
-
spec.add_development_dependency
|
15
|
-
spec.add_development_dependency
|
16
|
-
spec.add_development_dependency
|
17
|
-
spec.add_development_dependency
|
18
|
-
|
19
|
-
spec.add_runtime_dependency
|
20
|
-
spec.add_runtime_dependency
|
21
|
-
spec.add_runtime_dependency
|
22
|
-
spec.add_runtime_dependency
|
23
|
-
spec.add_runtime_dependency
|
12
|
+
|
13
|
+
spec.add_development_dependency "webmock", "~> 2.0"
|
14
|
+
spec.add_development_dependency "rake", "~> 10"
|
15
|
+
spec.add_development_dependency "rspec", "~> 2.12"
|
16
|
+
spec.add_development_dependency "simplecov", "~> 0.7"
|
17
|
+
spec.add_development_dependency "yard", "~> 0.6"
|
18
|
+
|
19
|
+
spec.add_runtime_dependency "rest-client", "~> 2.0"
|
20
|
+
spec.add_runtime_dependency "hashie", "~> 2.0"
|
21
|
+
spec.add_runtime_dependency "activesupport", ">= 3.0"
|
22
|
+
spec.add_runtime_dependency "i18n", "~> 0.5"
|
23
|
+
spec.add_runtime_dependency "oauth", "~> 0.4"
|
24
24
|
|
25
25
|
spec.files = `git ls-files`.split("\n")
|
26
26
|
spec.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
27
|
-
spec.executables = `git ls-files -- bin/*`.split("\n").map{|f| File.basename(f)}
|
27
|
+
spec.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
28
28
|
spec.require_paths = ["lib"]
|
29
29
|
end
|
data/lib/goodreads.rb
CHANGED
@@ -1,41 +1,42 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
1
|
+
require "goodreads/version"
|
2
|
+
require "goodreads/errors"
|
3
|
+
require "goodreads/request"
|
4
|
+
require "goodreads/client"
|
5
5
|
|
6
6
|
module Goodreads
|
7
|
-
|
8
|
-
|
7
|
+
class << self
|
8
|
+
attr_accessor :options
|
9
|
+
end
|
10
|
+
self.options = {}
|
11
|
+
|
9
12
|
# Create a new Goodreads::Client instance
|
10
13
|
#
|
11
|
-
def self.new(
|
12
|
-
Goodreads::Client.new(
|
14
|
+
def self.new(params = {})
|
15
|
+
Goodreads::Client.new(params)
|
13
16
|
end
|
14
|
-
|
17
|
+
|
15
18
|
# Define a global configuration
|
16
19
|
#
|
17
20
|
# options[:api_key] - Account API key
|
18
21
|
# options[:api_secret] - Account API secret
|
19
22
|
#
|
20
|
-
def self.configure(
|
21
|
-
unless
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
@@options[:api_secret] = options[:api_secret]
|
27
|
-
@@options
|
23
|
+
def self.configure(params = {})
|
24
|
+
fail(ArgumentError, "Options hash required.") unless params.is_a?(Hash)
|
25
|
+
|
26
|
+
options[:api_key] = params[:api_key]
|
27
|
+
options[:api_secret] = params[:api_secret]
|
28
|
+
options
|
28
29
|
end
|
29
|
-
|
30
|
+
|
30
31
|
# Returns global configuration hash
|
31
32
|
#
|
32
33
|
def self.configuration
|
33
|
-
|
34
|
+
options
|
34
35
|
end
|
35
|
-
|
36
|
+
|
36
37
|
# Resets the global configuration
|
37
38
|
#
|
38
39
|
def self.reset_configuration
|
39
|
-
|
40
|
+
self.options = {}
|
40
41
|
end
|
41
42
|
end
|
data/lib/goodreads/client.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
1
|
+
require "goodreads/client"
|
2
|
+
require "goodreads/client/books"
|
3
|
+
require "goodreads/client/reviews"
|
4
|
+
require "goodreads/client/authors"
|
5
|
+
require "goodreads/client/users"
|
6
|
+
require "goodreads/client/shelves"
|
7
|
+
require "goodreads/client/authorized"
|
8
|
+
require "goodreads/client/groups"
|
9
|
+
require "goodreads/client/friends"
|
10
10
|
|
11
11
|
module Goodreads
|
12
12
|
class Client
|
@@ -28,10 +28,8 @@ module Goodreads
|
|
28
28
|
# options[:api_secret] - Account API secret
|
29
29
|
# options[:oauth_token] - OAuth access token (optional, required for some calls)
|
30
30
|
#
|
31
|
-
def initialize(options={})
|
32
|
-
unless options.
|
33
|
-
raise ArgumentError, "Options hash required."
|
34
|
-
end
|
31
|
+
def initialize(options = {})
|
32
|
+
fail(ArgumentError, "Options hash required.") unless options.is_a?(Hash)
|
35
33
|
|
36
34
|
@api_key = options[:api_key] || Goodreads.configuration[:api_key]
|
37
35
|
@api_secret = options[:api_secret] || Goodreads.configuration[:api_secret]
|
@@ -2,19 +2,19 @@ module Goodreads
|
|
2
2
|
module Authors
|
3
3
|
# Get author details
|
4
4
|
#
|
5
|
-
def author(id, params={})
|
5
|
+
def author(id, params = {})
|
6
6
|
params[:id] = id
|
7
|
-
data = request(
|
8
|
-
Hashie::Mash.new(data[
|
7
|
+
data = request("/author/show", params)
|
8
|
+
Hashie::Mash.new(data["author"])
|
9
9
|
end
|
10
10
|
|
11
11
|
# Search for an author by name
|
12
12
|
#
|
13
|
-
def author_by_name(name, params={})
|
13
|
+
def author_by_name(name, params = {})
|
14
14
|
params[:id] = name
|
15
15
|
name_encoded = URI.encode(name)
|
16
16
|
data = request("/api/author_url/#{name_encoded}", params)
|
17
|
-
Hashie::Mash.new(data[
|
17
|
+
Hashie::Mash.new(data["author"])
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
@@ -8,28 +8,28 @@ module Goodreads
|
|
8
8
|
# options[:page] - Which page to returns (default: 1)
|
9
9
|
# options[:field] - Search field. One of: title, author, or genre (default is all)
|
10
10
|
#
|
11
|
-
def search_books(query, params={})
|
11
|
+
def search_books(query, params = {})
|
12
12
|
params[:q] = query.to_s.strip
|
13
|
-
data = request(
|
14
|
-
Hashie::Mash.new(data[
|
13
|
+
data = request("/search/index", params)
|
14
|
+
Hashie::Mash.new(data["search"])
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
# Get book details by Goodreads book ID
|
18
18
|
#
|
19
19
|
def book(id)
|
20
|
-
Hashie::Mash.new(request(
|
20
|
+
Hashie::Mash.new(request("/book/show", id: id)["book"])
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
# Get book details by book ISBN
|
24
24
|
#
|
25
25
|
def book_by_isbn(isbn)
|
26
|
-
Hashie::Mash.new(request(
|
26
|
+
Hashie::Mash.new(request("/book/isbn", isbn: isbn)["book"])
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
# Get book details by book title
|
30
30
|
#
|
31
31
|
def book_by_title(title)
|
32
|
-
Hashie::Mash.new(request(
|
32
|
+
Hashie::Mash.new(request("/book/title", title: title)["book"])
|
33
33
|
end
|
34
34
|
end
|
35
35
|
end
|
@@ -2,14 +2,14 @@ module Goodreads
|
|
2
2
|
module Groups
|
3
3
|
# Get group details
|
4
4
|
def group(group_id)
|
5
|
-
data = request(
|
6
|
-
Hashie::Mash.new(data[
|
5
|
+
data = request("/group/show", id: group_id)
|
6
|
+
Hashie::Mash.new(data["group"])
|
7
7
|
end
|
8
8
|
|
9
9
|
# Get list of groups a given user is a member of
|
10
|
-
def group_list(user_id, sort=
|
11
|
-
data = request(
|
12
|
-
Hashie::Mash.new(data[
|
10
|
+
def group_list(user_id, sort = "my_activity")
|
11
|
+
data = request("/group/list", id: user_id, sort: sort)
|
12
|
+
Hashie::Mash.new(data["groups"]["list"])
|
13
13
|
end
|
14
14
|
end
|
15
15
|
end
|
@@ -4,28 +4,27 @@ module Goodreads
|
|
4
4
|
#
|
5
5
|
# params[:skip_cropped] - Select only non-cropped reviews
|
6
6
|
#
|
7
|
-
def recent_reviews(params={})
|
7
|
+
def recent_reviews(params = {})
|
8
8
|
skip_cropped = params.delete(:skip_cropped) || false
|
9
|
-
data = request(
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
end
|
9
|
+
data = request("/review/recent_reviews", params)
|
10
|
+
return unless data["reviews"] && data["reviews"].key?("review")
|
11
|
+
reviews = data["reviews"]["review"].map { |r| Hashie::Mash.new(r) }
|
12
|
+
reviews = reviews.select { |r| !r.body.include?(r.url) } if skip_cropped
|
13
|
+
reviews
|
15
14
|
end
|
16
|
-
|
15
|
+
|
17
16
|
# Get review details
|
18
17
|
#
|
19
18
|
def review(id)
|
20
|
-
data = request(
|
21
|
-
Hashie::Mash.new(data[
|
19
|
+
data = request("/review/show", id: id)
|
20
|
+
Hashie::Mash.new(data["review"])
|
22
21
|
end
|
23
22
|
|
24
23
|
# Get list of reviews
|
25
24
|
#
|
26
|
-
def reviews(params={})
|
27
|
-
data = request(
|
28
|
-
reviews = data[
|
25
|
+
def reviews(params = {})
|
26
|
+
data = request("/review/list", params.merge(v: "2"))
|
27
|
+
reviews = data["reviews"]["review"]
|
29
28
|
if reviews.present?
|
30
29
|
reviews.map { |review| Hashie::Mash.new(review) }
|
31
30
|
else
|