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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cdb5d05c82ca5e425422843ec89590e50eeda168
4
- data.tar.gz: e3178dcd15a55d6efff239aa384b4a2c48a2f721
3
+ metadata.gz: 05b5d7bcfb1b191a1903769408ddde7388cda19d
4
+ data.tar.gz: 7328f0da8b45ef1de56633000277a14fb17bc085
5
5
  SHA512:
6
- metadata.gz: fb4206df7dd0b654bd9186488027f047ceba828b7db72a870f8775b8f068b668cf8d722a2af2ceb4dc701f710e98fdb990d1c8739436c30401f5e17e5e02519e
7
- data.tar.gz: f83a6ee536693dd4616811a1fcc965f788680ca4b6c09296667e5f5c8a6c7e80c9e10b4cf45f5e29bef683b42629d84e7116f0cdda54c9730a4c4c76f747190b
6
+ metadata.gz: 738620a4ff34654d856df9b0655e7e0f9fade0b76711ef8eabd2c0400e5cbc9bbe0ee26b91d3deade850f6c4952cf553c5e0990821f8b6ad1d3b9ed089e627f7
7
+ data.tar.gz: 3ece009096ddd3a2c36cfe3c090ba425d41a565ef611b65b262305969a4135a1f2a129accc6b09dc3a58704715fc6fa37c88e79d45f246d6141ed728a18ba5fb
@@ -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
- headers = get_headers(params)
71
- headers['Authorization'] = "Bearer #{@client_token}"
69
+ raise MissingAuthentication unless @client_token
72
70
 
73
- response = retry_connection verb, url, params
74
- end
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 response unless response.nil? || response.empty?
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 verb, url, params
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{|user_id, creds| "Bearer #{creds['token']}"}
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
- return false
101
+
102
+ false
100
103
  end
101
104
 
102
105
  def auth_header
103
- authorization = Base64.strict_encode64 "#{@client_id}:#{@client_secret}"
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
@@ -98,7 +98,7 @@ module RSpotify
98
98
  end
99
99
 
100
100
  def seek(position_ms)
101
- url = "/me/player/seek?position_ms=#{position_ms}"
101
+ url = "me/player/seek?position_ms=#{position_ms}"
102
102
  User.oauth_put(@user.id, url, {})
103
103
  end
104
104
  end
@@ -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 :oauth_header
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|
@@ -1,3 +1,3 @@
1
1
  module RSpotify
2
- VERSION = '2.3.0'
2
+ VERSION = '2.3.1'
3
3
  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: 2.3.0
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-09-17 00:00:00.000000000 Z
11
+ date: 2018-10-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: omniauth-oauth2