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.
@@ -1,26 +1,24 @@
1
1
  module Goodreads
2
2
  module Shelves
3
-
4
3
  # Get books from a user's shelf
5
- def shelf(user_id, shelf_name, options={})
6
- options = options.merge(:shelf => shelf_name, :v =>2)
4
+ def shelf(user_id, shelf_name, options = {})
5
+ options = options.merge(shelf: shelf_name, v: 2)
7
6
  data = request("/review/list/#{user_id}.xml", options)
8
- reviews = data['reviews']['review']
7
+ reviews = data["reviews"]["review"]
9
8
 
10
9
  books = []
11
10
  unless reviews.nil?
12
11
  # one-book results come back as a single hash
13
- reviews = [reviews] if !reviews.instance_of?(Array)
14
- books = reviews.map {|e| Hashie::Mash.new(e)}
12
+ reviews = [reviews] unless reviews.instance_of?(Array)
13
+ books = reviews.map { |e| Hashie::Mash.new(e) }
15
14
  end
16
15
 
17
- Hashie::Mash.new({
18
- :start => data['reviews']['start'].to_i,
19
- :end => data['reviews']['end'].to_i,
20
- :total => data['reviews']['total'].to_i,
21
- :books => books
22
- })
16
+ Hashie::Mash.new(
17
+ start: data["reviews"]["start"].to_i,
18
+ end: data["reviews"]["end"].to_i,
19
+ total: data["reviews"]["total"].to_i,
20
+ books: books
21
+ )
23
22
  end
24
-
25
23
  end
26
24
  end
@@ -3,8 +3,8 @@ module Goodreads
3
3
  # Get user details
4
4
  #
5
5
  def user(id)
6
- data = request('/user/show', :id => id)
7
- Hashie::Mash.new(data['user'])
6
+ data = request("/user/show", id: id)
7
+ Hashie::Mash.new(data["user"])
8
8
  end
9
9
  end
10
- end
10
+ end
@@ -1,7 +1,7 @@
1
1
  module Goodreads
2
- class Error < StandardError; end
3
- class ConfigurationError < Error ; end
4
- class Forbidden < Error ; end
5
- class Unauthorized < Error ; end
6
- class NotFound < Error ; end
2
+ class Error < StandardError; end
3
+ class ConfigurationError < Error; end
4
+ class Forbidden < Error; end
5
+ class Unauthorized < Error; end
6
+ class NotFound < Error; end
7
7
  end
@@ -1,11 +1,11 @@
1
- require 'active_support/core_ext/hash'
2
- require 'rest-client'
3
- require 'hashie'
1
+ require "active_support/core_ext/hash"
2
+ require "rest-client"
3
+ require "hashie"
4
4
 
5
5
  module Goodreads
6
6
  module Request
7
- API_URL = 'http://www.goodreads.com'
8
- API_FORMAT = 'xml'
7
+ API_URL = "https://www.goodreads.com"
8
+ API_FORMAT = "xml"
9
9
 
10
10
  protected
11
11
 
@@ -14,26 +14,24 @@ module Goodreads
14
14
  # path - Request path
15
15
  # params - Parameters hash
16
16
  #
17
- def request(path, params={})
17
+ def request(path, params = {})
18
18
  token = api_key || Goodreads.configuration[:api_key]
19
19
 
20
- if token.nil?
21
- raise Goodreads::ConfigurationError, 'API key required.'
22
- end
20
+ fail(Goodreads::ConfigurationError, "API key required.") if token.nil?
23
21
 
24
- params.merge!(:format => API_FORMAT, :key => token)
22
+ params.merge!(format: API_FORMAT, key: token)
25
23
  url = "#{API_URL}#{path}"
26
24
 
27
- resp = RestClient.get(url, :params => params) do |response, request, result, &block|
25
+ resp = RestClient.get(url, params: params) do |response, request, result, &block|
28
26
  case response.code
29
- when 200
30
- response.return!(request, result, &block)
31
- when 401
32
- raise Goodreads::Unauthorized
33
- when 403
34
- raise Goodreads::Forbidden
35
- when 404
36
- raise Goodreads::NotFound
27
+ when 200
28
+ response.return!(&block)
29
+ when 401
30
+ fail(Goodreads::Unauthorized)
31
+ when 403
32
+ fail(Goodreads::Forbidden)
33
+ when 404
34
+ fail(Goodreads::NotFound)
37
35
  end
