rspotify 1.25.0 → 1.25.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: 943084e2909b53a19452860de7622fdd2b560fcd
4
- data.tar.gz: a3949ea7c84455b591823b2771403053df0cbbe6
3
+ metadata.gz: 329704cda3c04b00d6fd736a343ff454ae10bab0
4
+ data.tar.gz: 99112da79287ac9ae9d4dad05dfda682973d79fc
5
5
  SHA512:
6
- metadata.gz: 3f317d488ee29a682d3aaf5e0af397057017ff1852a61d98ad2cb38b26d32097623aeddb410034e6911af65f9a5b6640d6533f861b44742afa6b0d8626999b53
7
- data.tar.gz: 6cc388d0d04d78f07b47002f439b358865f1f4dce1fcb21bc24642f107ed2579691f360281565b6fa6073b8ff42f2332dfd0be551b32583a10161cd91e6269b1
6
+ metadata.gz: f39f9a8d1d9747ae269676f13b5e672028e398097da3f667417239228905922bd8460f29bd0d0eb081df659d5ce29cdb86b232059b32f42c64b05670c4c3971e
7
+ data.tar.gz: 35603e5d98e9e732ab289e55f51dea5648fbd7b1f82899cf76848c47b42e3f738c851546567546df397a254484a87acebf904b53a8582523301b18ab47f48f47
@@ -11,6 +11,7 @@ module RSpotify
11
11
 
12
12
  class << self
13
13
  attr_accessor :raw_response
14
+ attr_reader :client_token
14
15
 
15
16
  # Authenticates access to restricted data. Requires {https://developer.spotify.com/my-applications user credentials}
16
17
  #
@@ -32,7 +33,7 @@ module RSpotify
32
33
 
33
34
  VERBS.each do |verb|
34
35
  define_method verb do |path, *params|
35
- params << { 'Authorization' => "Bearer #{@client_token}" } if @client_token
36
+ params << { 'Authorization' => "Bearer #{client_token}" } if client_token
36
37
  send_request(verb, path, *params)
37
38
  end
38
39
  end
@@ -60,7 +61,8 @@ module RSpotify
60
61
 
61
62
  begin
62
63
  response = RestClient.send(verb, url, *params)
63
- rescue RestClient::Unauthorized
64
+ rescue RestClient::Unauthorized => e
65
+ raise e if request_was_user_authenticated?(*params)
64
66
  if @client_token
65
67
  authenticate(@client_id, @client_secret)
66
68
 
@@ -80,6 +82,22 @@ module RSpotify
80
82
  RestClient.send(verb, url, *params)
81
83
  end
82
84
 
85
+ def request_was_user_authenticated?(*params)
86
+ users_credentials = if User.class_variable_defined?('@@users_credentials')
87
+ User.class_variable_get('@@users_credentials')
88
+ end
89
+
90
+ obj = params.find{|x| x.is_a?(Hash) && x['Authorization']}
91
+ if users_credentials
92
+ creds = users_credentials.map{|user_id, creds| "Bearer #{creds['token']}"}
93
+
94
+ if creds.include?(obj['Authorization'])
95
+ return true
96
+ end
97
+ end
98
+ return false
99
+ end
100
+
83
101
  def auth_header
84
102
  authorization = Base64.strict_encode64 "#{@client_id}:#{@client_secret}"
85
103
  { 'Authorization' => "Basic #{authorization}" }
@@ -1,3 +1,3 @@
1
1
  module RSpotify
2
- VERSION = '1.25.0'
2
+ VERSION = '1.25.1'
3
3
  end
@@ -0,0 +1,11 @@
1
+ module AuthenticationHelper
2
+ CLIENT_SECRET = 'BQBj_AiSFlKCkNIMbCWEYjuJLl6n76QmVsHU6MGDgTUBLZqNiKZ4ALs6Kvm6ulbsW9O81JDdIHyXBndXyhUOxg'
3
+
4
+ def authenticate_client
5
+ client_id = '5ac1cda2ad354aeaa1ad2693d33bb98c'
6
+ client_secret = '155fc038a85840679b55a1822ef36b9b'
7
+ VCR.use_cassette('authenticate:client') do
8
+ RSpotify.authenticate(client_id, client_secret)
9
+ end
10
+ end
11
+ end
@@ -92,9 +92,7 @@ describe RSpotify::Album do
92
92
  let(:client_secret) { '155fc038a85840679b55a1822ef36b9b' }
93
93
 
94
94
  before(:each) do
95
- VCR.use_cassette('authenticate:client') do
96
- RSpotify.authenticate(client_id, client_secret)
97
- end
95
+ authenticate_client
98
96
  end
99
97
 
100
98
  it 'should find the appropriate new releases' do
@@ -126,9 +124,7 @@ describe RSpotify::Album do
126
124
  let(:client_secret) { '155fc038a85840679b55a1822ef36b9b' }
127
125
 
128
126
  before(:each) do
129
- VCR.use_cassette('authenticate:client') do
130
- RSpotify.authenticate(client_id, client_secret)
131
- end
127
+ authenticate_client
132
128
  end
133
129
 
134
130
  it 'should search for the right albums' do
@@ -4,9 +4,7 @@ describe RSpotify::AudioFeatures do
4
4
  let(:client_secret) { '155fc038a85840679b55a1822ef36b9b' }
