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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3a7ce4a25d971ff2ecaed66fcf716dc165c015cd
4
- data.tar.gz: f18c09b1dddd737eb59f33c2d408208b7f82d522
3
+ metadata.gz: c1f2cb1c508d26a9c6309cba7ca13a85e0f20388
4
+ data.tar.gz: 5d1f918f508b01cc1063c21950cb057c04fe580f
5
5
  SHA512:
6
- metadata.gz: ebddd5cafe9200d6523c604fd88d3972e92bae5f70d34de9d316475dc2d57f4b574850128bc3090303cc886a5d44c6645e2bfa755376745fec70f6b1022d85f5
7
- data.tar.gz: 93fc3eefd76fed937f9261004257c6efb2e29a627e1d92286867790a8b7b2959c2bdc31f4562f51c39478c419598c2261ae884d8acbedab4d1a6e82748f26642
6
+ metadata.gz: 8cce89b90a3c547666c6ecca34ebaff3a117fcf68a631faadd963382eeb4eb79472fe310d509597c868b50e08f61932680f89bc23b372daf09cee732890b7d15
7
+ data.tar.gz: 6adc0d88e9a2c75a6055671662696718d9bf353e7c78bfd459130ce399804f5ffccd6258f98ddb29edd42534669512258dc8cb2f854d9ec2fb3aded95e374ee3
@@ -63,13 +63,22 @@ module RSpotify
63
63
  rescue RestClient::Unauthorized
64
64
  if @client_token
65
65
  authenticate(@client_id, @client_secret)
66
- response = RestClient.send(verb, url, *params)
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}"
@@ -1,3 +1,3 @@
1
1
  module RSpotify
2
- VERSION = '1.22.0'
2
+ VERSION = '1.22.1'
3
3
  end
@@ -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.0
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-30 00:00:00.000000000 Z
11
+ date: 2017-07-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: omniauth-oauth2