38
36
  end
39
37
 
@@ -45,24 +43,27 @@ module Goodreads
45
43
  # path - Request path
46
44
  # params - Parameters hash
47
45
  #
48
- def oauth_request(path, params=nil)
49
- raise 'OAuth access token required!' unless @oauth_token
50
- path = "#{path}?#{params.map{|k,v|"#{k}=#{v}"}.join('&')}" if params
51
- resp = @oauth_token.get(path, {'Accept'=>'application/xml'})
46
+ def oauth_request(path, params = nil)
47
+ fail "OAuth access token required!" unless @oauth_token
48
+ if params
49
+ url_params = params.map { |k, v| "#{k}=#{v}" }.join("&")
50
+ path = "#{path}?#{url_params}"
51
+ end
52
+ resp = @oauth_token.get(path, "Accept" => "application/xml")
52
53
 
53
54
  case resp
54
- when Net::HTTPUnauthorized
55
- raise Goodreads::Unauthorized
56
- when Net::HTTPNotFound
57
- raise Goodreads::NotFound
55
+ when Net::HTTPUnauthorized
56
+ fail Goodreads::Unauthorized
57
+ when Net::HTTPNotFound
58
+ fail Goodreads::NotFound
58
59
  end
59
60
 
60
61
  parse(resp)
61
62
  end
62
63
 
63
64
  def parse(resp)
64
- hash = Hash.from_xml(resp.body)['GoodreadsResponse']
65
- hash.delete('Request')
65
+ hash = Hash.from_xml(resp.body)["GoodreadsResponse"]
66
+ hash.delete("Request")
66
67
  hash
67
68
  end
68
69
  end
@@ -1,3 +1,3 @@
1
1
  module Goodreads
2
- VERSION = "0.4.3"
2
+ VERSION = "0.5.0"
3
3
  end
@@ -1,24 +1,24 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
- describe 'Client' do
3
+ describe "Client" do
4
4
  before :each do
5
5
  Goodreads.reset_configuration
6
6
  end
7
-
8
- it 'raises Goodreads::ConfigurationError if API key was not provided' do
7
+
8
+ it "raises Goodreads::ConfigurationError if API key was not provided" do
9
9
  client = Goodreads::Client.new
10
-
11
- proc { client.book_by_isbn('0307463745') }.
12
- should raise_error Goodreads::ConfigurationError, 'API key required.'
10
+
11
+ expect { client.book_by_isbn("0307463745") }
12
+ .to raise_error(Goodreads::ConfigurationError, "API key required.")
13
13
  end
14
-
15
- it 'raises Goodreads::Unauthorized if API key is not valid' do
16
- client = Goodreads::Client.new(:api_key => 'INVALID_KEY')
17
-
18
- stub_request(:get, "http://www.goodreads.com/book/isbn?format=xml&isbn=054748250711&key=INVALID_KEY").
19
- to_return(:status => 401)
20
-
21
- proc { client.book_by_isbn('054748250711') }.
22
- should raise_error Goodreads::Unauthorized
14
+
15
+ it "raises Goodreads::Unauthorized if API key is not valid" do
16
+ client = Goodreads::Client.new(api_key: "INVALID_KEY")
17
+
18
+ stub_request(:get, "https://www.goodreads.com/book/isbn?format=xml&isbn=054748250711&key=INVALID_KEY")
19
+ .to_return(status: 401)
20
+
21
+ expect { client.book_by_isbn("054748250711") }
22
+ .to raise_error(Goodreads::Unauthorized)
23
23
  end
24
24
  end
@@ -1,333 +1,337 @@
1
- require 'spec_helper'
2
- require 'oauth'
1
+ require "spec_helper"
2
+ require "oauth"
3
3
 
4
- describe 'Client' do
5
- let(:client) { Goodreads::Client.new(:api_key => 'SECRET_KEY') }
4
+ describe "Client" do
5
+ let(:client) { Goodreads::Client.new(api_key: "SECRET_KEY") }
6
6
  before(:each) { Goodreads.reset_configuration }
7
7
 
