Class: Spotted::Resources::Me::Player

Inherits:
Object
  • Object
show all
Defined in:
lib/spotted/resources/me/player.rb,
lib/spotted/resources/me/player/queue.rb

Defined Under Namespace

Classes: Queue

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Player

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Player.

Parameters:



375
376
377
378
# File 'lib/spotted/resources/me/player.rb', line 375

def initialize(client:)
  @client = client
  @queue = Spotted::Resources::Me::Player::Queue.new(client: client)
end

Instance Attribute Details

#queueSpotted::Resources::Me::Player::Queue (readonly)



8
9
10
# File 'lib/spotted/resources/me/player.rb', line 8

def queue
  @queue
end

Instance Method Details

#get_currently_playing(additional_types: nil, market: nil, request_options: {}) ⇒ Spotted::Models::Me::PlayerGetCurrentlyPlayingResponse

Some parameter documentations has been truncated, see Models::Me::PlayerGetCurrentlyPlayingParams for more details.

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

Parameters:

Returns:

See Also:



26
27
28
29
30
31
32
33
34
35
# File 'lib/spotted/resources/me/player.rb', line 26

def get_currently_playing(params = {})
  parsed, options = Spotted::Me::PlayerGetCurrentlyPlayingParams.dump_request(params)
  @client.request(
    method: :get,
    path: "me/player/currently-playing",
    query: parsed,
    model: Spotted::Models::Me::PlayerGetCurrentlyPlayingResponse,
    options: options
  )
end

#get_devices(request_options: {}) ⇒ Spotted::Models::Me::PlayerGetDevicesResponse

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.

Parameters:

Returns:

See Also:



47
48
49
50
51
52
53
54
# File 'lib/spotted/resources/me/player.rb', line 47

def get_devices(params = {})
  @client.request(
    method: :get,
    path: "me/player/devices",
    model: Spotted::Models::Me::PlayerGetDevicesResponse,
    options: params[:request_options]
  )
end

#get_state(additional_types: nil, market: nil, request_options: {}) ⇒ Spotted::Models::Me::PlayerGetStateResponse

Some parameter documentations has been truncated, see Models::Me::PlayerGetStateParams for more details.

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

Parameters:

Returns:

See Also:



73
74
75
76
77
78
79
80
81
82
# File 'lib/spotted/resources/me/player.rb', line 73

def get_state(params = {})
  parsed, options = Spotted::Me::PlayerGetStateParams.dump_request(params)
  @client.request(
    method: :get,
    path: "me/player",
    query: parsed,
    model: Spotted::Models::Me::PlayerGetStateResponse,
    options: options
  )
end

#list_recently_played(after: nil, before: nil, limit: nil, request_options: {}) ⇒ Spotted::Internal::CursorURLPage<Spotted::Models::Me::PlayerListRecentlyPlayedResponse>

Some parameter documentations has been truncated, see Models::Me::PlayerListRecentlyPlayedParams for more details.

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

