rspotify 2.8.0 → 2.10.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/FUNDING.yml +1 -0
- data/Gemfile +1 -1
- data/README.md +35 -1
- data/lib/rspotify/base.rb +3 -3
- data/lib/rspotify/connection.rb +1 -1
- data/lib/rspotify/player.rb +17 -0
- data/lib/rspotify/playlist.rb +2 -2
- data/lib/rspotify/user.rb +20 -4
- data/lib/rspotify/version.rb +1 -1
- data/rspotify.gemspec +1 -1
- metadata +11 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d19f6d23158c4ece9b8ede71d1b0ed2ed71598baad04895b62dc209f0147f556
|
4
|
+
data.tar.gz: 0c3b328c9b8f3ff4d87041c0d749fef09689bf922b4f7f4c9f5aa958a2d27587
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 636252d2d8d95caf3f8b07187b97fcefe22f6e6a052400d48ab200c2db47451934e37e7c4b25aa08bfddf1c0c1daf6b61fc7b0f2af19e54f25edcc0836da8731
|
7
|
+
data.tar.gz: fed825f00b36af6c3c9e2df6a6312b09219ea6d68b8136085b13ddcfa0764b747b1489a7afb1d73236a769f2fe1571617c49d709e199f7e58f1990a9bb4272e9
|
data/.github/FUNDING.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
custom: https://www.buymeacoffee.com/guilhermesad
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -217,7 +217,40 @@ class UsersController < ApplicationController
|
|
217
217
|
end
|
218
218
|
```
|
219
219
|
|
220
|
-
|
220
|
+
## Refreshing the access token
|
221
|
+
|
222
|
+
The user's access token is automatically refreshed by RSpotify when needed. This is especially useful if you persist
|
223
|
+
the user data on a database. This way, the user only need log in to Spotify once during the use of the application.
|
224
|
+
|
225
|
+
Additionally, you can store a proc that is invoked when a new access token is generated. This give you the
|
226
|
+
opportunity to persist the new access token for future use. The proc will be invoked with two arguments: the
|
227
|
+
new access token and the lifetime of the token in seconds. For example, if lifetime value returned from
|
228
|
+
Spotify is 3600, you know that the token will be good for one hour.
|
229
|
+
|
230
|
+
In the sample code below, the credentials have been retrieved from some persistent store such as
|
231
|
+
AWS SecretsManager.
|
232
|
+
|
233
|
+
```ruby
|
234
|
+
|
235
|
+
callback_proc = Proc.new { |new_access_token, token_lifetime |
|
236
|
+
now = Time.now.utc.to_i # seconds since 1/1/1970, midnight UTC
|
237
|
+
deadline = now+token_lifetime
|
238
|
+
#puts("new access token will expire at #{Time.at(deadline).utc.to_s}")
|
239
|
+
self.save_new_access_token(new_access_token)
|
240
|
+
}
|
241
|
+
|
242
|
+
spotify_user = RSpotify::User.new(
|
243
|
+
{
|
244
|
+
'credentials' => {
|
245
|
+
"token" => self.credentials["access_token"],
|
246
|
+
"refresh_token" => self.credentials["refresh_token"],
|
247
|
+
"access_refresh_callback" => callback_proc
|
248
|
+
} ,
|
249
|
+
'id' => self.credentials["user_id"]
|
250
|
+
})
|
251
|
+
|
252
|
+
|
253
|
+
```
|
221
254
|
|
222
255
|
RSpotify provides a way to facilitate persistence:
|
223
256
|
|
@@ -232,6 +265,7 @@ spotify_user = RSpotify::User.new(hash)
|
|
232
265
|
spotify_user.create_playlist!('my_awesome_playlist') # automatically refreshes token
|
233
266
|
```
|
234
267
|
|
268
|
+
|
235
269
|
## Getting raw response
|
236
270
|
|
237
271
|
To get the raw response from Spotify API requests, just toggle the `raw_response` variable:
|
data/lib/rspotify/base.rb
CHANGED
@@ -125,9 +125,9 @@ module RSpotify
|
|
125
125
|
|
126
126
|
# Generate an embed code for an album, artist or track.
|
127
127
|
# @param [Hash] options
|
128
|
-
# @option options [
|
129
|
-
# @option options [
|
130
|
-
# @option options [
|
128
|
+
# @option options [Integer] :width the width of the frame
|
129
|
+
# @option options [Integer] :height the height of the frame
|
130
|
+
# @option options [Integer] :frameborder the frameborder of the frame
|
131
131
|
# @option options [Boolean] :allowtransparency toggle frame transparency
|
132
132
|
# @option options [nil|String|Symbol] :view specific view option for iframe
|
133
133
|
# @option options [nil|String|Symbol] :theme specific theme option for iframe
|
data/lib/rspotify/connection.rb
CHANGED
@@ -67,7 +67,7 @@ module RSpotify
|
|
67
67
|
rescue RestClient::Unauthorized => e
|
68
68
|
raise e if request_was_user_authenticated?(*params)
|
69
69
|
|
70
|
-
raise MissingAuthentication unless @
|
70
|
+
raise MissingAuthentication unless @client_id && @client_secret
|
71
71
|
|
72
72
|
authenticate(@client_id, @client_secret)
|
73
73
|
|
data/lib/rspotify/player.rb
CHANGED
@@ -9,6 +9,8 @@ module RSpotify
|
|
9
9
|
@progress = options['progress_ms']
|
10
10
|
@is_playing = options['is_playing']
|
11
11
|
@currently_playing_type = options['currently_playing_type']
|
12
|
+
@context_type = options.dig('context', 'type')
|
13
|
+
@context_uri = options.dig('context', 'uri')
|
12
14
|
|
13
15
|
@track = if options['track']
|
14
16
|
Track.new options['track']
|
@@ -71,6 +73,21 @@ module RSpotify
|
|
71
73
|
User.oauth_put(@user.id, url, params.to_json)
|
72
74
|
end
|
73
75
|
|
76
|
+
# Add an item to the end of the user’s current playback queue
|
77
|
+
# If `device_id` is not passed, the currently active spotify app will be triggered
|
78
|
+
#
|
79
|
+
# @param [String] device_id the ID of the device to set the repeat state on.
|
80
|
+
# @param [String] uri the spotify uri of the track to be queued
|
81
|
+
#
|
82
|
+
# @example
|
83
|
+
# player = user.player
|
84
|
+
# player.queue("spotify:track:4iV5W9uYEdYUVa79Axb7Rh")
|
85
|
+
def queue(device_id = nil, uri)
|
86
|
+
url = "me/player/queue?uri=#{uri}"
|
87
|
+
url = device_id.nil? ? url : "#{url}&device_id=#{device_id}"
|
88
|
+
User.oauth_post(@user.id, url, {})
|
89
|
+
end
|
90
|
+
|
74
91
|
# Toggle the current user's player repeat status.
|
75
92
|
# If `device_id` is not passed, the currently active spotify app will be triggered.
|
76
93
|
# If `state` is not passed, the currently active context will be set to repeat.
|
data/lib/rspotify/playlist.rb
CHANGED
@@ -303,7 +303,7 @@ module RSpotify
|
|
303
303
|
# positions = [0,3,8]
|
304
304
|
# playlist.remove_tracks!(positions, snapshot_id: '0ZvtH...')
|
305
305
|
def remove_tracks!(tracks, snapshot_id: nil)
|
306
|
-
positions = tracks if tracks.first.is_a?
|
306
|
+
positions = tracks if tracks.first.is_a? Integer
|
307
307
|
|
308
308
|
tracks = tracks.map do |track|
|
309
309
|
next { uri: track.uri } if track.is_a? Track
|
@@ -390,7 +390,7 @@ module RSpotify
|
|
390
390
|
def replace_tracks!(tracks)
|
391
391
|
track_uris = tracks.map(&:uri).join(',')
|
392
392
|
url = "#{@path}/tracks?uris=#{track_uris}"
|
393
|
-
User.oauth_put(@owner.id, url, {})
|
393
|
+
User.oauth_put(@owner.id, url, {}.to_json)
|
394
394
|
|
395
395
|
@total = tracks.size
|
396
396
|
@tracks_cache = nil
|
data/lib/rspotify/user.rb
CHANGED
@@ -38,6 +38,16 @@ module RSpotify
|
|
38
38
|
response = RestClient.post(TOKEN_URI, request_body, RSpotify.send(:auth_header))
|
39
39
|
response = JSON.parse(response)
|
40
40
|
@@users_credentials[user_id]['token'] = response['access_token']
|
41
|
+
access_refresh_proc = @@users_credentials[user_id]['access_refresh_callback']
|
42
|
+
# If the access token expires and a new one is granted via the refresh
|
43
|
+
# token, then this proc will be called with two parameters:
|
44
|
+
# new_access_token and token_lifetime (in seconds)
|
45
|
+
# The purpose is to allow the calling environment to invoke some action,
|
46
|
+
# such as persisting the new access token somewhere, when the new token
|
47
|
+
# is generated.
|
48
|
+
if (access_refresh_proc.respond_to? :call)
|
49
|
+
access_refresh_proc.call(response['access_token'], response['expires_in'])
|
50
|
+
end
|
41
51
|
rescue RestClient::BadRequest => e
|
42
52
|
raise e if e.response !~ /Refresh token revoked/
|
43
53
|
end
|
@@ -104,6 +114,8 @@ module RSpotify
|
|
104
114
|
# Creates a playlist in user's Spotify account. This method is only available when the current
|
105
115
|
# user has granted access to the *playlist-modify-public* and *playlist-modify-private* scopes.
|
106
116
|
#
|
117
|
+
# @note To create a collaborative playlist the public option must be set to false.
|
118
|
+
#
|
107
119
|
# @param name [String] The name for the new playlist
|
108
120
|
# @param public [Boolean] Whether the playlist is public or private. Default: true
|
109
121
|
# @return [Playlist]
|
@@ -116,10 +128,14 @@ module RSpotify
|
|
116
128
|
# playlist = user.create_playlist!('my-second-playlist', public: false)
|
117
129
|
# playlist.name #=> "my-second-playlist"
|
118
130
|
# playlist.public #=> false
|
119
|
-
def create_playlist!(name, public: true)
|
131
|
+
def create_playlist!(name, description: nil, public: true, collaborative: false)
|
120
132
|
url = "users/#{@id}/playlists"
|
121
|
-
request_data = {
|
122
|
-
|
133
|
+
request_data = {
|
134
|
+
name: name,
|
135
|
+
public: public,
|
136
|
+
description: description,
|
137
|
+
collaborative: collaborative
|
138
|
+
}.to_json
|
123
139
|
response = User.oauth_post(@id, url, request_data)
|
124
140
|
return response if RSpotify.raw_response
|
125
141
|
Playlist.new response
|
@@ -133,7 +149,7 @@ module RSpotify
|
|
133
149
|
url = "me/player"
|
134
150
|
response = User.oauth_get(@id, url)
|
135
151
|
return response if RSpotify.raw_response
|
136
|
-
response
|
152
|
+
response ? Player.new(self, response) : Player.new(self)
|
137
153
|
end
|
138
154
|
|
139
155
|
# Get the current user’s recently played tracks. Requires the *user-read-recently-played* scope.
|
data/lib/rspotify/version.rb
CHANGED
data/rspotify.gemspec
CHANGED
@@ -16,7 +16,7 @@ Gem::Specification.new do |spec|
|
|
16
16
|
spec.test_files = spec.files.grep(/^spec\//)
|
17
17
|
spec.require_paths = ['lib']
|
18
18
|
|
19
|
-
spec.add_dependency 'omniauth-oauth2', '
|
19
|
+
spec.add_dependency 'omniauth-oauth2', '>= 1.6'
|
20
20
|
spec.add_dependency 'rest-client', '~> 2.0.2'
|
21
21
|
spec.add_dependency 'addressable', '~> 2.5.2'
|
22
22
|
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspotify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.10.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Guilherme Sad
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-12-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: omniauth-oauth2
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 1.
|
19
|
+
version: '1.6'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 1.
|
26
|
+
version: '1.6'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rest-client
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -136,7 +136,7 @@ dependencies:
|
|
136
136
|
- - "~>"
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: '3.0'
|
139
|
-
description:
|
139
|
+
description:
|
140
140
|
email:
|
141
141
|
- gorgulhoguilherme@gmail.com
|
142
142
|
executables: []
|
@@ -144,6 +144,7 @@ extensions: []
|
|
144
144
|
extra_rdoc_files: []
|
145
145
|
files:
|
146
146
|
- ".editorconfig"
|
147
|
+
- ".github/FUNDING.yml"
|
147
148
|
- ".gitignore"
|
148
149
|
- ".rspec"
|
149
150
|
- ".travis.yml"
|
@@ -260,7 +261,7 @@ homepage: http://rubygems.org/gems/rspotify
|
|
260
261
|
licenses:
|
261
262
|
- MIT
|
262
263
|
metadata: {}
|
263
|
-
post_install_message:
|
264
|
+
post_install_message:
|
264
265
|
rdoc_options: []
|
265
266
|
require_paths:
|
266
267
|
- lib
|
@@ -276,7 +277,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
276
277
|
version: '0'
|
277
278
|
requirements: []
|
278
279
|
rubygems_version: 3.0.6
|
279
|
-
signing_key:
|
280
|
+
signing_key:
|
280
281
|
specification_version: 4
|
281
282
|
summary: A ruby wrapper for the Spotify Web API
|
282
283
|
test_files:
|