8
- describe '#new' do
9
- it 'requires an argument' do
10
- expect { Goodreads::Client.new(nil) }.
11
- to raise_error ArgumentError, "Options hash required."
8
+ describe "#new" do
9
+ it "requires an argument" do
10
+ expect { Goodreads::Client.new(nil) }
11
+ .to raise_error(ArgumentError, "Options hash required.")
12
12
  end
13
13
 
14
- it 'requires a hash argument' do
15
- expect { Goodreads::Client.new('foo') }.
16
- to raise_error ArgumentError, "Options hash required."
14
+ it "requires a hash argument" do
15
+ expect { Goodreads::Client.new("foo") }
16
+ .to raise_error(ArgumentError, "Options hash required.")
17
17
  end
18
18
  end
19
19
 
20
- describe '#book_by_isbn' do
21
- before { stub_with_key_get('/book/isbn', {:isbn => '0307463745'}, 'book.xml') }
20
+ describe "#book_by_isbn" do
21
+ before { stub_with_key_get("/book/isbn", { isbn: "0307463745" }, "book.xml") }
22
22
 
23
- it 'returns a book by isbn' do
24
- book = client.book_by_isbn('0307463745')
23
+ it "returns a book by isbn" do
24
+ book = client.book_by_isbn("0307463745")
25
25
 
26
- book.should respond_to :id
27
- book.should respond_to :title
26
+ expect(book).to respond_to :id
27
+ expect(book).to respond_to :title
28
28
  end
29
29
 
30
- context 'when book does not exist' do
30
+ context "when book does not exist" do
31
31
  before do
32
- stub_request(:get, "http://www.goodreads.com/book/isbn?format=xml&isbn=123456789&key=SECRET_KEY").
33
- to_return(:status => 404, :body => "", :headers => {})
32
+ stub_request(:get, "https://www.goodreads.com/book/isbn?format=xml&isbn=123456789&key=SECRET_KEY")
33
+ .to_return(status: 404, body: "", headers: {})
34
34
  end
35
35
 
36
- it 'raises Goodreads::NotFound' do
37
- expect { client.book_by_isbn('123456789') }.to raise_error Goodreads::NotFound
36
+ it "raises Goodreads::NotFound" do
37
+ expect { client.book_by_isbn("123456789") }.to raise_error(Goodreads::NotFound)
38
38
  end
39
39
  end
40
40
  end
41
41
 
42
- describe '#search_books' do
43
- before { stub_with_key_get('/search/index', {:q => 'Rework'}, 'search_books_by_name.xml') }
42
+ describe "#search_books" do
43
+ before { stub_with_key_get("/search/index", { q: "Rework" }, "search_books_by_name.xml") }
44
44
 
45
- it 'returns book search results' do
46
- result = client.search_books('Rework')
45
+ it "returns book search results" do
46
+ result = client.search_books("Rework")
47
47
 
48
- result.should be_a Hashie::Mash
49
- result.should respond_to :query
50
- result.should respond_to :total_results
51
- result.should respond_to :results
52
- result.results.should respond_to :work
53
- result.query.should eq 'Rework'
54
- result.results.work.size.should eq 3
55
- result.results.work.first.id.should eq 6928276
48
+ expect(result).to be_a(Hashie::Mash)
49
+ expect(result).to respond_to(:query)
50
+ expect(result).to respond_to(:total_results)
51
+ expect(result).to respond_to(:results)
52
+ expect(result.results).to respond_to(:work)
53
+ expect(result.query).to eq("Rework")
54
+ expect(result.results.work.size).to eq(3)
55
+ expect(result.results.work.first.id).to eq(6_928_276)
56
56
  end
57
57
  end
58
58
 
59
- describe '#book' do
60
- before { stub_with_key_get('/book/show', {:id => '6732019'}, 'book.xml') }
59
+ describe "#book" do
60
+ before { stub_with_key_get("/book/show", { id: "6732019" }, "book.xml") }
61
61
 
62
- it 'returns a book by goodreads id' do
63
- expect { client.book('6732019') }.not_to raise_error
62
+ it "returns a book by goodreads id" do
63
+ expect { client.book("6732019") }.not_to raise_error
64
64
  end
65
65
  end
66
66
 
