rspotify 1.10.1 → 1.11.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 746c93e4929aee391922cfc5443d922647189a5d
4
- data.tar.gz: 5cc0425b5c7e21262f18bf6a138aa9aa395a5541
3
+ metadata.gz: 5bb4cfacaa5e965c3790ff69e4fa1772779535c2
4
+ data.tar.gz: 937b66b4e61e143ea789c566618b01236d6f4739
5
5
  SHA512:
6
- metadata.gz: 6415dc6b2d4eaaa51afc3614a3251836202fb21e803c8cc570f69aa2dd1d796524a4849463c6de6a630bca78a828cd9ccf59ec173b937f5a1a7fcccfdaff75af
7
- data.tar.gz: 43fa01bce310d84ca9788bc5b5b1ece98198093429b5ff794ad17df882579cf016f609aafb5b74ce70648f783843f1da9525d29f2c33b065f95fea2e620417fb
6
+ metadata.gz: 41e73ebfca07ffc53660f3c8e27d1172941bc092df5059206351823ad01571d9390068ca270c181dc3750c87d3fbf79ab038383731f324f12dcd9224be828551
7
+ data.tar.gz: 8cf584d541243c000a268c4fdc21ea87beb24fae06617298d6f69a49b22b632656939c81eb0d7542e529e7a43554b4219e2facee8e119c4fd3fb1d05fe50906e
data/README.md CHANGED
@@ -181,8 +181,9 @@ class UsersController < ApplicationController
181
181
  spotify_user.saved_tracks.size #=> 20
182
182
  spotify_user.remove_tracks!(tracks)
183
183
 
184
- # Follow artists and other Spotify users
185
- spotify_user.follow(artists)
184
+ # Use Spotify Follow features
185
+ spotify_user.follow(playlist)
186
+ spotify_user.follows?(artists)
186
187
  spotify_user.unfollow(users)
187
188
 
188
189
  # Check doc for more
data/lib/rspotify/user.rb CHANGED
@@ -106,38 +106,61 @@ module RSpotify
106
106
  Playlist.new User.oauth_post(@id, url, request_data)
107
107
  end
108
108
 
109
- # Add the current user as a follower of one or more artists or other Spotify users. This method
110
- # is only available when the current user has granted access to the *user-follow-modify* scope.
109
+ # Add the current user as a follower of one or more artists, other Spotify users or a playlist. Following artists or users require the *user-follow-modify*
110
+ # scope. Following a playlist publicly requires the *playlist-modify-public* scope; following it privately requires the *playlist-modify-private* scope.
111
+ #
112
+ # @note Scopes you provide for playlists determine only whether the current user can themselves follow the playlist publicly or privately (i.e. show others what they are following), not whether the playlist itself is public or private.
111
113
  #
112
- # @param followed [Array<User>, Array<Artist>] The users or artists to follow
113
- # @return [Array<User>, Array<Artist>]
114
+ # @param followed [Artist, Array<Artist>, User, Array<User>, Playlist] The artists, users or playlist to follow
115
+ # @param public [Boolean] If true the playlist will be included in user's public playlists, if false it will remain private.
116
+ # @return [Artist, Array<Artist>, User, Array<User>, Playlist]
114
117
  #
115
118
  # @example
116
119
  # artists = RSpotify::Artist.search('John')
117
120
  # user.follow(artists)
118
- def follow(followed)
119
- type = followed.first.type
120
- ids = followed.map(&:id).join(',')
121
- url = "me/following?type=#{type}&ids=#{ids}"
121
+ #
122
+ # playlist = RSpotify::Playlist.search('Movie').first
123
+ # user.follow(playlist, public: false)
124
+ def follow(followed, public: true)
125
+ if followed.is_a? Array
126
+ ids = followed.map(&:id).join(',')
127
+ type = followed.first.type
128
+ else
129
+ ids = followed.id
130
+ type = followed.type
131
+ end
132
+
133
+ if type == 'playlist'
134
+ request_body = { public: public }
135
+ url = "users/#{followed.owner.id}/playlists/#{followed.id}/followers"
136
+ else
137
+ request_body = {}
138
+ url = "me/following?type=#{type}&ids=#{ids}"
139
+ end
122
140
 