5
5
 
6
6
  before do
7
- VCR.use_cassette('authenticate:client') do
8
- RSpotify.authenticate(client_id, client_secret)
9
- end
7
+ authenticate_client
10
8
  end
11
9
 
12
10
  describe 'AudioFeatures::find' do
@@ -5,9 +5,7 @@ describe RSpotify::Category do
5
5
  let(:client_secret) { '155fc038a85840679b55a1822ef36b9b' }
6
6
 
7
7
  before do
8
- VCR.use_cassette('authenticate:client') do
9
- RSpotify.authenticate(client_id, client_secret)
10
- end
8
+ authenticate_client
11
9
  end
12
10
 
13
11
  describe 'Category::find' do
@@ -0,0 +1,9 @@
1
+ describe RSpotify do
2
+ describe '.client_token' do
3
+ it 'should return the client_token' do
4
+ authenticate_client
5
+
6
+ expect(RSpotify.client_token).to eq(AuthenticationHelper::CLIENT_SECRET)
7
+ end
8
+ end
9
+ end
@@ -10,9 +10,7 @@ describe RSpotify::Playlist do
10
10
  end
11
11
 
12
12
  before do
13
- VCR.use_cassette('authenticate:client') do
14
- RSpotify.authenticate(client_id, client_secret)
15
- end
13
+ authenticate_client
16
14
  end
17
15
 
18
16
  describe 'Playlist::browse_featured' do
@@ -4,9 +4,7 @@ describe RSpotify::Recommendations do
4
4
  let(:client_secret) { '155fc038a85840679b55a1822ef36b9b' }
5
5
 
6
6
  before do
7
- VCR.use_cassette('authenticate:client') do
8
- RSpotify.authenticate(client_id, client_secret)
9
- end
7
+ authenticate_client
10
8
  end
11
9
 
12
10
  describe 'Recommendations::available_genre_seeds' do
@@ -141,9 +141,7 @@ describe RSpotify::Track do
141
141
  let(:client_secret) { '155fc038a85840679b55a1822ef36b9b' }
142
142
 
143
143
  before do
144
- VCR.use_cassette('authenticate:client') do
145
- RSpotify.authenticate(client_id, client_secret)
146
- end
144
+ authenticate_client
147
145
  end
148
146
 
149
147
  let(:track) do
@@ -22,9 +22,7 @@ describe RSpotify::User do
22
22
  # Keys generated specifically for the tests. Should be removed in the future
23
23
  client_id = '5ac1cda2ad354aeaa1ad2693d33bb98c'
24
24
  client_secret = '155fc038a85840679b55a1822ef36b9b'
25
- VCR.use_cassette('authenticate:client') do
26
- RSpotify.authenticate(client_id, client_secret)
27
- end
25
+ authenticate_client
28
26
 
29
27
  playlists = VCR.use_cassette('user:wizzler:playlists:limit:20:offset:0') do
30
28
  @user.playlists
@@ -1,6 +1,7 @@
1
1
  require 'rspotify'
2
2
  require 'vcr'
3
3
  require 'webmock/rspec'
4
+ require 'authentication_helper'
4
5
 
5
6
  VCR.configure do |c|
6
7
  c.cassette_library_dir = 'spec/vcr_cassettes'
@@ -9,7 +10,7 @@ end
9
10
 
10
11
 
11
12
  RSpec.configure do |config|
12
-
13
+ config.include AuthenticationHelper
13
14
  config.filter_run :focus
14
15
  config.run_all_when_everything_filtered = true
15
16
 
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.25.0
4
+ version: 1.25.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-12-21 00:00:00.000000000 Z
11
+ date: 2018-01-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: omniauth-oauth2
@@ -153,10 +153,12 @@ files:
153
153
  - lib/rspotify/user.rb
154
154
  - lib/rspotify/version.rb
155
155
  - rspotify.gemspec
156
+ - spec/authentication_helper.rb
156
157
  - spec/lib/rspotify/album_spec.rb
157
158
  - spec/lib/rspotify/artist_spec.rb
158
159
  - spec/lib/rspotify/audio_features_spec.rb
159
160
  - spec/lib/rspotify/category_spec.rb
161
+ - spec/lib/rspotify/client_token_spec.rb
160
162
  - spec/lib/rspotify/playlist_spec.rb
161
163
  - spec/lib/rspotify/recommendations_spec.rb
162
164
  - spec/lib/rspotify/track_spec.rb
@@ -258,10 +260,12 @@ signing_key:
258
260
  specification_version: 4
259
261
  summary: A ruby wrapper for the Spotify Web API
260
262
  test_files:
263
+ - spec/authentication_helper.rb
261
264
  - spec/lib/rspotify/album_spec.rb
262
265
  - spec/lib/rspotify/artist_spec.rb
263
266
  - spec/lib/rspotify/audio_features_spec.rb
264
267
  - spec/lib/rspotify/category_spec.rb
268
+ - spec/lib/rspotify/client_token_spec.rb
265
269
  - spec/lib/rspotify/playlist_spec.rb
266
270
  - spec/lib/rspotify/recommendations_spec.rb
267
271
  - spec/lib/rspotify/track_spec.rb