67
- describe '#book_by_title' do
68
- before { stub_with_key_get('/book/title', {:title => 'Rework'}, 'book.xml') }
67
+ describe "#book_by_title" do
68
+ before { stub_with_key_get("/book/title", { title: "Rework" }, "book.xml") }
69
69
 
70
- it 'returns a book by title' do
71
- expect { client.book_by_title('Rework') }.not_to raise_error
70
+ it "returns a book by title" do
71
+ expect { client.book_by_title("Rework") }.not_to raise_error
72
72
  end
73
73
  end
74
74
 
75
- describe '#recent_reviews' do
76
- before { stub_with_key_get('/review/recent_reviews', {}, 'recent_reviews.xml') }
75
+ describe "#recent_reviews" do
76
+ before { stub_with_key_get("/review/recent_reviews", {}, "recent_reviews.xml") }
77
77
 
78
- it 'returns recent reviews' do
78
+ it "returns recent reviews" do
79
79
  reviews = client.recent_reviews
80
80
 
81
- reviews.should be_an Array
82
- reviews.should_not be_empty
83
- reviews.first.should respond_to :id
81
+ expect(reviews).to be_an(Array)
82
+ expect(reviews).to_not be_empty
83
+ expect(reviews.first).to respond_to(:id)
84
84
  end
85
85
 
86
- context 'with :skip_cropped => true' do
87
- before { stub_with_key_get('/review/recent_reviews', {}, 'recent_reviews.xml') }
88
-
89
- it 'returns only full reviews' do
90
- reviews = client.recent_reviews(:skip_cropped => true)
91
- reviews.should be_an Array
92
- reviews.should_not be_empty
86
+ context "with skip_cropped: true" do
87
+ before { stub_with_key_get("/review/recent_reviews", {}, "recent_reviews.xml") }
88
+
89
+ it "returns only full reviews" do
90
+ reviews = client.recent_reviews(skip_cropped: true)
91
+ expect(reviews).to be_an(Array)
92
+ expect(reviews).to_not be_empty
93
93
  end
94
94
  end
95
95
  end
96
96
 
97
- describe '#review' do
98
- before { stub_with_key_get('/review/show', {:id => '166204831'}, 'review.xml') }
97
+ describe "#review" do
98
+ before { stub_with_key_get("/review/show", { id: "166204831" }, "review.xml") }
99
99
 
100
- it 'returns review details' do
101
- review = client.review('166204831')
100
+ it "returns review details" do
101
+ review = client.review("166204831")
102
102
 
103
- review.should be_a Hashie::Mash
104
- review.id.should eq '166204831'
103
+ expect(review).to be_a(Hashie::Mash)
104
+ expect(review.id).to eq("166204831")
105
105
  end
106
106
 
107
- context 'when review does not exist' do
107
+ context "when review does not exist" do
108
108
  before do
109
- stub_request(:get, "http://www.goodreads.com/review/show?format=xml&id=12345&key=SECRET_KEY").
110
- to_return(:status => 404, :body => "", :headers => {})
109
+ stub_request(:get, "https://www.goodreads.com/review/show?format=xml&id=12345&key=SECRET_KEY")
110
+ .to_return(status: 404, body: "", headers: {})
111
111
  end
112
112
 
113
- it 'raises Goodreads::NotFound' do
114
- expect { client.review('12345') }.to raise_error Goodreads::NotFound
113
+ it "raises Goodreads::NotFound" do
114
+ expect { client.review("12345") }.to raise_error(Goodreads::NotFound)
115
115
  end
116
116
  end
117
117
  end
118
118
 
119
- describe '#reviews' do
119
+ describe "#reviews" do
120
120
  subject { client.reviews(id: user_id, shelf: shelf) }
