Class: SpotifyWebApi::PlayerController

Inherits:
BaseController show all
Defined in:
lib/spotify_web_api/controllers/player_controller.rb

Overview

PlayerController

Constant Summary

Constants inherited from BaseController

BaseController::GLOBAL_ERRORS

Instance Attribute Summary

Attributes inherited from BaseController

#config, #http_call_back

Instance Method Summary collapse

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_to_queue(uri, device_id: nil) ⇒ void

This method returns an undefined value.

Add an item to the end of the user’s current playback queue. This API only works for users who have Spotify Premium. The order of execution is not guaranteed when you use this API with other Player API endpoints.

Parameters:

  • uri (String)

    Required parameter: Example:

  • device_id (String) (defaults to: nil)

    Optional parameter: Example:



481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
# File 'lib/spotify_web_api/controllers/player_controller.rb', line 481

def add_to_queue(uri,
                 device_id: nil)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::POST,
                                 '/me/player/queue',
                                 Server::DEFAULT)
               .query_param(new_parameter(uri, key: 'uri'))
               .query_param(new_parameter(device_id, key: 'device_id'))
               .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

#get_a_users_available_devicesManyDevices

Get information about a user’s available Spotify Connect devices. Some device models are not supported and will not be listed in the API response.

Returns:



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/spotify_web_api/controllers/player_controller.rb', line 81

def get_a_users_available_devices
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/me/player/devices',
                                 Server::DEFAULT)
               .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(ManyDevices.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_information_about_the_users_current_playback(market: nil, additional_types: nil) ⇒ CurrentlyPlayingContextObject

Get information about the user’s current playback state, including track or episode, progress, and active device.

Parameters:

  • market (String) (defaults to: nil)

    Optional parameter: Example:

  • additional_types (String) (defaults to: nil)

    Optional parameter: Example:

Returns:



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
# File 'lib/spotify_web_api/controllers/player_controller.rb', line 14

def get_information_about_the_users_current_playback(market: nil,
                                                     additional_types: nil)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/me/player',
                                 Server::DEFAULT)
               .query_param(new_parameter(market, key: 'market'))
               .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(CurrentlyPlayingContextObject.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_queueQueueObject

Get the list of objects that make up the user’s queue.

Returns:



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
# File 'lib/spotify_web_api/controllers/player_controller.rb', line 448

def get_queue
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/me/player/queue',
                                 Server::DEFAULT)
               .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(QueueObject.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_recently_played(limit: 20, after: nil, before: nil) ⇒ CursorPagingPlayHistoryObject

Get tracks from the current user’s recently played tracks. _Note: Currently doesn’t support podcast episodes._

Parameters:

  • limit (Integer) (defaults to: 20)

    Optional parameter: Example:20

  • after (Integer) (defaults to: nil)

    Optional parameter: Example:

  • before (Integer) (defaults to: nil)

    Optional parameter: Example:

Returns:



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
# File 'lib/spotify_web_api/controllers/player_controller.rb', line 414

def get_recently_played(limit: 20,
                        after: nil,
                        before: nil)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/me/player/recently-played',
                                 Server::DEFAULT)
               .query_param(new_parameter(limit, key: 'limit'))
               .query_param(new_parameter(after, key: 'after'))
               .query_param(new_parameter(before, key: 'before'))
               .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(CursorPagingPlayHistoryObject.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_the_users_currently_playing_track(market: nil, additional_types: nil) ⇒ CurrentlyPlayingObject

Get the object currently being played on the user’s Spotify account.

Parameters:

  • market (String) (defaults to: nil)

    Optional parameter: Example:

  • additional_types (String) (defaults to: nil)

    Optional parameter: Example:

Returns:



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/spotify_web_api/controllers/player_controller.rb', line 112

def get_the_users_currently_playing_track(market: nil,
                                          additional_types: nil)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/me/player/currently-playing',
                                 Server::DEFAULT)
               .query_param(new_parameter(market, key: 'market'))
               .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(CurrentlyPlayingObject.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

#pause_a_users_playback(device_id: nil) ⇒ void

This method returns an undefined value.

Pause playback on the user’s account. This API only works for users who have Spotify Premium. The order of execution is not guaranteed when you use this API with other Player API endpoints.

Parameters:

  • device_id (String) (defaults to: nil)

    Optional parameter: Example:



184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
# File 'lib/spotify_web_api/controllers/player_controller.rb', line 184

def pause_a_users_playback(device_id: nil)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::PUT,
                                 '/me/player/pause',
                                 Server::DEFAULT)
               .query_param(new_parameter(device_id, key: 'device_id'))
               .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

#seek_to_position_in_currently_playing_track(position_ms, device_id: nil) ⇒ void

This method returns an undefined value.

Seeks to the given position in the user’s currently playing track. This API only works for users who have Spotify Premium. The order of execution is not guaranteed when you use this API with other Player API endpoints.

Parameters:

  • position_ms (Integer)

    Required parameter: Example:

  • device_id (String) (defaults to: nil)

    Optional parameter: Example:



278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
# File 'lib/spotify_web_api/controllers/player_controller.rb', line 278

