rspotify 2.3.0 → 2.3.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 +17 -15
- data/lib/rspotify/player.rb +1 -1
- data/lib/rspotify/user.rb +1 -1
- data/lib/rspotify/version.rb +1 -1
- 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: 05b5d7bcfb1b191a1903769408ddde7388cda19d
|
4
|
+
data.tar.gz: 7328f0da8b45ef1de56633000277a14fb17bc085
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 738620a4ff34654d856df9b0655e7e0f9fade0b76711ef8eabd2c0400e5cbc9bbe0ee26b91d3deade850f6c4952cf553c5e0990821f8b6ad1d3b9ed089e627f7
|
7
|
+
data.tar.gz: 3ece009096ddd3a2c36cfe3c090ba425d41a565ef611b65b262305969a4135a1f2a129accc6b09dc3a58704715fc6fa37c88e79d45f246d6141ed728a18ba5fb
|
data/lib/rspotify/connection.rb
CHANGED
@@ -3,10 +3,11 @@ require 'json'
|
|
3
3
|
require 'restclient'
|
4
4
|
|
5
5
|
module RSpotify
|
6
|
+
class MissingAuthentication < StandardError; end
|
6
7
|
|
7
|
-
API_URI = 'https://api.spotify.com/v1/'
|
8
|
-
AUTHORIZE_URI = 'https://accounts.spotify.com/authorize'
|
9
|
-
TOKEN_URI = 'https://accounts.spotify.com/api/token'
|
8
|
+
API_URI = 'https://api.spotify.com/v1/'.freeze
|
9
|
+
AUTHORIZE_URI = 'https://accounts.spotify.com/authorize'.freeze
|
10
|
+
TOKEN_URI = 'https://accounts.spotify.com/api/token'.freeze
|
10
11
|
VERBS = %w(get post put delete)
|
11
12
|
|
12
13
|
class << self
|
@@ -64,22 +65,23 @@ module RSpotify
|
|
64
65
|
response = RestClient.send(verb, url, *params)
|
65
66
|
rescue RestClient::Unauthorized => e
|
66
67
|
raise e if request_was_user_authenticated?(*params)
|
67
|
-
if @client_token
|
68
|
-
authenticate(@client_id, @client_secret)
|
69
68
|
|
70
|
-
|
71
|
-
headers['Authorization'] = "Bearer #{@client_token}"
|
69
|
+
raise MissingAuthentication unless @client_token
|
72
70
|
|
73
|
-
|
74
|
-
|
71
|
+
authenticate(@client_id, @client_secret)
|
72
|
+
|
73
|
+
headers = get_headers(params)
|
74
|
+
headers['Authorization'] = "Bearer #{@client_token}"
|
75
|
+
|
76
|
+
response = retry_connection(verb, url, params)
|
75
77
|
end
|
76
78
|
|
77
79
|
return response if raw_response
|
78
|
-
JSON.parse
|
80
|
+
JSON.parse(response) unless response.nil? || response.empty?
|
79
81
|
end
|
80
82
|
|
81
83
|
# Added this method for testing
|
82
|
-
def retry_connection
|
84
|
+
def retry_connection(verb, url, params)
|
83
85
|
RestClient.send(verb, url, *params)
|
84
86
|
end
|
85
87
|
|
@@ -90,23 +92,23 @@ module RSpotify
|
|
90
92
|
|
91
93
|
headers = get_headers(params)
|
92
94
|
if users_credentials
|
93
|
-
creds = users_credentials.map{|
|
95
|
+
creds = users_credentials.map{|_user_id, creds| "Bearer #{creds['token']}"}
|
94
96
|
|
95
97
|
if creds.include?(headers['Authorization'])
|
96
98
|
return true
|
97
99
|
end
|
98
100
|
end
|
99
|
-
|
101
|
+
|
102
|
+
false
|
100
103
|
end
|
101
104
|
|
102
105
|
def auth_header
|
103
|
-
authorization = Base64.strict_encode64
|
106
|
+
authorization = Base64.strict_encode64("#{@client_id}:#{@client_secret}")
|
104
107
|
{ 'Authorization' => "Basic #{authorization}" }
|
105
108
|
end
|
106
109
|
|
107
110
|
def get_headers(params)
|
108
111
|
params.find{|param| param.is_a?(Hash) && param['Authorization']}
|
109
112
|
end
|
110
|
-
|
111
113
|
end
|
112
114
|
end
|
data/lib/rspotify/player.rb
CHANGED
data/lib/rspotify/user.rb
CHANGED
@@ -70,7 +70,7 @@ module RSpotify
|
|
70
70
|
params[-1] = oauth_header(user_id).merge(custom_headers)
|
71
71
|
RSpotify.send(:send_request, verb, path, *params)
|
72
72
|
end
|
73
|
-
private_class_method :
|
73
|
+
private_class_method :oauth_send
|
74
74
|
|
75
75
|
RSpotify::VERBS.each do |verb|
|
76
76
|
define_singleton_method "oauth_#{verb}" do |user_id, path, *params|
|
data/lib/rspotify/version.rb
CHANGED
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: 2.3.
|
4
|
+
version: 2.3.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: 2018-
|
11
|
+
date: 2018-10-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: omniauth-oauth2
|