121
- let(:user_id) { '5076380' }
122
- let(:shelf) { 'to-read' }
123
-
124
- before { stub_with_key_get('/review/list', {:v => '2', :id => user_id, :shelf => shelf}, response_fixture) }
125
- let(:response_fixture) { 'reviews.xml' }
126
-
127
- it 'returns a list of reviews' do
128
- subject.should be_a Array
129
- subject.count.should eq 2
130
- subject.first.should be_a Hashie::Mash
131
- subject.first.keys.should include(*['book', 'rating', 'started_at', 'read_at'])
132
- subject.map(&:id).should eq(['1371624338', '1371623371'])
121
+ let(:user_id) { "5076380" }
122
+ let(:shelf) { "to-read" }
123
+
124
+ before { stub_with_key_get("/review/list", { v: "2", id: user_id, shelf: shelf }, response_fixture) }
125
+ let(:response_fixture) { "reviews.xml" }
126
+
127
+ it "returns a list of reviews" do
128
+ expect(subject).to be_an(Array)
129
+ expect(subject.count).to eq(2)
130
+ expect(subject.first).to be_a(Hashie::Mash)
131
+ expect(subject.first.keys).to include(*%w(book rating started_at read_at))
132
+ expect(subject.map(&:id)).to eq(%w(1371624338 1371623371))
133
133
  end
134
134
 
135
- context 'when there are no more reviews' do
136
- let(:response_fixture) { 'reviews_empty.xml' }
135
+ context "when there are no more reviews" do
136
+ let(:response_fixture) { "reviews_empty.xml" }
137
137
 
138
- it 'returns an empty array' do
139
- subject.should be_a Array
140
- subject.count.should eq 0
138
+ it "returns an empty array" do
139
+ expect(subject).to be_an(Array)
140
+ expect(subject.count).to eq(0)
141
141
  end
142
142
  end
143
143
 
144
- context 'when user does not exist' do
144
+ context "when user does not exist" do
145
145
  before do
146
- stub_request(:get, "http://www.goodreads.com/review/list?v=2&format=xml&id=#{user_id}&key=SECRET_KEY&shelf=#{shelf}").
147
- to_return(:status => 404, :body => "", :headers => {})
146
+ url_params = "v=2&format=xml&id=#{user_id}&key=SECRET_KEY&shelf=#{shelf}"
147
+ stub_request(:get, "https://www.goodreads.com/review/list?#{url_params}")
148
+ .to_return(status: 404, body: "", headers: {})
148
149
  end
149
150
 
150
- it 'raises Goodreads::NotFound' do
151
- expect { subject }.to raise_error Goodreads::NotFound
151
+ it "raises Goodreads::NotFound" do
152
+ expect { subject }.to raise_error(Goodreads::NotFound)
152
153
  end
153
154
  end
154
155
  end
155
156
 
156
- describe '#author' do
157
- before { stub_with_key_get('/author/show', {:id => '18541'}, 'author.xml') }
158
-
159
- it 'returns author details' do
160
- author = client.author('18541')
161
-
162
- author.should be_a Hashie::Mash
163
- author.id.should eq '18541'
164
- author.name.should eq "Tim O'Reilly"
165
- author.link.should eq 'http://www.goodreads.com/author/show/18541.Tim_O_Reilly'
166
- author.fans_count.should eq 109
167
- author.image_url.should eq 'http://photo.goodreads.com/authors/1199698411p5/18541.jpg'
168
- author.small_image_url.should eq 'http://photo.goodreads.com/authors/1199698411p2/18541.jpg'
169
- author.about.should eq ''
170
- author.influences.should eq ''
171
- author.works_count.should eq '34'
172
- author.gender.should eq 'male'
173
- author.hometown.should eq 'Cork'
174
- author.born_at.should eq '1954/06/06'
175
- author.died_at.should be_nil
157
+ describe "#author" do
158
+ before { stub_with_key_get("/author/show", { id: "18541" }, "author.xml") }
159
+
160
+ it "returns author details" do
161
+ author = client.author("18541")
162
+
163
+ expect(author).to be_a(Hashie::Mash)
164
+ expect(author.id).to eq("18541")
165
+ expect(author.name).to eq("Tim O'Reilly")
166
+ expect(author.link).to eq("http://www.goodreads.com/author/show/18541.Tim_O_Reilly")
167
+ expect(author.fans_count).to eq(109)
168
+ expect(author.image_url).to eq("http://photo.goodreads.com/authors/1199698411p5/18541.jpg")
169
+ expect(author.small_image_url).to eq("http://photo.goodreads.com/authors/1199698411p2/18541.jpg")
170
+ expect(author.about).to eq("")
171
+ expect(author.influences).to eq("")
172
+ expect(author.works_count).to eq("34")
173
+ expect(author.gender).to eq("male")
174
+ expect(author.hometown).to eq("Cork")
175
+ expect(author.born_at).to eq("1954/06/06")
176
+ expect(author.died_at).to be_nil
176
177
  end
