rspotify 2.5.0 → 2.9.0
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 +5 -5
- data/lib/rspotify/base.rb +4 -5
- data/lib/rspotify/connection.rb +1 -1
- data/lib/rspotify/player.rb +53 -12
- data/lib/rspotify/playlist.rb +1 -1
- data/lib/rspotify/user.rb +23 -6
- data/lib/rspotify/version.rb +1 -1
- metadata +7 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: bd4464a0bd9145130472ed8f8abe11c595e3e5065a44e083d7a41ef26a315dad
|
4
|
+
data.tar.gz: a81d26ab41cfb8ff340eb30a39f6d878503481378757ca4cc480db89c147bd07
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 23d30c3094d7c243733190ca8e02231159968027a3d3b30eb72c0d8fb0694ecde85bb0b7c3327b86021a624bfa96890f33315d8acb134f67396124068c4bcee2
|
7
|
+
data.tar.gz: ec899b94e25402f6a22ba6e9ecca3be4ced60f763ed4108d3f206d6f054449ce3f6d3b3b1eab4b4cc47053532c3320756d382d5a11bc2c41b966c51fbaf6be3c
|
data/lib/rspotify/base.rb
CHANGED
@@ -30,7 +30,6 @@ module RSpotify
|
|
30
30
|
warn 'Spotify API does not support finding several users simultaneously'
|
31
31
|
return false
|
32
32
|
end
|
33
|
-
limit = (type == 'album' ? 20 : 50)
|
34
33
|
find_many(ids, type, market: market)
|
35
34
|
when String
|
36
35
|
id = ids
|
@@ -126,9 +125,9 @@ module RSpotify
|
|
126
125
|
|
127
126
|
# Generate an embed code for an album, artist or track.
|
128
127
|
# @param [Hash] options
|
129
|
-
# @option options [
|
130
|
-
# @option options [
|
131
|
-
# @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
|
132
131
|
# @option options [Boolean] :allowtransparency toggle frame transparency
|
133
132
|
# @option options [nil|String|Symbol] :view specific view option for iframe
|
134
133
|
# @option options [nil|String|Symbol] :theme specific theme option for iframe
|
@@ -143,7 +142,7 @@ module RSpotify
|
|
143
142
|
frameborder: 0,
|
144
143
|
allowtransparency: true,
|
145
144
|
view: nil,
|
146
|
-
theme: nil
|
145
|
+
theme: nil
|
147
146
|
}
|
148
147
|
options = default_options.merge(options)
|
149
148
|
|
data/lib/rspotify/connection.rb
CHANGED
@@ -9,7 +9,7 @@ module RSpotify
|
|
9
9
|
API_URI = 'https://api.spotify.com/v1/'.freeze
|
10
10
|
AUTHORIZE_URI = 'https://accounts.spotify.com/authorize'.freeze
|
11
11
|
TOKEN_URI = 'https://accounts.spotify.com/api/token'.freeze
|
12
|
-
VERBS = %w
|
12
|
+
VERBS = %w[get post put delete].freeze
|
13
13
|
|
14
14
|
class << self
|
15
15
|
attr_accessor :raw_response
|
data/lib/rspotify/player.rb
CHANGED
@@ -4,18 +4,19 @@ module RSpotify
|
|
4
4
|
def initialize(user, options = {})
|
5
5
|
@user = user
|
6
6
|
|
7
|
-
@repeat_state
|
8
|
-
@shuffle_state
|
9
|
-
@progress
|
10
|
-
@is_playing
|
7
|
+
@repeat_state = options['repeat_state']
|
8
|
+
@shuffle_state = options['shuffle_state']
|
9
|
+
@progress = options['progress_ms']
|
10
|
+
@is_playing = options['is_playing']
|
11
|
+
@currently_playing_type = options['currently_playing_type']
|
11
12
|
|
12
13
|
@track = if options['track']
|
13
|
-
|
14
|
-
|
14
|
+
Track.new options['track']
|
15
|
+
end
|
15
16
|
|
16
17
|
@device = if options['device']
|
17
|
-
|
18
|
-
|
18
|
+
Device.new options['device']
|
19
|
+
end
|
19
20
|
end
|
20
21
|
|
21
22
|
def playing?
|
@@ -28,7 +29,7 @@ module RSpotify
|
|
28
29
|
# @example
|
29
30
|
# player = user.player
|
30
31
|
# player.play_context(nil,"spotify:album:1Je1IMUlBXcx1Fz0WE7oPT")
|
31
|
-
def play_context(device_id=nil, uri)
|
32
|
+
def play_context(device_id = nil, uri)
|
32
33
|
params = {"context_uri": uri}
|
33
34
|
play(device_id, params)
|
34
35
|
end
|
@@ -40,7 +41,7 @@ module RSpotify
|
|
40
41
|
# player = user.player
|
41
42
|
# tracks_uris = ["spotify:track:4iV5W9uYEdYUVa79Axb7Rh", "spotify:track:1301WleyT98MSxVHPZCA6M"]
|
42
43
|
# player.play_tracks(nil, tracks_uris)
|
43
|
-
def play_tracks(device_id=nil, uris)
|
44
|
+
def play_tracks(device_id = nil, uris)
|
44
45
|
params = {"uris": uris}
|
45
46
|
play(device_id, params)
|
46
47
|
end
|
@@ -52,7 +53,7 @@ module RSpotify
|
|
52
53
|
# player = user.player
|
53
54
|
# player.play_track(nil, "spotify:track:4iV5W9uYEdYUVa79Axb7Rh")
|
54
55
|
# # User must be a premium subscriber for this feature to work.
|
55
|
-
def play_track(device_id=nil, uri)
|
56
|
+
def play_track(device_id = nil, uri)
|
56
57
|
params = {"uris": [uri]}
|
57
58
|
play(device_id, params)
|
58
59
|
end
|
@@ -65,11 +66,31 @@ module RSpotify
|
|
65
66
|
# player.play
|
66
67
|
def play(device_id = nil, params = {})
|
67
68
|
url = "me/player/play"
|
68
|
-
url = device_id.nil? ? url : url
|
69
|
+
url = device_id.nil? ? url : "#{url}?device_id=#{device_id}"
|
69
70
|
|
70
71
|
User.oauth_put(@user.id, url, params.to_json)
|
71
72
|
end
|
72
73
|
|
74
|
+
# Toggle the current user's player repeat status.
|
75
|
+
# If `device_id` is not passed, the currently active spotify app will be triggered.
|
76
|
+
# If `state` is not passed, the currently active context will be set to repeat.
|
77
|
+
#
|
78
|
+
# @see https://developer.spotify.com/documentation/web-api/reference/player/set-repeat-mode-on-users-playback/
|
79
|
+
#
|
80
|
+
# @param [String] device_id the ID of the device to set the repeat state on.
|
81
|
+
# @param [String] state the repeat state. Defaults to the current play context.
|
82
|
+
#
|
83
|
+
# @example
|
84
|
+
# player = user.player
|
85
|
+
# player.repeat(state: 'track')
|
86
|
+
def repeat(device_id: nil, state: "context")
|
87
|
+
url = "me/player/repeat"
|
88
|
+
url += "?state=#{state}"
|
89
|
+
url += "&device_id=#{device_id}" if device_id
|
90
|
+
|
91
|
+
User.oauth_put(@user.id, url, {})
|
92
|
+
end
|
93
|
+
|
73
94
|
# Pause the user's currently active player
|
74
95
|
#
|
75
96
|
# @example
|
@@ -80,6 +101,26 @@ module RSpotify
|
|
80
101
|
User.oauth_put(@user.id, url, {})
|
81
102
|
end
|
82
103
|
|
104
|
+
# Toggle the current user's shuffle status.
|
105
|
+
# If `device_id` is not passed, the currently active spotify app will be triggered.
|
106
|
+
# If `state` is not passed, shuffle mode will be turned on.
|
107
|
+
#
|
108
|
+
# @see https://developer.spotify.com/documentation/web-api/reference/player/toggle-shuffle-for-users-playback/
|
109
|
+
#
|
110
|
+
# @param [String] device_id the ID of the device to set the shuffle state on.
|
111
|
+
# @param [String] state the shuffle state. Defaults to turning the shuffle behavior on.
|
112
|
+
#
|
113
|
+
# @example
|
114
|
+
# player = user.player
|
115
|
+
# player.shuffle(state: false)
|
116
|
+
def shuffle(device_id: nil, state: true)
|
117
|
+
url = "me/player/shuffle"
|
118
|
+
url += "?state=#{state}"
|
119
|
+
url += "&device_id=#{device_id}" if device_id
|
120
|
+
|
121
|
+
User.oauth_put(@user.id, url, {})
|
122
|
+
end
|
123
|
+
|
83
124
|
# Skip User’s Playback To Next Track
|
84
125
|
#
|
85
126
|
# @example
|
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
|
data/lib/rspotify/user.rb
CHANGED
@@ -104,6 +104,8 @@ module RSpotify
|
|
104
104
|
# Creates a playlist in user's Spotify account. This method is only available when the current
|
105
105
|
# user has granted access to the *playlist-modify-public* and *playlist-modify-private* scopes.
|
106
106
|
#
|
107
|
+
# @note To create a collaborative playlist the public option must be set to false.
|
108
|
+
#
|
107
109
|
# @param name [String] The name for the new playlist
|
108
110
|
# @param public [Boolean] Whether the playlist is public or private. Default: true
|
109
111
|
# @return [Playlist]
|
@@ -116,10 +118,14 @@ module RSpotify
|
|
116
118
|
# playlist = user.create_playlist!('my-second-playlist', public: false)
|
117
119
|
# playlist.name #=> "my-second-playlist"
|
118
120
|
# playlist.public #=> false
|
119
|
-
def create_playlist!(name, public: true)
|
121
|
+
def create_playlist!(name, description: nil, public: true, collaborative: false)
|
120
122
|
url = "users/#{@id}/playlists"
|
121
|
-
request_data = {
|
122
|
-
|
123
|
+
request_data = {
|
124
|
+
name: name,
|
125
|
+
public: public,
|
126
|
+
description: description,
|
127
|
+
collaborative: collaborative
|
128
|
+
}.to_json
|
123
129
|
response = User.oauth_post(@id, url, request_data)
|
124
130
|
return response if RSpotify.raw_response
|
125
131
|
Playlist.new response
|
@@ -139,14 +145,21 @@ module RSpotify
|
|
139
145
|
# Get the current user’s recently played tracks. Requires the *user-read-recently-played* scope.
|
140
146
|
#
|
141
147
|
# @param limit [Integer] Optional. The number of entities to return. Default: 20. Minimum: 1. Maximum: 50.
|
148
|
+
# @param after [String] Optional. A Unix timestamp in milliseconds. Returns all items after (but not including) this cursor position. If after is specified, before must not be specified.
|
149
|
+
# @param before [String] Optional. A Unix timestamp in milliseconds. Returns all items before (but not including) this cursor position. If before is specified, after must not be specified.
|
142
150
|
# @return [Array<Track>]
|
143
151
|
#
|
144
152
|
# @example
|
145
153
|
# recently_played = user.recently_played
|
146
154
|
# recently_played.size #=> 20
|
147
155
|
# recently_played.first.name #=> "Ice to Never"
|
148
|
-
|
156
|
+
# user.recently_played(limit: 50)
|
157
|
+
# user.recently_played(after: '1572561234', before: '1572562369')
|
158
|
+
def recently_played(limit: 20, after: nil, before: nil)
|
149
159
|
url = "me/player/recently-played?limit=#{limit}"
|
160
|
+
url << "&after=#{after}" if after
|
161
|
+
url << "&before=#{before}" if before
|
162
|
+
|
150
163
|
response = RSpotify.resolve_auth_request(@id, url)
|
151
164
|
return response if RSpotify.raw_response
|
152
165
|
|
@@ -300,14 +313,16 @@ module RSpotify
|
|
300
313
|
#
|
301
314
|
# @param limit [Integer] Maximum number of tracks to return. Maximum: 50. Minimum: 1. Default: 20.
|
302
315
|
# @param offset [Integer] The index of the first track to return. Use with limit to get the next set of tracks. Default: 0.
|
316
|
+
# @param market [String] Optional. An {http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2 ISO 3166-1 alpha-2 country code}.
|
303
317
|
# @return [Array<Track>]
|
304
318
|
#
|
305
319
|
# @example
|
306
320
|
# tracks = user.saved_tracks
|
307
321
|
# tracks.size #=> 20
|
308
322
|
# tracks.first.name #=> "Do I Wanna Know?"
|
309
|
-
def saved_tracks(limit: 20, offset: 0)
|
323
|
+
def saved_tracks(limit: 20, offset: 0, market: nil)
|
310
324
|
url = "me/tracks?limit=#{limit}&offset=#{offset}"
|
325
|
+
url << "&market=#{market}" if market
|
311
326
|
response = User.oauth_get(@id, url)
|
312
327
|
json = RSpotify.raw_response ? JSON.parse(response) : response
|
313
328
|
|
@@ -375,14 +390,16 @@ module RSpotify
|
|
375
390
|
#
|
376
391
|
# @param limit [Integer] Maximum number of albums to return. Maximum: 50. Minimum: 1. Default: 20.
|
377
392
|
# @param offset [Integer] The index of the first album to return. Use with limit to get the next set of albums. Default: 0.
|
393
|
+
# @param market [String] Optional. An {http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2 ISO 3166-1 alpha-2 country code}.
|
378
394
|
# @return [Array<Album>]
|
379
395
|
#
|
380
396
|
# @example
|
381
397
|
# albums = user.saved_albums
|
382
398
|
# albums.size #=> 20
|
383
399
|
# albums.first.name #=> "Launeddas"
|
384
|
-
def saved_albums(limit: 20, offset: 0)
|
400
|
+
def saved_albums(limit: 20, offset: 0, market: nil)
|
385
401
|
url = "me/albums?limit=#{limit}&offset=#{offset}"
|
402
|
+
url << "&market=#{market}" if market
|
386
403
|
response = User.oauth_get(@id, url)
|
387
404
|
json = RSpotify.raw_response ? JSON.parse(response) : response
|
388
405
|
|
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.
|
4
|
+
version: 2.9.0
|
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:
|
11
|
+
date: 2020-07-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: omniauth-oauth2
|
@@ -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: []
|
@@ -260,7 +260,7 @@ homepage: http://rubygems.org/gems/rspotify
|
|
260
260
|
licenses:
|
261
261
|
- MIT
|
262
262
|
metadata: {}
|
263
|
-
post_install_message:
|
263
|
+
post_install_message:
|
264
264
|
rdoc_options: []
|
265
265
|
require_paths:
|
266
266
|
- lib
|
@@ -275,9 +275,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
275
275
|
- !ruby/object:Gem::Version
|
276
276
|
version: '0'
|
277
277
|
requirements: []
|
278
|
-
|
279
|
-
|
280
|
-
signing_key:
|
278
|
+
rubygems_version: 3.0.6
|
279
|
+
signing_key:
|
281
280
|
specification_version: 4
|
282
281
|
summary: A ruby wrapper for the Spotify Web API
|
283
282
|
test_files:
|
@@ -368,4 +367,3 @@ test_files:
|
|
368
367
|
- spec/vcr_cassettes/user_find_spotify.yml
|
369
368
|
- spec/vcr_cassettes/user_find_wizzler.yml
|
370
369
|
- spec/vcr_cassettes/user_wizzler_playlists_limit_20_offset_0.yml
|
371
|
-
has_rdoc:
|