Parameters:

  • after (Integer)

    A Unix timestamp in milliseconds. Returns all items

  • before (Integer)

    A Unix timestamp in milliseconds. Returns all items

  • limit (Integer)

    The maximum number of items to return. Default: 20. Minimum: 1. Maximum: 50.

  • request_options (Spotted::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



103
104
105
106
107
108
109
110
111
112
113
# File 'lib/spotted/resources/me/player.rb', line 103

def list_recently_played(params = {})
  parsed, options = Spotted::Me::PlayerListRecentlyPlayedParams.dump_request(params)
  @client.request(
    method: :get,
    path: "me/player/recently-played",
    query: parsed,
    page: Spotted::Internal::CursorURLPage,
    model: Spotted::Models::Me::PlayerListRecentlyPlayedResponse,
    options: options
  )
end

#pause_playback(device_id: nil, request_options: {}) ⇒ nil

Some parameter documentations has been truncated, see Models::Me::PlayerPausePlaybackParams for more details.

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)

    The id of the device this command is targeting. If not supplied, the user’s curr

  • request_options (Spotted::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

  • (nil)

See Also:



131
132
133
134
135
136
137
138
139
140
# File 'lib/spotted/resources/me/player.rb', line 131

def pause_playback(params = {})
  parsed, options = Spotted::Me::PlayerPausePlaybackParams.dump_request(params)
  @client.request(
    method: :put,
    path: "me/player/pause",
    query: parsed,
    model: NilClass,
    options: options
  )
end

#seek_to_position(position_ms: , device_id: nil, request_options: {}) ⇒ nil

Some parameter documentations has been truncated, see Models::Me::PlayerSeekToPositionParams for more details.

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)

    The position in milliseconds to seek to. Must be a

  • device_id (String)

    The id of the device this command is targeting. If

  • request_options (Spotted::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

  • (nil)

See Also:



160
161
162
163
164
165
166
167
168
169
# File 'lib/spotted/resources/me/player.rb', line 160

def seek_to_position(params)
  parsed, options = Spotted::Me::PlayerSeekToPositionParams.dump_request(params)
  @client.request(
    method: :put,
    path: "me/player/seek",
    query: parsed,
    model: NilClass,
    options: options
  )
end

#set_repeat_mode(state: , device_id: nil, request_options: {}) ⇒ nil

Some parameter documentations has been truncated, see Models::Me::PlayerSetRepeatModeParams for more details.

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)

    track, context or off.<br/>

  • device_id (String)

    The id of the device this command is targeting. If

  • request_options (Spotted::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

  • (nil)

See Also:



189
190
191
192
193
194
195
196
197
198
# File 'lib/spotted/resources/me/player.rb', line 189

def set_repeat_mode(params)
  parsed, options = Spotted::Me::PlayerSetRepeatModeParams.dump_request(params)
  @client.request(
    method: :put,
    path: "me/player/repeat",
    query: parsed,
    model: NilClass,
    options: options
  )
end

#set_volume(volume_percent: , device_id: nil, request_options: {}) ⇒ nil

Some parameter documentations has been truncated, see Models::Me::PlayerSetVolumeParams for more details.

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)

    The volume to set. Must be a value from 0 to 100 inclusive.

  • device_id (String)

    The id of the device this command is targeting. If not supplied, the user’s curr

  • request_options (Spotted::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

  • (nil)

See Also:



218
219
220
221
222
223
224
225
226
227
# File 'lib/spotted/resources/me/player.rb', line 218

def set_volume(params)
  parsed, options = Spotted::Me::PlayerSetVolumeParams.dump_request(params)
  @client.request(
    method: :put,
    path: "me/player/volume",
    query: parsed,
    model: NilClass,
    options: options
  )
end

#skip_next(device_id: nil, request_options: {}) ⇒ nil

Some parameter documentations has been truncated, see Models::Me::PlayerSkipNextParams for more details.

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)

    The id of the device this command is targeting. If not supplied, the user’s curr

  • request_options (Spotted::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

  • (nil)

See Also:



245
246
247
248
249
250
251
252
253
254
# File 'lib/spotted/resources/me/player.rb', line 245

def skip_next(params = {})
  parsed, options = Spotted::Me::PlayerSkipNextParams.dump_request(params)
  @client.request(
    method: :post,
    path: "me/player/next",
    query: parsed,
    model: NilClass,
    options: options
  )
end

#skip_previous(device_id: nil, request_options: {}) ⇒ nil

Some parameter documentations has been truncated, see Models::Me::PlayerSkipPreviousParams for more details.

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)

    The id of the device this command is targeting. If

  • request_options (Spotted::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

  • (nil)

See Also:



272
273
274
275
276
277
278
279
280
281
# File 'lib/spotted/resources/me/player.rb', line 272

def skip_previous(params = {})
  parsed, options = Spotted::Me::PlayerSkipPreviousParams.dump_request(params)
  @client.request(
    method: :post,
    path: "me/player/previous",
    query: parsed,
    model: NilClass,
    options: options
  )
end

#start_playback(device_id: nil, context_uri: nil, offset: nil, position_ms: nil, uris: nil, request_options: {}) ⇒ nil

Some parameter documentations has been truncated, see Models::Me::PlayerStartPlaybackParams for more details.

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)

    Query param: The id of the device this command is targeting. If not supplied, th

  • context_uri (String)

    Body param: Optional. Spotify URI of the context to play.

  • offset (Hash{Symbol=>Object})

    Body param: Optional. Indicates from where in the context playback should start.

  • position_ms (Integer)

    Body param: Indicates from what position to start playback. Must be a positive n

  • uris (Array<String>)

    Body param: Optional. A JSON array of the Spotify track URIs to play.

  • request_options (Spotted::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

  • (nil)

See Also:



307
308
309
310
311
312
313
314
315
316
317
318
# File 'lib/spotted/resources/me/player.rb', line 307

def start_playback(params = {})
  parsed, options = Spotted::Me::PlayerStartPlaybackParams.dump_request(params)
  query_params = [:device_id]
  @client.request(
    method: :put,
    path: "me/player/play",
    query: parsed.slice(*query_params),
    body: parsed.except(*query_params),
    model: NilClass,
    options: options
  )
end

#toggle_shuffle(state: , device_id: nil, request_options: {}) ⇒ nil

Some parameter documentations has been truncated, see Models::Me::PlayerToggleShuffleParams for more details.

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 (Boolean)

    true : Shuffle user’s playback.<br/>

  • device_id (String)

    The id of the device this command is targeting. If

  • request_options (Spotted::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

  • (nil)

See Also:



338
339
340
341
342
343
344
345
346
347
# File 'lib/spotted/resources/me/player.rb', line 338

def toggle_shuffle(params)
  parsed, options = Spotted::Me::PlayerToggleShuffleParams.dump_request(params)
  @client.request(
    method: :put,
    path: "me/player/shuffle",
    query: parsed,
    model: NilClass,
    options: options
  )
end

#transfer(device_ids: , play: nil, request_options: {}) ⇒ nil

Some parameter documentations has been truncated, see Models::Me::PlayerTransferParams for more details.

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:

  • device_ids (Array<String>)

    A JSON array containing the ID of the device on which playback should be started

  • play (Boolean)

    true: ensure playback happens on new device.<br/>false or not provided:

  • request_options (Spotted::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

  • (nil)

See Also:



367
368
369
370
# File 'lib/spotted/resources/me/player.rb', line 367

def transfer(params)
  parsed, options = Spotted::Me::PlayerTransferParams.dump_request(params)
  @client.request(method: :put, path: "me/player", body: parsed, model: NilClass, options: options)
end