def seek_to_position_in_currently_playing_track(position_ms,
                                                device_id: nil)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::PUT,
                                 '/me/player/seek',
                                 Server::DEFAULT)
               .query_param(new_parameter(position_ms, key: 'position_ms'))
               .query_param(new_parameter(device_id, key: 'device_id'))
               .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

#set_repeat_mode_on_users_playback(state, device_id: nil) ⇒ void

This method returns an undefined value.

Set the repeat mode for the user’s playback. This API only works for users who have Spotify Premium. The order of execution is not guaranteed when you use this API with other Player API endpoints.

Parameters:

  • state (String)

    Required parameter: Example:

  • device_id (String) (defaults to: nil)

    Optional parameter: Example:



312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
# File 'lib/spotify_web_api/controllers/player_controller.rb', line 312

def set_repeat_mode_on_users_playback(state,
                                      device_id: nil)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::PUT,
                                 '/me/player/repeat',
                                 Server::DEFAULT)
               .query_param(new_parameter(state, key: 'state'))
               .query_param(new_parameter(device_id, key: 'device_id'))
               .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

#set_volume_for_users_playback(volume_percent, device_id: nil) ⇒ void

This method returns an undefined value.

Set the volume for the user’s current playback device. This API only works for users who have Spotify Premium. The order of execution is not guaranteed when you use this API with other Player API endpoints.

Parameters:

  • volume_percent (Integer)

    Required parameter: Example:

  • device_id (String) (defaults to: nil)

    Optional parameter: Example:



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
# File 'lib/spotify_web_api/controllers/player_controller.rb', line 346

def set_volume_for_users_playback(volume_percent,
                                  device_id: nil)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::PUT,
                                 '/me/player/volume',
                                 Server::DEFAULT)
               .query_param(new_parameter(volume_percent, key: 'volume_percent'))
               .query_param(new_parameter(device_id, key: 'device_id'))
               .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

#skip_users_playback_to_next_track(device_id: nil) ⇒ void

This method returns an undefined value.

Skips to next track in the user’s queue. This API only works for users who have Spotify Premium. The order of execution is not guaranteed when you use this API with other Player API endpoints.

Parameters:

  • device_id (String) (defaults to: nil)

    Optional parameter: Example:



215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
# File 'lib/spotify_web_api/controllers/player_controller.rb', line 215

def skip_users_playback_to_next_track(device_id: nil)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::POST,
                                 '/me/player/next',
                                 Server::DEFAULT)
               .query_param(new_parameter(device_id, key: 'device_id'))
               .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

#skip_users_playback_to_previous_track(device_id: nil) ⇒ void

This method returns an undefined value.

Skips to previous track in the user’s queue. This API only works for users who have Spotify Premium. The order of execution is not guaranteed when you use this API with other Player API endpoints.

Parameters:

  • device_id (String) (defaults to: nil)

    Optional parameter: Example:



246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
# File 'lib/spotify_web_api/controllers/player_controller.rb', line 246

def skip_users_playback_to_previous_track(device_id: nil)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::POST,
                                 '/me/player/previous',
                                 Server::DEFAULT)
               .query_param(new_parameter(device_id, key: 'device_id'))
               .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

#start_a_users_playback(device_id: nil, body: nil) ⇒ void

This method returns an undefined value.

Start a new context or resume current playback on the user’s active device. This API only works for users who have Spotify Premium. The order of execution is not guaranteed when you use this API with other Player API endpoints.

Parameters:

  • device_id (String) (defaults to: nil)

    Optional parameter: Example:

  • body (MePlayerPlayRequest) (defaults to: nil)

    Optional parameter: Example:



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
175
176
177
# File 'lib/spotify_web_api/controllers/player_controller.rb', line 149

def start_a_users_playback(device_id: nil,
                           body: nil)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::PUT,
                                 '/me/player/play',
                                 Server::DEFAULT)
               .header_param(new_parameter('application/json', key: 'Content-Type'))
               .query_param(new_parameter(device_id, key: 'device_id'))
               .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

#toggle_shuffle_for_users_playback(state, device_id: nil) ⇒ void

This method returns an undefined value.

Toggle shuffle on or off for user’s playback. This API only works for users who have Spotify Premium. The order of execution is not guaranteed when you use this API with other Player API endpoints.

Parameters:

  • state (TrueClass | FalseClass)

    Required parameter: Example:

  • device_id (String) (defaults to: nil)

    Optional parameter: Example:



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
# File 'lib/spotify_web_api/controllers/player_controller.rb', line 380

def toggle_shuffle_for_users_playback(state,
                                      device_id: nil)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::PUT,
                                 '/me/player/shuffle',
                                 Server::DEFAULT)
               .query_param(new_parameter(state, key: 'state'))
               .query_param(new_parameter(device_id, key: 'device_id'))
               .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

#transfer_a_users_playback(body: nil) ⇒ void

This method returns an undefined value.

Transfer playback to a new device and optionally begin playback. This API only works for users who have Spotify Premium. The order of execution is not guaranteed when you use this API with other Player API endpoints.

Parameters:

  • body (MePlayerRequest) (defaults to: nil)

    Optional parameter: Example:



49
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
# File 'lib/spotify_web_api/controllers/player_controller.rb', line 49

def transfer_a_users_playback(body: nil)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::PUT,
                                 '/me/player',
                                 Server::DEFAULT)
               .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