rspotify 1.15.5 → 1.16.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 +4 -4
- data/README.md +5 -0
- data/lib/rspotify/user.rb +72 -0
- 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: 8a88de811476fbb0042abe48a1a7ff99ed6d3e30
|
4
|
+
data.tar.gz: e1f261ed242e3a7abc2cf0f5b1aae6c05495f04e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 58a7634fff6edcbe1d5b9f73c9c5723f49d3c446b16bff93a4e93dbe3e98bf8dd422e77ef671cbe797ae54913a05d15142e994d09d7eef71d88e79509006dd4f
|
7
|
+
data.tar.gz: 24200d848d08744d17002d3215ca67d2efa6c54cefd708bdad33ac3ffef98476ac769315555c239249a02436d402fad8d2c871aa10d8cd7b0959812ac732851c
|
data/README.md
CHANGED
@@ -186,6 +186,11 @@ class UsersController < ApplicationController
|
|
186
186
|
spotify_user.saved_tracks.size #=> 20
|
187
187
|
spotify_user.remove_tracks!(tracks)
|
188
188
|
|
189
|
+
albums = RSpotify::Album.search('launeddas')
|
190
|
+
spotify_user.save_albums!(albums)
|
191
|
+
spotify_user.saved_albums.size #=> 10
|
192
|
+
spotify_user.remove_albums!(albums)
|
193
|
+
|
189
194
|
# Use Spotify Follow features
|
190
195
|
spotify_user.follow(playlist)
|
191
196
|
spotify_user.follows?(artists)
|
data/lib/rspotify/user.rb
CHANGED
@@ -286,6 +286,78 @@ module RSpotify
|
|
286
286
|
User.oauth_get(@id, url)
|
287
287
|
end
|
288
288
|
|
289
|
+
# Remove albums from the user’s “Your Music” library.
|
290
|
+
#
|
291
|
+
# @param albums [Array<Album>] The albums to remove. Maximum: 50.
|
292
|
+
# @return [Array<Album>] The albums removed.
|
293
|
+
#
|
294
|
+
# @example
|
295
|
+
# albums = user.saved_albums
|
296
|
+
#
|
297
|
+
# user.saved_albums.size #=> 20
|
298
|
+
# user.remove_albums!(albums)
|
299
|
+
# user.saved_albums.size #=> 0
|
300
|
+
def remove_albums!(albums)
|
301
|
+
albums_ids = albums.map(&:id)
|
302
|
+
url = "me/albums?ids=#{albums_ids.join ','}"
|
303
|
+
User.oauth_delete(@id, url)
|
304
|
+
albums
|
305
|
+
end
|
306
|
+
|
307
|
+
# Save albums to the user’s “Your Music” library.
|
308
|
+
#
|
309
|
+
# @param albums [Array<Album>] The albums to save. Maximum: 50.
|
310
|
+
# @return [Array<Album>] The albums saved.
|
311
|
+
#
|
312
|
+
# @example
|
313
|
+
# albums = RSpotify::Album.search('launeddas')
|
314
|
+
#
|
315
|
+
# user.saved_albums.size #=> 0
|
316
|
+
# user.save_albums!(albums)
|
317
|
+
# user.saved_albums.size #=> 10
|
318
|
+
def save_albums!(albums)
|
319
|
+
albums_ids = albums.map(&:id)
|
320
|
+
url = "me/albums"
|
321
|
+
request_body = albums_ids.inspect
|
322
|
+
User.oauth_put(@id, url, request_body)
|
323
|
+
albums
|
324
|
+
end
|
325
|
+
|
326
|
+
# Returns the albums saved in the Spotify user’s “Your Music” library. ** Includes albums whose tracks you saved
|
327
|
+
#
|
328
|
+
# @param limit [Integer] Maximum number of albums to return. Maximum: 50. Minimum: 1. Default: 20.
|
329
|
+
# @param offset [Integer] The index of the first album to return. Use with limit to get the next set of albums. Default: 0.
|
330
|
+
# @return [Array<Album>]
|
331
|
+
#
|
332
|
+
# @example
|
333
|
+
# albums = user.saved_albums
|
334
|
+
# albums.size #=> 20
|
335
|
+
# albums.first.name #=> "Launeddas"
|
336
|
+
def saved_albums(limit: 20, offset: 0)
|
337
|
+
url = "me/albums?limit=#{limit}&offset=#{offset}"
|
338
|
+
response = User.oauth_get(@id, url)
|
339
|
+
json = RSpotify.raw_response ? JSON.parse(response) : response
|
340
|
+
|
341
|
+
albums = json['items'].select { |i| i['album'] }
|
342
|
+
|
343
|
+
return response if RSpotify.raw_response
|
344
|
+
albums.map { |a| Album.new a['album'] }
|
345
|
+
end
|
346
|
+
|
347
|
+
# Check if albums are already saved in the Spotify user’s “Your Music” library. ** Only returns true if the album was saved via me/albums, not if you saved each track individually.
|
348
|
+
#
|
349
|
+
# @param albums [Array<Album>] The albums to check. Maximum: 50.
|
350
|
+
# @return [Array<Boolean>] Array of booleans, in the same order in which the albums were specified.
|
351
|
+
#
|
352
|
+
# @example
|
353
|
+
# albums = RSpotify::Album.search('launeddas')
|
354
|
+
# user.saved_albums?(albums) #=> [true, false, true...]
|
355
|
+
def saved_albums?(albums)
|
356
|
+
albums_ids = albums.map(&:id)
|
357
|
+
url = "me/albums/contains?ids=#{albums_ids.join ','}"
|
358
|
+
User.oauth_get(@id, url)
|
359
|
+
end
|
360
|
+
|
289
361
|
# Returns a hash containing all user attributes
|
290
362
|
def to_hash
|
291
363
|
pairs = instance_variables.map do |var|
|
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: 1.
|
4
|
+
version: 1.16.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Guilherme Sad
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-11-
|
11
|
+
date: 2015-11-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: omniauth-oauth2
|