123
- User.oauth_put(@id, url, {})
141
+ User.oauth_put(@id, url, request_body.to_json)
124
142
  followed
125
143
  end
126
144
 
127
145
  # Check to see if the current user is following one or more artists or other Spotify users. This method
128
146
  # is only available when the current user has granted access to the *user-follow-read* scope.
129
147
  #
130
- # @param followed [Array<User>, Array<Artist>] The users or artists to check
148
+ # @param followed [Artist, Array<Artist>, User, Array<User>] The users or artists to check
131
149
  # @return [Array<Boolean>]
132
150
  #
133
151
  # @example
134
152
  # artists = RSpotify::Artist.search('John')
135
153
  # user.follows?(artists) #=> [true, false, true...]
136
154
  def follows?(followed)
137
- type = followed.first.type
138
- ids = followed.map(&:id).join(',')
139
- url = "me/following/contains?type=#{type}&ids=#{ids}"
155
+ if followed.is_a? Array
156
+ ids = followed.map(&:id).join(',')
157
+ type = followed.first.type
158
+ else
159
+ ids = followed.id
160
+ type = followed.type
161
+ end
140
162
 
163
+ url = "me/following/contains?type=#{type}&ids=#{ids}"
141
164
  User.oauth_get(@id, url)
142
165
  end
143
166
 
@@ -239,19 +262,34 @@ module RSpotify
239
262
  Hash[pairs]
240
263
  end
241
264
 
242
- # Remove the current user as a follower of one or more artists or other Spotify users. This method
243
- # is only available when the current user has granted access to the *user-follow-modify* scope.
265
+ # Remove the current user as a follower of one or more artists, other Spotify users or a playlist. Unfollowing artists or users require the *user-follow-modify* scope.
266
+ # Unfollowing a publicly followed playlist requires the *playlist-modify-public* scope; unfollowing a privately followed playlist requires the *playlist-modify-private* scope.
267
+ #
268
+ # @note Note that the scopes you provide for playlists relate only to whether the current user is following the playlist publicly or privately (i.e. showing others what they are following), not whether the playlist itself is public or private.
244
269
  #
245
- # @param followed [Array<User>, Array<Artist>] The users or artists to unfollow
246
- # @return [Array<User>, Array<Artist>]
270
+ # @param unfollowed [Artist, Array<Artist>, User, Array<User>, Playlist] The artists, users or playlist to unfollow
271
+ # @return [Artist, Array<Artist>, User, Array<User>, Playlist]
247
272
  #
248
273
  # @example
249
274
  # artists = RSpotify::Artist.search('John')
250
275
  # user.unfollow(artists)
276
+ #
277
+ # playlist = RSpotify::Playlist.search('Movie').first
278
+ # user.unfollow(playlist)
251
279
  def unfollow(unfollowed)
252
- type = unfollowed.first.type
253
- ids = unfollowed.map(&:id).join(',')
254
- url = "me/following?type=#{type}&ids=#{ids}"
280
+ if unfollowed.is_a? Array
281
+ ids = unfollowed.map(&:id).join(',')
282
+ type = unfollowed.first.type
283
+ else
284
+ ids = unfollowed.id
285
+ type = unfollowed.type
286
+ end
287
+
288
+ url = if type == 'playlist'
289
+ "users/#{unfollowed.owner.id}/playlists/#{unfollowed.id}/followers"
290
+ else
291
+ "me/following?type=#{type}&ids=#{ids}"
292
+ end
255
293
 
256
294
  User.oauth_delete(@id, url)
257
295
  unfollowed
@@ -1,3 +1,3 @@
1
1
  module RSpotify
2
- VERSION = '1.10.1'
2
+ VERSION = '1.11.0'
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: 1.10.1
4
+ version: 1.11.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-01-15 00:00:00.000000000 Z
11
+ date: 2015-01-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: omniauth-oauth2