177
178
 
178
- context 'when author does not exist' do
179
+ context "when author does not exist" do
179
180
  before do
180
- stub_request(:get, "http://www.goodreads.com/author/show?format=xml&id=12345&key=SECRET_KEY").
181
- to_return(:status => 404, :body => "", :headers => {})
181
+ stub_request(:get, "https://www.goodreads.com/author/show?format=xml&id=12345&key=SECRET_KEY")
182
+ .to_return(status: 404, body: "", headers: {})
182
183
  end
183
184
 
184
- it 'raises Goodreads::NotFound' do
185
- expect { client.author('12345') }.to raise_error Goodreads::NotFound
185
+ it "raises Goodreads::NotFound" do
186
+ expect { client.author("12345") }.to raise_error(Goodreads::NotFound)
186
187
  end
187
188
  end
188
189
  end
189
190
 
190
- describe '#author_by_name' do
191
+ describe "#author_by_name" do
191
192
  before do
192
- stub_with_key_get('/api/author_url/Orson%20Scott%20Card', {:id => 'Orson Scott Card'}, 'author_by_name.xml')
193
+ stub_with_key_get("/api/author_url/Orson%20Scott%20Card", { id: "Orson Scott Card" }, "author_by_name.xml")
193
194
  end
194
195
 
195
- it 'returns author details' do
196
- author = client.author_by_name('Orson Scott Card')
196
+ it "returns author details" do
197
+ author = client.author_by_name("Orson Scott Card")
197
198
 
198
- author.should be_a Hashie::Mash
199
- author.id.should eq '589'
200
- author.name.should eq 'Orson Scott Card'
201
- author.link.should eq 'http://www.goodreads.com/author/show/589.Orson_Scott_Card?utm_medium=api&utm_source=author_link'
199
+ expect(author).to be_a(Hashie::Mash)
200
+ expect(author.id).to eq("589")
201
+ expect(author.name).to eq("Orson Scott Card")
202
+ expect(author.link).to eq("http://www.goodreads.com/author/show/589.Orson_Scott_Card?utm_medium=api&utm_source=author_link")
202
203
  end
203
204
  end
204
205
 
205
- describe '#user' do
206
- before { stub_with_key_get('/user/show', {:id => '878044'}, 'user.xml') }
206
+ describe "#user" do
207
+ before { stub_with_key_get("/user/show", { id: "878044" }, "user.xml") }
207
208
 
208
- it 'returns user details' do
209
- user = client.user('878044')
209
+ it "returns user details" do
210
+ user = client.user("878044")
210
211
 
211
- user.should be_a Hashie::Mash
212
- user.id.should eq '878044'
213
- user.name.should eq 'Jan'
214
- user.user_name.should eq 'janmt'
212
+ expect(user).to be_a(Hashie::Mash)
213
+ expect(user.id).to eq("878044")
214
+ expect(user.name).to eq("Jan")
215
+ expect(user.user_name).to eq("janmt")
215
216
  end
216
217
 
217
- context 'when user does not exist' do
218
+ context "when user does not exist" do
218
219
  before do
219
- stub_request(:get, "http://www.goodreads.com/user/show?format=xml&id=12345&key=SECRET_KEY").
220
- to_return(:status => 404, :body => "", :headers => {})
220
+ stub_request(:get, "https://www.goodreads.com/user/show?format=xml&id=12345&key=SECRET_KEY")
221
+ .to_return(status: 404, body: "", headers: {})
221
222
  end
222
223
 
223
- it 'raises Goodreads::NotFound' do
224
- expect { client.user('12345') }.to raise_error Goodreads::NotFound
224
+ it "raises Goodreads::NotFound" do
225
+ expect { client.user("12345") }.to raise_error(Goodreads::NotFound)
225
226
  end
226
227
  end
227
228
  end
228
229
 
229
- describe '#friends' do
230
- before { client.stub(:oauth_request).and_return(Hash.from_xml(fixture('friends.xml'))['GoodreadsResponse']) }
230
+ describe "#friends" do
231
+ before do
232
+ allow(client).to receive(:oauth_request)
233
+ .and_return(Hash.from_xml(fixture("friends.xml"))["GoodreadsResponse"])
234
+ end
231
235
 
