Class: SpotifyWebApi::TracksController
- Inherits:
-
BaseController
- Object
- BaseController
- SpotifyWebApi::TracksController
- Defined in:
- lib/spotify_web_api/controllers/tracks_controller.rb
Overview
TracksController
Constant Summary
Constants inherited from BaseController
Instance Attribute Summary
Attributes inherited from BaseController
Instance Method Summary collapse
-
#check_users_saved_tracks(ids) ⇒ Array[TrueClass | FalseClass]
Check if one or more tracks is already saved in the current Spotify user’s ‘Your Music’ library.
-
#get_audio_analysis(id) ⇒ AudioAnalysisObject
Get a low-level audio analysis for a track in the Spotify catalog.
-
#get_audio_features(id) ⇒ AudioFeaturesObject
Get audio feature information for a single track identified by its unique Spotify ID.
-
#get_recommendations(limit: 20, market: nil, seed_artists: nil, seed_genres: nil, seed_tracks: nil, min_acousticness: nil, max_acousticness: nil, target_acousticness: nil, min_danceability: nil, max_danceability: nil, target_danceability: nil, min_duration_ms: nil, max_duration_ms: nil, target_duration_ms: nil, min_energy: nil, max_energy: nil, target_energy: nil, min_instrumentalness: nil, max_instrumentalness: nil, target_instrumentalness: nil, min_key: nil, max_key: nil, target_key: nil, min_liveness: nil, max_liveness: nil, target_liveness: nil, min_loudness: nil, max_loudness: nil, target_loudness: nil, min_mode: nil, max_mode: nil, target_mode: nil, min_popularity: nil, max_popularity: nil, target_popularity: nil, min_speechiness: nil, max_speechiness: nil, target_speechiness: nil, min_tempo: nil, max_tempo: nil, target_tempo: nil, min_time_signature: nil, max_time_signature: nil, target_time_signature: nil, min_valence: nil, max_valence: nil, target_valence: nil) ⇒ RecommendationsObject
Recommendations are generated based on the available information for a given seed entity and matched against similar artists and tracks.
-
#get_several_audio_features(ids) ⇒ ManyAudioFeatures
Get audio features for multiple tracks based on their Spotify IDs.
-
#get_several_tracks(ids, market: nil) ⇒ ManyTracks
Get Spotify catalog information for multiple tracks based on their Spotify IDs.
-
#get_track(id, market: nil) ⇒ TrackObject
Get Spotify catalog information for a single track identified by its unique Spotify ID.
-
#get_users_saved_tracks(market: nil, limit: 20, offset: 0) ⇒ PagingSavedTrackObject
Get a list of the songs saved in the current Spotify user’s ‘Your Music’ library.
-
#remove_tracks_user(ids, body: nil) ⇒ void
Remove one or more tracks from the current user’s ‘Your Music’ library.
-
#save_tracks_user(ids, body: nil) ⇒ void
Save one or more tracks to the current user’s ‘Your Music’ library.
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
#check_users_saved_tracks(ids) ⇒ Array[TrueClass | FalseClass]
Check if one or more tracks is already saved in the current Spotify user’s ‘Your Music’ library.
190 191 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 |
# File 'lib/spotify_web_api/controllers/tracks_controller.rb', line 190 def check_users_saved_tracks(ids) new_api_call_builder .request(new_request_builder(HttpMethodEnum::GET, '/me/tracks/contains', Server::DEFAULT) .query_param(new_parameter(ids, key: 'ids')) .header_param(new_parameter('application/json', key: 'accept')) .auth(Single.new('oauth_2_0'))) .response(new_response_handler .deserializer(APIHelper.method(:deserialize_primitive_types)) .is_api_response(true) .is_response_array(true) .is_primitive_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_audio_analysis(id) ⇒ AudioAnalysisObject
Get a low-level audio analysis for a track in the Spotify catalog. The audio analysis describes the track’s structure and musical content, including rhythm, pitch, and timbre.
288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 |
# File 'lib/spotify_web_api/controllers/tracks_controller.rb', line 288 def get_audio_analysis(id) new_api_call_builder .request(new_request_builder(HttpMethodEnum::GET, '/audio-analysis/{id}', Server::DEFAULT) .template_param(new_parameter(id, key: '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(AudioAnalysisObject.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_audio_features(id) ⇒ AudioFeaturesObject
Get audio feature information for a single track identified by its unique Spotify ID.
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 |
# File 'lib/spotify_web_api/controllers/tracks_controller.rb', line 254 def get_audio_features(id) new_api_call_builder .request(new_request_builder(HttpMethodEnum::GET, '/audio-features/{id}', Server::DEFAULT) .template_param(new_parameter(id, key: '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(AudioFeaturesObject.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_recommendations(limit: 20, market: nil, seed_artists: nil, seed_genres: nil, seed_tracks: nil, min_acousticness: nil, max_acousticness: nil, target_acousticness: nil, min_danceability: nil, max_danceability: nil, target_danceability: nil, min_duration_ms: nil, max_duration_ms: nil, target_duration_ms: nil, min_energy: nil, max_energy: nil, target_energy: nil, min_instrumentalness: nil, max_instrumentalness: nil, target_instrumentalness: nil, min_key: nil, max_key: nil, target_key: nil, min_liveness: nil, max_liveness: nil, target_liveness: nil, min_loudness: nil, max_loudness: nil, target_loudness: nil, min_mode: nil, max_mode: nil, target_mode: nil, min_popularity: nil, max_popularity: nil, target_popularity: nil, min_speechiness: nil, max_speechiness: nil, target_speechiness: nil, min_tempo: nil, max_tempo: nil, target_tempo: nil, min_time_signature: nil, max_time_signature: nil, target_time_signature: nil, min_valence: nil, max_valence: nil, target_valence: nil) ⇒ RecommendationsObject
Recommendations are generated based on the available information for a given seed entity and matched against similar artists and tracks. If there is sufficient information about the provided seeds, a list of tracks will be returned together with pool size details. For artists and tracks that are very new or obscure there might not be enough data to generate a list of tracks.
371 372 373 374 375 376 377 378 379 380 381 382 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 414 415 416 417 418 419 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 452 453 454 455 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 485 486 487 488 489 |
# File 'lib/spotify_web_api/controllers/tracks_controller.rb', line 371 def get_recommendations(limit: 20, market: nil, seed_artists: nil, seed_genres: nil, seed_tracks: nil, min_acousticness: nil, max_acousticness: nil, target_acousticness: nil, min_danceability: nil, max_danceability: nil, target_danceability: nil, min_duration_ms: nil, max_duration_ms: nil, target_duration_ms: nil, min_energy: nil, max_energy: nil, target_energy: nil, min_instrumentalness: nil, max_instrumentalness: nil, target_instrumentalness: nil, min_key: nil, max_key: nil, target_key: nil, min_liveness: nil, max_liveness: nil, target_liveness: nil, min_loudness: nil, max_loudness: nil, target_loudness: nil, min_mode: nil, max_mode: nil, target_mode: nil, min_popularity: nil, max_popularity: nil, target_popularity: nil, min_speechiness: nil, max_speechiness: nil, target_speechiness: nil, min_tempo: nil, max_tempo: nil, target_tempo: nil, min_time_signature: nil, max_time_signature: nil, target_time_signature: nil, min_valence: nil, max_valence: nil, target_valence: nil) new_api_call_builder .request(new_request_builder(HttpMethodEnum::GET, '/recommendations', Server::DEFAULT) .query_param(new_parameter(limit, key: 'limit')) .query_param(new_parameter(market, key: 'market')) .query_param(new_parameter(seed_artists, key: 'seed_artists')) .query_param(new_parameter(seed_genres, key: 'seed_genres')) .query_param(new_parameter(seed_tracks, key: 'seed_tracks')) .query_param(new_parameter(min_acousticness, key: 'min_acousticness')) .query_param(new_parameter(max_acousticness, key: 'max_acousticness')) .query_param(new_parameter(target_acousticness, key: 'target_acousticness')) .query_param(new_parameter(min_danceability, key: 'min_danceability')) .query_param(new_parameter(max_danceability, key: 'max_danceability')) .query_param(new_parameter(target_danceability, key: 'target_danceability')) .query_param(new_parameter(min_duration_ms, key: 'min_duration_ms')) .query_param(new_parameter(max_duration_ms, key: 'max_duration_ms')) .query_param(new_parameter(target_duration_ms, key: 'target_duration_ms')) .query_param(new_parameter(min_energy, key: 'min_energy')) .query_param(new_parameter(max_energy, key: 'max_energy')) .query_param(new_parameter(target_energy, key: 'target_energy')) .query_param(new_parameter(min_instrumentalness, key: 'min_instrumentalness')) .query_param(new_parameter(max_instrumentalness, key: 'max_instrumentalness')) .query_param(new_parameter(target_instrumentalness, key: 'target_instrumentalness')) .query_param(new_parameter(min_key, key: 'min_key')) .query_param(new_parameter(max_key, key: 'max_key')) .query_param(new_parameter(target_key, key: 'target_key')) .query_param(new_parameter(min_liveness, key: 'min_liveness')) .query_param(new_parameter(max_liveness, key: 'max_liveness')) .query_param(new_parameter(target_liveness, key: 'target_liveness')) .query_param(new_parameter(min_loudness, key: 'min_loudness')) .query_param(new_parameter(max_loudness, key: 'max_loudness')) .query_param(new_parameter(target_loudness, key: 'target_loudness')) .query_param(new_parameter(min_mode, key: 'min_mode')) .query_param(new_parameter(max_mode, key: 'max_mode')) .query_param(new_parameter(target_mode, key: 'target_mode')) .query_param(new_parameter(min_popularity, key: 'min_popularity')) .query_param(new_parameter(max_popularity, key: 'max_popularity')) .query_param(new_parameter(target_popularity, key: 'target_popularity')) .query_param(new_parameter(min_speechiness, key: 'min_speechiness')) .query_param(new_parameter(max_speechiness, key: 'max_speechiness')) .query_param(new_parameter(target_speechiness, key: 'target_speechiness')) .query_param(new_parameter(min_tempo, key: 'min_tempo')) .query_param(new_parameter(max_tempo, key: 'max_tempo')) .query_param(new_parameter(target_tempo, key: 'target_tempo')) .query_param(new_parameter(min_time_signature, key: 'min_time_signature')) .query_param(new_parameter(max_time_signature, key: 'max_time_signature')) .query_param(new_parameter(target_time_signature, key: 'target_time_signature')) .query_param(new_parameter(min_valence, key: 'min_valence')) .query_param(new_parameter(max_valence, key: 'max_valence')) .query_param(new_parameter(target_valence, key: 'target_valence')) .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(RecommendationsObject.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_several_audio_features(ids) ⇒ ManyAudioFeatures
Get audio features for multiple tracks based on their Spotify IDs.
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 |
# File 'lib/spotify_web_api/controllers/tracks_controller.rb', line 222 def get_several_audio_features(ids) new_api_call_builder .request(new_request_builder(HttpMethodEnum::GET, '/audio-features', Server::DEFAULT) .query_param(new_parameter(ids, key: 'ids')) .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(ManyAudioFeatures.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_several_tracks(ids, market: nil) ⇒ ManyTracks
Get Spotify catalog information for multiple tracks based on their Spotify IDs.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/spotify_web_api/controllers/tracks_controller.rb', line 50 def get_several_tracks(ids, market: nil) new_api_call_builder .request(new_request_builder(HttpMethodEnum::GET, '/tracks', Server::DEFAULT) .query_param(new_parameter(ids, key: 'ids')) .query_param(new_parameter(market, key: 'market')) .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(ManyTracks.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_track(id, market: nil) ⇒ TrackObject
Get Spotify catalog information for a single track identified by its unique Spotify ID.
14 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 |
# File 'lib/spotify_web_api/controllers/tracks_controller.rb', line 14 def get_track(id, market: nil) new_api_call_builder .request(new_request_builder(HttpMethodEnum::GET, '/tracks/{id}', Server::DEFAULT) .template_param(new_parameter(id, key: 'id') .should_encode(true)) .query_param(new_parameter(market, key: 'market')) .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(TrackObject.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_users_saved_tracks(market: nil, limit: 20, offset: 0) ⇒ PagingSavedTrackObject
Get a list of the songs saved in the current Spotify user’s ‘Your Music’ library.
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/spotify_web_api/controllers/tracks_controller.rb', line 86 def get_users_saved_tracks(market: nil, limit: 20, offset: 0) new_api_call_builder .request(new_request_builder(HttpMethodEnum::GET, '/me/tracks', Server::DEFAULT) .query_param(new_parameter(market, key: 'market')) .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(PagingSavedTrackObject.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_user(ids, body: nil) ⇒ void
This method returns an undefined value.
Remove one or more tracks from the current user’s ‘Your Music’ library.
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'lib/spotify_web_api/controllers/tracks_controller.rb', line 156 def remove_tracks_user(ids, body: nil) new_api_call_builder .request(new_request_builder(HttpMethodEnum::DELETE, '/me/tracks', Server::DEFAULT) .query_param(new_parameter(ids, key: 'ids')) .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 |
#save_tracks_user(ids, body: nil) ⇒ void
This method returns an undefined value.
Save one or more tracks to the current user’s ‘Your Music’ library.
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/spotify_web_api/controllers/tracks_controller.rb', line 122 def save_tracks_user(ids, body: nil) new_api_call_builder .request(new_request_builder(HttpMethodEnum::PUT, '/me/tracks', Server::DEFAULT) .query_param(new_parameter(ids, key: 'ids')) .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 |