Class: SpotifyWebApi::PlaylistsController
- Inherits:
-
BaseController
- Object
- BaseController
- SpotifyWebApi::PlaylistsController
- Defined in:
- lib/spotify_web_api/controllers/playlists_controller.rb
Overview
PlaylistsController
Constant Summary
Constants inherited from BaseController
Instance Attribute Summary
Attributes inherited from BaseController
Instance Method Summary collapse
-
#add_tracks_to_playlist(playlist_id, position: nil, uris: nil, body: nil) ⇒ PlaylistSnapshotId
Add one or more items to a user’s playlist.
-
#change_playlist_details(playlist_id, body: nil) ⇒ void
Change a playlist’s name and public/private state.
-
#create_playlist(user_id, body: nil) ⇒ PlaylistObject
Create a playlist for a Spotify user.
-
#get_a_categories_playlists(category_id, limit: 20, offset: 0) ⇒ PagingFeaturedPlaylistObject
Get a list of Spotify playlists tagged with a particular category.
-
#get_a_list_of_current_users_playlists(limit: 20, offset: 0) ⇒ PagingPlaylistObject
Get a list of the playlists owned or followed by the current Spotify user.
-
#get_featured_playlists(locale: nil, limit: 20, offset: 0) ⇒ PagingFeaturedPlaylistObject
Get a list of Spotify featured playlists (shown, for example, on a Spotify player’s ‘Browse’ tab).
-
#get_list_users_playlists(user_id, limit: 20, offset: 0) ⇒ PagingPlaylistObject
Get a list of the playlists owned or followed by a Spotify user.
-
#get_playlist(playlist_id, market: nil, fields: nil, additional_types: nil) ⇒ PlaylistObject
Get a playlist owned by a Spotify user.
-
#get_playlist_cover(playlist_id) ⇒ Array[ImageObject]
Get the current image associated with a specific playlist.
-
#get_playlists_tracks(playlist_id, market: nil, fields: nil, limit: 20, offset: 0, additional_types: nil) ⇒ PagingPlaylistTrackObject
Get full details of the items of a playlist owned by a Spotify user.
-
#remove_tracks_playlist(playlist_id, body: nil) ⇒ PlaylistSnapshotId
Remove one or more items from a user’s playlist.
-
#reorder_or_replace_playlists_tracks(playlist_id, uris: nil, body: nil) ⇒ PlaylistSnapshotId
Either reorder or replace items in a playlist depending on the request’s parameters.
-
#upload_custom_playlist_cover(playlist_id, body) ⇒ void
Replace the image used to represent a specific playlist.
Methods inherited from BaseController
#initialize, #new_api_call_builder, #new_parameter, #new_request_builder, #new_response_handler, user_agent
Constructor Details
This class inherits a constructor from SpotifyWebApi::BaseController
Instance Method Details
#add_tracks_to_playlist(playlist_id, position: nil, uris: nil, body: nil) ⇒ PlaylistSnapshotId
Add one or more items to a user’s playlist.
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/spotify_web_api/controllers/playlists_controller.rb', line 139 def add_tracks_to_playlist(playlist_id, position: nil, uris: nil, body: nil) new_api_call_builder .request(new_request_builder(HttpMethodEnum::POST, '/playlists/{playlist_id}/tracks', Server::DEFAULT) .template_param(new_parameter(playlist_id, key: 'playlist_id') .should_encode(true)) .header_param(new_parameter('application/json', key: 'Content-Type')) .query_param(new_parameter(position, key: 'position')) .query_param(new_parameter(uris, key: 'uris')) .body_param(new_parameter(body)) .header_param(new_parameter('application/json', key: 'accept')) .body_serializer(proc do |param| param.to_json unless param.nil? end) .auth(Single.new('oauth_2_0'))) .response(new_response_handler .deserializer(APIHelper.method(:custom_type_deserializer)) .deserialize_into(PlaylistSnapshotId.method(:from_hash)) .is_api_response(true) .local_error('401', "Bad or expired token. This can happen if the user revoked a'\ ' token or\nthe access token has expired. You should'\ ' re-authenticate the user.\n", UnauthorizedException) .local_error('403', "Bad OAuth request (wrong consumer key, bad nonce, expired'\ '\ntimestamp...). Unfortunately, re-authenticating the user'\ ' won't help here.\n", ForbiddenException) .local_error('429', "The app has exceeded its rate limits.\n", TooManyRequestsException)) .execute end |
#change_playlist_details(playlist_id, body: nil) ⇒ void
This method returns an undefined value.
Change a playlist’s name and public/private state. (The user must, of course, own the playlist.)
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/spotify_web_api/controllers/playlists_controller.rb', line 55 def change_playlist_details(playlist_id, body: nil) new_api_call_builder .request(new_request_builder(HttpMethodEnum::PUT, '/playlists/{playlist_id}', Server::DEFAULT) .template_param(new_parameter(playlist_id, key: 'playlist_id') .should_encode(true)) .header_param(new_parameter('application/json', key: 'Content-Type')) .body_param(new_parameter(body)) .body_serializer(proc do |param| param.to_json unless param.nil? end) .auth(Single.new('oauth_2_0'))) .response(new_response_handler .is_response_void(true) .is_api_response(true) .local_error('401', "Bad or expired token. This can happen if the user revoked a'\ ' token or\nthe access token has expired. You should'\ ' re-authenticate the user.\n", UnauthorizedException) .local_error('403', "Bad OAuth request (wrong consumer key, bad nonce, expired'\ '\ntimestamp...). Unfortunately, re-authenticating the user'\ ' won't help here.\n", ForbiddenException) .local_error('429', "The app has exceeded its rate limits.\n", TooManyRequestsException)) .execute end |
#create_playlist(user_id, body: nil) ⇒ PlaylistObject
Create a playlist for a Spotify user. (The playlist will be empty until you [add tracks](/documentation/web-api/reference/add-tracks-to-playlist).) Each user is generally limited to a maximum of 11000 playlists.
344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 |
# File 'lib/spotify_web_api/controllers/playlists_controller.rb', line 344 def create_playlist(user_id, body: nil) new_api_call_builder .request(new_request_builder(HttpMethodEnum::POST, '/users/{user_id}/playlists', Server::DEFAULT) .template_param(new_parameter(user_id, key: 'user_id') .should_encode(true)) .header_param(new_parameter('application/json', key: 'Content-Type')) .body_param(new_parameter(body)) .header_param(new_parameter('application/json', key: 'accept')) .body_serializer(proc do |param| param.to_json unless param.nil? end) .auth(Single.new('oauth_2_0'))) .response(new_response_handler .deserializer(APIHelper.method(:custom_type_deserializer)) .deserialize_into(PlaylistObject.method(:from_hash)) .is_api_response(true) .local_error('401', "Bad or expired token. This can happen if the user revoked a'\ ' token or\nthe access token has expired. You should'\ ' re-authenticate the user.\n", UnauthorizedException) .local_error('403', "Bad OAuth request (wrong consumer key, bad nonce, expired'\ '\ntimestamp...). Unfortunately, re-authenticating the user'\ ' won't help here.\n", ForbiddenException) .local_error('429', "The app has exceeded its rate limits.\n", TooManyRequestsException)) .execute end |
#get_a_categories_playlists(category_id, limit: 20, offset: 0) ⇒ PagingFeaturedPlaylistObject
Get a list of Spotify playlists tagged with a particular category.
420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 |
# File 'lib/spotify_web_api/controllers/playlists_controller.rb', line 420 def get_a_categories_playlists(category_id, limit: 20, offset: 0) new_api_call_builder .request(new_request_builder(HttpMethodEnum::GET, '/browse/categories/{category_id}/playlists', Server::DEFAULT) .template_param(new_parameter(category_id, key: 'category_id') .should_encode(true)) .query_param(new_parameter(limit, key: 'limit')) .query_param(new_parameter(offset, key: 'offset')) .header_param(new_parameter('application/json', key: 'accept')) .auth(Single.new('oauth_2_0'))) .response(new_response_handler .deserializer(APIHelper.method(:custom_type_deserializer)) .deserialize_into(PagingFeaturedPlaylistObject.method(:from_hash)) .is_api_response(true) .local_error('401', "Bad or expired token. This can happen if the user revoked a'\ ' token or\nthe access token has expired. You should'\ ' re-authenticate the user.\n", UnauthorizedException) .local_error('403', "Bad OAuth request (wrong consumer key, bad nonce, expired'\ '\ntimestamp...). Unfortunately, re-authenticating the user'\ ' won't help here.\n", ForbiddenException) .local_error('429', "The app has exceeded its rate limits.\n", TooManyRequestsException)) .execute end |
#get_a_list_of_current_users_playlists(limit: 20, offset: 0) ⇒ PagingPlaylistObject
Get a list of the playlists owned or followed by the current Spotify user.
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 |
# File 'lib/spotify_web_api/controllers/playlists_controller.rb', line 269 def get_a_list_of_current_users_playlists(limit: 20, offset: 0) new_api_call_builder .request(new_request_builder(HttpMethodEnum::GET, '/me/playlists', Server::DEFAULT) .query_param(new_parameter(limit, key: 'limit')) .query_param(new_parameter(offset, key: 'offset')) .header_param(new_parameter('application/json', key: 'accept')) .auth(Single.new('oauth_2_0'))) .response(new_response_handler .deserializer(APIHelper.method(:custom_type_deserializer)) .deserialize_into(PagingPlaylistObject.method(:from_hash)) .is_api_response(true) .local_error('401', "Bad or expired token. This can happen if the user revoked a'\ ' token or\nthe access token has expired. You should'\ ' re-authenticate the user.\n", UnauthorizedException) .local_error('403', "Bad OAuth request (wrong consumer key, bad nonce, expired'\ '\ntimestamp...). Unfortunately, re-authenticating the user'\ ' won't help here.\n", ForbiddenException) .local_error('429', "The app has exceeded its rate limits.\n", TooManyRequestsException)) .execute end |
#get_featured_playlists(locale: nil, limit: 20, offset: 0) ⇒ PagingFeaturedPlaylistObject
Get a list of Spotify featured playlists (shown, for example, on a Spotify player’s ‘Browse’ tab).
383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 |
# File 'lib/spotify_web_api/controllers/playlists_controller.rb', line 383 def get_featured_playlists(locale: nil, limit: 20, offset: 0) new_api_call_builder .request(new_request_builder(HttpMethodEnum::GET, '/browse/featured-playlists', Server::DEFAULT) .query_param(new_parameter(locale, key: 'locale')) .query_param(new_parameter(limit, key: 'limit')) .query_param(new_parameter(offset, key: 'offset')) .header_param(new_parameter('application/json', key: 'accept')) .auth(Single.new('oauth_2_0'))) .response(new_response_handler .deserializer(APIHelper.method(:custom_type_deserializer)) .deserialize_into(PagingFeaturedPlaylistObject.method(:from_hash)) .is_api_response(true) .local_error('401', "Bad or expired token. This can happen if the user revoked a'\ ' token or\nthe access token has expired. You should'\ ' re-authenticate the user.\n", UnauthorizedException) .local_error('403', "Bad OAuth request (wrong consumer key, bad nonce, expired'\ '\ntimestamp...). Unfortunately, re-authenticating the user'\ ' won't help here.\n", ForbiddenException) .local_error('429', "The app has exceeded its rate limits.\n", TooManyRequestsException)) .execute end |
#get_list_users_playlists(user_id, limit: 20, offset: 0) ⇒ PagingPlaylistObject
Get a list of the playlists owned or followed by a Spotify user.
304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 |
# File 'lib/spotify_web_api/controllers/playlists_controller.rb', line 304 def get_list_users_playlists(user_id, limit: 20, offset: 0) new_api_call_builder .request(new_request_builder(HttpMethodEnum::GET, '/users/{user_id}/playlists', Server::DEFAULT) .template_param(new_parameter(user_id, key: 'user_id') .should_encode(true)) .query_param(new_parameter(limit, key: 'limit')) .query_param(new_parameter(offset, key: 'offset')) .header_param(new_parameter('application/json', key: 'accept')) .auth(Single.new('oauth_2_0'))) .response(new_response_handler .deserializer(APIHelper.method(:custom_type_deserializer)) .deserialize_into(PagingPlaylistObject.method(:from_hash)) .is_api_response(true) .local_error('401', "Bad or expired token. This can happen if the user revoked a'\ ' token or\nthe access token has expired. You should'\ ' re-authenticate the user.\n", UnauthorizedException) .local_error('403', "Bad OAuth request (wrong consumer key, bad nonce, expired'\ '\ntimestamp...). Unfortunately, re-authenticating the user'\ ' won't help here.\n", ForbiddenException) .local_error('429', "The app has exceeded its rate limits.\n", TooManyRequestsException)) .execute end |
#get_playlist(playlist_id, market: nil, fields: nil, additional_types: nil) ⇒ PlaylistObject
Get a playlist owned by a Spotify user.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/spotify_web_api/controllers/playlists_controller.rb', line 15 def get_playlist(playlist_id, market: nil, fields: nil, additional_types: nil) new_api_call_builder .request(new_request_builder(HttpMethodEnum::GET, '/playlists/{playlist_id}', Server::DEFAULT) .template_param(new_parameter(playlist_id, key: 'playlist_id') .should_encode(true)) .query_param(new_parameter(market, key: 'market')) .query_param(new_parameter(fields, key: 'fields')) .query_param(new_parameter(additional_types, key: 'additional_types')) .header_param(new_parameter('application/json', key: 'accept')) .auth(Single.new('oauth_2_0'))) .response(new_response_handler .deserializer(APIHelper.method(:custom_type_deserializer)) .deserialize_into(PlaylistObject.method(:from_hash)) .is_api_response(true) .local_error('401', "Bad or expired token. This can happen if the user revoked a'\ ' token or\nthe access token has expired. You should'\ ' re-authenticate the user.\n", UnauthorizedException) .local_error('403', "Bad OAuth request (wrong consumer key, bad nonce, expired'\ '\ntimestamp...). Unfortunately, re-authenticating the user'\ ' won't help here.\n", ForbiddenException) .local_error('429', "The app has exceeded its rate limits.\n", TooManyRequestsException)) .execute end |
#get_playlist_cover(playlist_id) ⇒ Array[ImageObject]
Get the current image associated with a specific playlist.
456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 |
# File 'lib/spotify_web_api/controllers/playlists_controller.rb', line 456 def get_playlist_cover(playlist_id) new_api_call_builder .request(new_request_builder(HttpMethodEnum::GET, '/playlists/{playlist_id}/images', Server::DEFAULT) .template_param(new_parameter(playlist_id, key: 'playlist_id') .should_encode(true)) .header_param(new_parameter('application/json', key: 'accept')) .auth(Single.new('oauth_2_0'))) .response(new_response_handler .deserializer(APIHelper.method(:custom_type_deserializer)) .deserialize_into(ImageObject.method(:from_hash)) .is_api_response(true) .is_response_array(true) .local_error('401', "Bad or expired token. This can happen if the user revoked a'\ ' token or\nthe access token has expired. You should'\ ' re-authenticate the user.\n", UnauthorizedException) .local_error('403', "Bad OAuth request (wrong consumer key, bad nonce, expired'\ '\ntimestamp...). Unfortunately, re-authenticating the user'\ ' won't help here.\n", ForbiddenException) .local_error('429', "The app has exceeded its rate limits.\n", TooManyRequestsException)) .execute end |
#get_playlists_tracks(playlist_id, market: nil, fields: nil, limit: 20, offset: 0, additional_types: nil) ⇒ PagingPlaylistTrackObject
Get full details of the items of a playlist owned by a Spotify user.
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/spotify_web_api/controllers/playlists_controller.rb', line 94 def get_playlists_tracks(playlist_id, market: nil, fields: nil, limit: 20, offset: 0, additional_types: nil) new_api_call_builder .request(new_request_builder(HttpMethodEnum::GET, '/playlists/{playlist_id}/tracks', Server::DEFAULT) .template_param(new_parameter(playlist_id, key: 'playlist_id') .should_encode(true)) .query_param(new_parameter(market, key: 'market')) .query_param(new_parameter(fields, key: 'fields')) .query_param(new_parameter(limit, key: 'limit')) .query_param(new_parameter(offset, key: 'offset')) .query_param(new_parameter(additional_types, key: 'additional_types')) .header_param(new_parameter('application/json', key: 'accept')) .auth(Single.new('oauth_2_0'))) .response(new_response_handler .deserializer(APIHelper.method(:custom_type_deserializer)) .deserialize_into(PagingPlaylistTrackObject.method(:from_hash)) .is_api_response(true) .local_error('401', "Bad or expired token. This can happen if the user revoked a'\ ' token or\nthe access token has expired. You should'\ ' re-authenticate the user.\n", UnauthorizedException) .local_error('403', "Bad OAuth request (wrong consumer key, bad nonce, expired'\ '\ntimestamp...). Unfortunately, re-authenticating the user'\ ' won't help here.\n", ForbiddenException) .local_error('429', "The app has exceeded its rate limits.\n", TooManyRequestsException)) .execute end |
#remove_tracks_playlist(playlist_id, body: nil) ⇒ PlaylistSnapshotId
Remove one or more items from a user’s playlist.
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 |
# File 'lib/spotify_web_api/controllers/playlists_controller.rb', line 231 def remove_tracks_playlist(playlist_id, body: nil) new_api_call_builder .request(new_request_builder(HttpMethodEnum::DELETE, '/playlists/{playlist_id}/tracks', Server::DEFAULT) .template_param(new_parameter(playlist_id, key: 'playlist_id') .should_encode(true)) .header_param(new_parameter('application/json', key: 'Content-Type')) .body_param(new_parameter(body)) .header_param(new_parameter('application/json', key: 'accept')) .body_serializer(proc do |param| param.to_json unless param.nil? end) .auth(Single.new('oauth_2_0'))) .response(new_response_handler .deserializer(APIHelper.method(:custom_type_deserializer)) .deserialize_into(PlaylistSnapshotId.method(:from_hash)) .is_api_response(true) .local_error('401', "Bad or expired token. This can happen if the user revoked a'\ ' token or\nthe access token has expired. You should'\ ' re-authenticate the user.\n", UnauthorizedException) .local_error('403', "Bad OAuth request (wrong consumer key, bad nonce, expired'\ '\ntimestamp...). Unfortunately, re-authenticating the user'\ ' won't help here.\n", ForbiddenException) .local_error('429', "The app has exceeded its rate limits.\n", TooManyRequestsException)) .execute end |
#reorder_or_replace_playlists_tracks(playlist_id, uris: nil, body: nil) ⇒ PlaylistSnapshotId
Either reorder or replace items in a playlist depending on the request’s parameters. To reorder items, include ‘range_start`, `insert_before`, `range_length` and `snapshot_id` in the request’s body. To replace items, include ‘uris` as either a query parameter or in the request’s body. Replacing items in a playlist will overwrite its existing items. This operation can be used for replacing or clearing items in a playlist. <br/> Note: Replace and reorder are mutually exclusive operations which share the same endpoint, but have different parameters. These operations can’t be applied together in a single request.
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 |
# File 'lib/spotify_web_api/controllers/playlists_controller.rb', line 192 def reorder_or_replace_playlists_tracks(playlist_id, uris: nil, body: nil) new_api_call_builder .request(new_request_builder(HttpMethodEnum::PUT, '/playlists/{playlist_id}/tracks', Server::DEFAULT) .template_param(new_parameter(playlist_id, key: 'playlist_id') .should_encode(true)) .header_param(new_parameter('application/json', key: 'Content-Type')) .query_param(new_parameter(uris, key: 'uris')) .body_param(new_parameter(body)) .header_param(new_parameter('application/json', key: 'accept')) .body_serializer(proc do |param| param.to_json unless param.nil? end) .auth(Single.new('oauth_2_0'))) .response(new_response_handler .deserializer(APIHelper.method(:custom_type_deserializer)) .deserialize_into(PlaylistSnapshotId.method(:from_hash)) .is_api_response(true) .local_error('401', "Bad or expired token. This can happen if the user revoked a'\ ' token or\nthe access token has expired. You should'\ ' re-authenticate the user.\n", UnauthorizedException) .local_error('403', "Bad OAuth request (wrong consumer key, bad nonce, expired'\ '\ntimestamp...). Unfortunately, re-authenticating the user'\ ' won't help here.\n", ForbiddenException) .local_error('429', "The app has exceeded its rate limits.\n", TooManyRequestsException)) .execute end |
#upload_custom_playlist_cover(playlist_id, body) ⇒ void
This method returns an undefined value.
Replace the image used to represent a specific playlist.
490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 |
# File 'lib/spotify_web_api/controllers/playlists_controller.rb', line 490 def upload_custom_playlist_cover(playlist_id, body) new_api_call_builder .request(new_request_builder(HttpMethodEnum::PUT, '/playlists/{playlist_id}/images', Server::DEFAULT) .template_param(new_parameter(playlist_id, key: 'playlist_id') .should_encode(true)) .body_param(new_parameter(body)) .header_param(new_parameter('application/json; charset=utf-8', key: 'content-type')) .body_serializer(APIHelper.method(:json_serialize)) .auth(Single.new('oauth_2_0'))) .response(new_response_handler .is_response_void(true) .is_api_response(true) .local_error('401', "Bad or expired token. This can happen if the user revoked a'\ ' token or\nthe access token has expired. You should'\ ' re-authenticate the user.\n", UnauthorizedException) .local_error('403', "Bad OAuth request (wrong consumer key, bad nonce, expired'\ '\ntimestamp...). Unfortunately, re-authenticating the user'\ ' won't help here.\n", ForbiddenException) .local_error('429', "The app has exceeded its rate limits.\n", TooManyRequestsException)) .execute end |