rspotify 1.22.0 → 1.22.1
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/lib/rspotify/connection.rb +10 -1
- data/lib/rspotify/version.rb +1 -1
- data/spec/lib/rspotify/artist_spec.rb +27 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c1f2cb1c508d26a9c6309cba7ca13a85e0f20388
|
4
|
+
data.tar.gz: 5d1f918f508b01cc1063c21950cb057c04fe580f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8cce89b90a3c547666c6ecca34ebaff3a117fcf68a631faadd963382eeb4eb79472fe310d509597c868b50e08f61932680f89bc23b372daf09cee732890b7d15
|
7
|
+
data.tar.gz: 6adc0d88e9a2c75a6055671662696718d9bf353e7c78bfd459130ce399804f5ffccd6258f98ddb29edd42534669512258dc8cb2f854d9ec2fb3aded95e374ee3
|
data/lib/rspotify/connection.rb
CHANGED
@@ -63,13 +63,22 @@ module RSpotify
|
|
63
63
|
rescue RestClient::Unauthorized
|
64
64
|
if @client_token
|
65
65
|
authenticate(@client_id, @client_secret)
|
66
|
-
|
66
|
+
|
67
|
+
obj = params.find{|x| x.is_a?(Hash) && x['Authorization']}
|
68
|
+
obj['Authorization'] = "Bearer #{@client_token}"
|
69
|
+
|
70
|
+
response = retry_connection verb, url, params
|
67
71
|
end
|
68
72
|
end
|
69
73
|
|
70
74
|
return response if raw_response
|
71
75
|
JSON.parse response unless response.empty?
|
72
76
|
end
|
77
|
+
|
78
|
+
# Added this method for testing
|
79
|
+
def retry_connection verb, url, params
|
80
|
+
RestClient.send(verb, url, *params)
|
81
|
+
end
|
73
82
|
|
74
83
|
def auth_header
|
75
84
|
authorization = Base64.strict_encode64 "#{@client_id}:#{@client_secret}"
|
data/lib/rspotify/version.rb
CHANGED
@@ -111,5 +111,32 @@ describe RSpotify::Artist do
|
|
111
111
|
expect(artists.size) .to eq 20
|
112
112
|
expect(artists.map(&:name)) .to include('Arctic Queen', 'Arctic Sleep')
|
113
113
|
end
|
114
|
+
|
115
|
+
|
116
|
+
context 'when token is expired' do
|
117
|
+
it 'should resend token with new token' do
|
118
|
+
auth_response = {'access_token': 'token'}.to_json
|
119
|
+
new_auth_response = {'access_token': 'new_token'}.to_json
|
120
|
+
|
121
|
+
expect(RestClient).to receive(:post)
|
122
|
+
.and_return(auth_response, new_auth_response)
|
123
|
+
|
124
|
+
RSpotify.authenticate('client_id', 'client_secret')
|
125
|
+
|
126
|
+
# When token is expired it returns 401
|
127
|
+
expect(RestClient).to receive(:send).and_raise(RestClient::Unauthorized)
|
128
|
+
.with(anything, anything, {"Authorization" => "Bearer token"})
|
129
|
+
|
130
|
+
retry_response = {
|
131
|
+
"artists" => { "items" => [] }
|
132
|
+
}.to_json
|
133
|
+
expect(RestClient).to receive(:send).and_return(retry_response)
|
134
|
+
.with(anything, anything, {"Authorization" => "Bearer new_token"})
|
135
|
+
|
136
|
+
artists = VCR.use_cassette('artist:search:Arctic') do
|
137
|
+
RSpotify::Artist.search('Arctic')
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
114
141
|
end
|
115
142
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspotify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.22.
|
4
|
+
version: 1.22.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Guilherme Sad
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-05
|
11
|
+
date: 2017-07-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: omniauth-oauth2
|