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 +4 -4
- data/lib/rspotify/connection.rb +20 -2
- data/lib/rspotify/version.rb +1 -1
- data/spec/authentication_helper.rb +11 -0
- data/spec/lib/rspotify/album_spec.rb +2 -6
- data/spec/lib/rspotify/audio_features_spec.rb +1 -3
- data/spec/lib/rspotify/category_spec.rb +1 -3
- data/spec/lib/rspotify/client_token_spec.rb +9 -0
- data/spec/lib/rspotify/playlist_spec.rb +1 -3
- data/spec/lib/rspotify/recommendations_spec.rb +1 -3
- data/spec/lib/rspotify/track_spec.rb +1 -3
- data/spec/lib/rspotify/user_spec.rb +1 -3
- data/spec/spec_helper.rb +2 -1
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 329704cda3c04b00d6fd736a343ff454ae10bab0
|
4
|
+
data.tar.gz: 99112da79287ac9ae9d4dad05dfda682973d79fc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f39f9a8d1d9747ae269676f13b5e672028e398097da3f667417239228905922bd8460f29bd0d0eb081df659d5ce29cdb86b232059b32f42c64b05670c4c3971e
|
7
|
+
data.tar.gz: 35603e5d98e9e732ab289e55f51dea5648fbd7b1f82899cf76848c47b42e3f738c851546567546df397a254484a87acebf904b53a8582523301b18ab47f48f47
|
data/lib/rspotify/connection.rb
CHANGED
@@ -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 #{
|
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}" }
|
data/lib/rspotify/version.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
9
|
-
RSpotify.authenticate(client_id, client_secret)
|
10
|
-
end
|
8
|
+
authenticate_client
|
11
9
|
end
|
12
10
|
|
13
11
|
describe 'Category::find' do
|
@@ -4,9 +4,7 @@ describe RSpotify::Recommendations do
|
|
4
4
|
let(:client_secret) { '155fc038a85840679b55a1822ef36b9b' }
|
5
5
|
|
6
6
|
before do
|
7
|
-
|
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
|
-
|
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
|
-
|
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
|
data/spec/spec_helper.rb
CHANGED
@@ -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.
|
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:
|
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
|