goodreads 0.4.3 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4e1c4bc2ac3e141e0c1b7774c1a80507a236946d
4
- data.tar.gz: 2d335ac55485c8ec4259a1296df9ae68095e94ab
3
+ metadata.gz: 0bf2079b03cdc4a3630504bab0adf6fceb39116d
4
+ data.tar.gz: 41ffa08e6b041c58d284a94489a55926d8be22aa
5
5
  SHA512:
6
- metadata.gz: 497e314c0b4596b2117cdd3402d01602d33abcabce9653abcb6cd9bc112dee643ba970f7e0cdda1462fa8ea1c439248e3400562160fcd5b8b7c57fea80a9b706
7
- data.tar.gz: 43aea244b93abe77c875cf894aa229c3d2062e6ed78e094ba9d1dcac4c46fffac46cc968d263536d45cdbbcd18c808b13b53db4f220ea8efa3644a1a445d2362
6
+ metadata.gz: 76523d2373dc284161ba63dd8b914028a17bbbc09bb943984f4b8610e766d2f2e9fec30be23c76fae2b633e452d389d523e34fbaa9b0d18b44020a1b4d83a91d
7
+ data.tar.gz: be44f0721b36dcb13f97dba807dc34b81de66612179a82b878aa9f143f05bb9aefba5a0e7b174e74c3e7cd212e2e83e5486be86cd9aeb0fa0ac06460f4dcd736
@@ -0,0 +1,6 @@
1
+ Metrics/LineLength:
2
+ Max: 120
3
+ Documentation:
4
+ Enabled: false
5
+ StringLiterals:
6
+ EnforcedStyle: double_quotes
@@ -1,10 +1,10 @@
1
1
  sudo: false
2
2
 
3
3
  rvm:
4
- - 1.9.3
5
- - 2.0
6
4
  - 2.1
7
5
  - 2.2
6
+ - 2.3
7
+ - 2.4
8
8
 
9
9
  script:
10
10
  - bundle exec rake test
data/Gemfile CHANGED
@@ -1,3 +1,3 @@
1
- source 'https://rubygems.org'
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(:api_key => 'KEY', :api_secret => 'SECRET')
31
- client = Goodreads.new(:api_key => 'KEY') # short version
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
- :api_key => 'KEY',
42
- :api_secret => 'SECRET'
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 # => {:api_key => 'YOUR_KEY'}
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('id')
66
- client.book_by_isbn('ISBN')
67
- client.book_by_title('Book 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('The Lord Of The Rings')
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('id')
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('Author 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('id')
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('id')
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('user_id', 'sort')
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 'bundler'
2
- require 'bundler/gem_tasks'
3
- require 'rspec/core/rake_task'
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 = 'spec/*_spec.rb'
6
+ t.pattern = "spec/*_spec.rb"
7
7
  t.verbose = false
8
8
  end
9
9
 
10
- task :default => :test
10
+ task default: :test
@@ -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
- :site => 'http://www.goodreads.com'
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 :oauth_token => access_token
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
+ ```
@@ -1,4 +1,4 @@
1
- require File.expand_path('../lib/goodreads/version', __FILE__)
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 'webmock', '~> 1.11'
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', '~> 1.6'
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'
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
@@ -1,41 +1,42 @@
1
- require 'goodreads/version'
2
- require 'goodreads/errors'
3
- require 'goodreads/request'
4
- require 'goodreads/client'
1
+ require "goodreads/version"
2
+ require "goodreads/errors"
3
+ require "goodreads/request"
4
+ require "goodreads/client"
5
5
 
6
6
  module Goodreads
7
- @@options = {}
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(options={})
12
- Goodreads::Client.new(options)
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(options={})
21
- unless options.kind_of?(Hash)
22
- raise ArgumentError, "Options hash required."
23
- end
24
-
25
- @@options[:api_key] = options[:api_key]
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
- @@options
34
+ options
34
35
  end
35
-
36
+
36
37
  # Resets the global configuration
37
38
  #
38
39
  def self.reset_configuration
39
- @@options = {}
40
+ self.options = {}
40
41
  end
41
42
  end
@@ -1,12 +1,12 @@
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'
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.kind_of?(Hash)
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]
@@ -1,9 +1,7 @@
1
1
  module Goodreads
2
2
  module Authorized
3
-
4
3
  def user_id
5
- oauth_request('/api/auth_user')['user']['id']
4
+ oauth_request("/api/auth_user")["user"]["id"]
6
5
  end
7
-
8
6
  end
9
7
  end
@@ -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('/author/show', params)
8
- Hashie::Mash.new(data['author'])
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['author'])
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('/search/index', params)
14
- Hashie::Mash.new(data['search'])
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('/book/show', :id => id)['book'])
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('/book/isbn', :isbn => isbn)['book'])
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('/book/title', :title => title)['book'])
32
+ Hashie::Mash.new(request("/book/title", title: title)["book"])
33
33
  end
34
34
  end
35
35
  end
@@ -6,7 +6,7 @@ module Goodreads
6
6
  #
7
7
  def friends(user_id)
8
8
  data = oauth_request("/friend/user/#{user_id}")
9
- Hashie::Mash.new(data['friends'])
9
+ Hashie::Mash.new(data["friends"])
10
10
  end
11
11
  end
12
- end
12
+ 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('/group/show', :id => group_id)
6
- Hashie::Mash.new(data['group'])
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='my_activity')
11
- data = request('/group/list', :id => user_id, :sort => sort)
12
- Hashie::Mash.new(data['groups']['list'])
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('/review/recent_reviews', params)
10
- if 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
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('/review/show', :id => id)
21
- Hashie::Mash.new(data['review'])
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('/review/list', params.merge(:v => '2'))
28
- reviews = data['reviews']['review']
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