232
- it 'returns friend details' do
233
- friends = client.friends('878044')
236
+ it "returns friend details" do
237
+ friends = client.friends("878044")
234
238
 
235
- friends.should be_an_instance_of Hashie::Mash
236
- friends.should respond_to :user
237
- friends.user.size.should eq friends.end.to_i
238
- friends.user.first.should respond_to :name
239
+ expect(friends).to be_an_instance_of(Hashie::Mash)
240
+ expect(friends).to respond_to(:user)
241
+ expect(friends.user.size).to eq(friends.end.to_i)
242
+ expect(friends.user.first).to respond_to(:name)
239
243
  end
240
244
  end
241
245
 
242
- describe '#shelf' do
246
+ describe "#shelf" do
243
247
  it "returns list of books for a user's specified shelf" do
244
- stub_with_key_get('/review/list/1.xml', {:shelf => 'to-read', :v => '2'}, 'to-read.xml')
248
+ stub_with_key_get("/review/list/1.xml", { shelf: "to-read", v: "2" }, "to-read.xml")
245
249
 
246
- shelf = client.shelf('1', 'to-read')
250
+ shelf = client.shelf("1", "to-read")
247
251
 
248
- shelf.should respond_to :start
249
- shelf.should respond_to :end
250
- shelf.should respond_to :total
251
- shelf.should respond_to :books
252
+ expect(shelf).to respond_to(:start)
253
+ expect(shelf).to respond_to(:end)
254
+ expect(shelf).to respond_to(:total)
255
+ expect(shelf).to respond_to(:books)
252
256
 
253
- shelf.start.should eq 1
254
- shelf.end.should eq 20
255
- shelf.total.should eq 40
256
- shelf.books.length.should eq 20
257
- shelf.books.first.id.should eq '45590939'
258
- shelf.books.first.book.title.strip.should eq 'The Demon-Haunted World: Science as a Candle in the Dark'
257
+ expect(shelf.start).to eq(1)
258
+ expect(shelf.end).to eq(20)
259
+ expect(shelf.total).to eq(40)
260
+ expect(shelf.books.length).to eq(20)
261
+ expect(shelf.books.first.id).to eq("45590939")
262
+ expect(shelf.books.first.book.title.strip).to eq("The Demon-Haunted World: Science as a Candle in the Dark")
259
263
  end
260
264
 
261
265
  it "paginates book lists from a user's shelf" do
262
- stub_with_key_get('/review/list/1.xml', {:shelf => 'to-read', :v => '2', :page => '2'}, 'to-read-p2.xml')
266
+ stub_with_key_get("/review/list/1.xml", { shelf: "to-read", v: "2", page: "2" }, "to-read-p2.xml")
263
267
 
264
- shelf = client.shelf('1', 'to-read', :page => 2)
268
+ shelf = client.shelf("1", "to-read", page: 2)
265
269
 
266
- shelf.start.should eq 21
267
- shelf.end.should eq 40
268
- shelf.total.should eq 40
269
- shelf.books.length.should eq 20
270
- shelf.books.first.id.should eq '107804211'
271
- shelf.books.first.book.title.should match /Your Money or Your Life/
270
+ expect(shelf.start).to eq(21)
271
+ expect(shelf.end).to eq(40)
272
+ expect(shelf.total).to eq(40)
273
+ expect(shelf.books.length).to eq(20)
274
+ expect(shelf.books.first.id).to eq("107804211")
275
+ expect(shelf.books.first.book.title).to match(/Your Money or Your Life/)
272
276
  end
273
277
 
274
278
  it "returns an empty array when shelf is empty" do
275
- stub_with_key_get('/review/list/1.xml', {:shelf => 'to-read', :v => '2'}, 'empty.xml')
279
+ stub_with_key_get("/review/list/1.xml", { shelf: "to-read", v: "2" }, "empty.xml")
276
280
 
277
- shelf = client.shelf('1', 'to-read')
281
+ shelf = client.shelf("1", "to-read")
278
282
 
279
- shelf.start.should eq 0
280
- shelf.end.should eq 0
281
- shelf.total.should eq 0
282
- shelf.books.length.should eq 0
283
+ expect(shelf.start).to eq(0)
284
+ expect(shelf.end).to eq(0)
285
+ expect(shelf.total).to eq(0)
286
+ expect(shelf.books.length).to eq(0)
283
287
  end
284
288
  end
285
289
 
286
- describe '#user_id' do
287
- let(:consumer) { OAuth::Consumer.new('API_KEY', 'SECRET_KEY', :site => 'http://www.goodreads.com') }
288
- let(:token) { OAuth::AccessToken.new(consumer, 'ACCESS_TOKEN', 'ACCESS_SECRET') }
290
+ describe "#user_id" do
291
+ let(:consumer) { OAuth::Consumer.new("API_KEY", "SECRET_KEY", site: "https://www.goodreads.com") }
292
+ let(:token) { OAuth::AccessToken.new(consumer, "ACCESS_TOKEN", "ACCESS_SECRET") }
289
293
 
290
294
  before do
291
- stub_request(:get, "http://www.goodreads.com/api/auth_user").
292
- to_return(:status => 200, :body => fixture('oauth_response.xml'), :headers => {})
295
+ stub_request(:get, "https://www.goodreads.com/api/auth_user")
296
+ .to_return(status: 200, body: fixture("oauth_response.xml"), headers: {})
293
297
  end
294
298
 
295
- it 'returns id of the user with oauth authentication' do
296
- client = Goodreads::Client.new(:api_key => 'SECRET_KEY', :oauth_token => token)
297
- client.user_id.should eq '2003928'
299
+ it "returns id of the user with oauth authentication" do
300
+ client = Goodreads::Client.new(api_key: "SECRET_KEY", oauth_token: token)
301
+ expect(client.user_id).to eq("2003928")
298
302
  end
299
303
  end
300
304
 
301
- describe '#group' do
302
- before { stub_with_key_get('/group/show', {:id => '1'}, 'group.xml') }
305
+ describe "#group" do
306
+ before { stub_with_key_get("/group/show", { id: "1" }, "group.xml") }
303
307
 
304
308
  it "returns group details" do
305
- group = client.group('1')
306
-
307
- group.should be_a Hashie::Mash
308
- group.id.should eq '1'
309
- group.title.should eq 'Goodreads Feedback'
310
- group.access.should eq 'public'
311
- group.location.should eq ''
312
- group.category.should eq 'Business'
313
- group.subcategory.should eq 'Companies'
314
- group.group_users_count.should eq '10335'
309
+ group = client.group("1")
310
+
311
+ expect(group).to be_a(Hashie::Mash)
312
+ expect(group.id).to eq("1")
313
+ expect(group.title).to eq("Goodreads Feedback")
314
+ expect(group.access).to eq("public")
315
+ expect(group.location).to eq("")
316
+ expect(group.category).to eq("Business")
317
+ expect(group.subcategory).to eq("Companies")
318
+ expect(group.group_users_count).to eq("10335")
315
319
  end
316
320
  end
317
321
 
318
- describe '#group_list' do
319
- before { stub_with_key_get('/group/list', {:id => '1', :sort => 'my_activity'}, 'group_list.xml') }
322
+ describe "#group_list" do
323
+ before { stub_with_key_get("/group/list", { id: "1", sort: "my_activity" }, "group_list.xml") }
320
324
 
321
325
  it "returns groups a given user is a member of" do
322
- group_list = client.group_list('1')
323
-
324
- group_list.should be_a Hashie::Mash
325
- group_list.total.should eq '107'
326
- group_list.group.count.should eq 50
327
- group_list.group[0].id.should eq '1'
328
- group_list.group[0].title.should eq 'Goodreads Feedback'
329
- group_list.group[1].id.should eq '220'
330
- group_list.group[2].users_count.should eq '530'
326
+ group_list = client.group_list("1")
327
+
328
+ expect(group_list).to be_a(Hashie::Mash)
329
+ expect(group_list.total).to eq("107")
330
+ expect(group_list.group.count).to eq(50)
331
+ expect(group_list.group[0].id).to eq("1")
332
+ expect(group_list.group[0].title).to eq("Goodreads Feedback")
333
+ expect(group_list.group[1].id).to eq("220")
334
+ expect(group_list.group[2].users_count).to eq("530")
331
335
  end
332
336
  end
333
337
  end