Class: Spotify::SDK::Connect::Device
- Defined in:
- lib/spotify/sdk/connect/device.rb
Instance Attribute Summary
Attributes inherited from Model
Instance Method Summary collapse
-
#active? ⇒ Boolean
Is the device active?.
-
#change_volume!(volume_percent) ⇒ Spotify::SDK::Connect::Device
(also: #volume=)
Set volume for current device.
-
#next! ⇒ Spotify::SDK::Connect::Device
Skip to next track on device.
-
#pause! ⇒ Spotify::SDK::Connect::Device
Pause the currently playing track on device.
-
#play!(config) ⇒ Spotify::SDK::Connect::Device
Play the currently playing track on device.
-
#playback ⇒ Spotify::SDK::Connect::PlaybackState
Get the currently playing track.
-
#previous! ⇒ Spotify::SDK::Connect::Device
Skip to previous track on device.
-
#private_session? ⇒ Boolean
Is the device’s session private?.
-
#repeat!(state) ⇒ Spotify::SDK::Connect::Device
(also: #repeat=)
Set repeat mode for current device.
-
#restricted? ⇒ Boolean
Is the device restricted?.
-
#resume! ⇒ Spotify::SDK::Connect::Device
Resume the currently playing track on device.
-
#seek_ms!(position_ms) ⇒ Spotify::SDK::Connect::Device
(also: #position_ms=)
Seek position (in milliseconds) for the currently playing track on the device.
-
#shuffle!(state) ⇒ Spotify::SDK::Connect::Device
(also: #shuffle=)
Set shuffle for current device.
-
#transfer_playback! ⇒ Spotify::SDK::Connect::Device
Transfer a user’s playback to another device, and continue playing.
-
#transfer_state! ⇒ Spotify::SDK::Connect::Device
Transfer a user’s playback to another device, and pause.
-
#volume ⇒ Integer
Get the device’s volume.
Methods inherited from Model
alias_attribute, hash_selector, #initialize, #to_h, #to_json
Constructor Details
This class inherits a constructor from Spotify::SDK::Model
Instance Method Details
#active? ⇒ Boolean
Is the device active?
27 |
# File 'lib/spotify/sdk/connect/device.rb', line 27 alias_attribute :active?, :is_active |
#change_volume!(volume_percent) ⇒ Spotify::SDK::Connect::Device Also known as: volume=
Set volume for current device. PUT /v1/me/player/volume
197 198 199 200 201 202 203 |
# File 'lib/spotify/sdk/connect/device.rb', line 197 def change_volume!(volume_percent) raise "Must be an integer" unless volume_percent.is_a?(Integer) endpoint = "/v1/me/player/volume?volume_percent=%i&device_id=%s" % [volume_percent, id] opts = {http_options: {expect_nil: true}} parent.send_http_request(:put, endpoint, opts) self end |
#next! ⇒ Spotify::SDK::Connect::Device
Skip to next track on device. POST /v1/me/player/next
174 175 176 177 |
# File 'lib/spotify/sdk/connect/device.rb', line 174 def next! parent.send_http_request(:post, "/v1/me/player/next?device_id=%s" % id, http_options: {expect_nil: true}) self end |
#pause! ⇒ Spotify::SDK::Connect::Device
Pause the currently playing track on device. PUT /v1/me/player/pause
140 141 142 143 |
# File 'lib/spotify/sdk/connect/device.rb', line 140 def pause! parent.send_http_request(:put, "/v1/me/player/pause?device_id=%s" % id, http_options: {expect_nil: true}) self end |
#play!(config) ⇒ Spotify::SDK::Connect::Device
Play the currently playing track on device. PUT /v1/me/player/play
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/spotify/sdk/connect/device.rb', line 94 def play!(config) payload = case config.keys when %i[index context] {context_uri: config[:context], offset: {position: config[:index]}} when %i[uri] {uris: [config[:uri]]} when %i[uri context] {context_uri: config[:context], offset: {uri: config[:uri]}} else raise "Unrecognized play instructions. See documentation for details." end parent.send_http_request(:put, "/v1/me/player/play?device_id=%s" % id, http_options: {expect_nil: true}, body: payload.to_json) self end |
#playback ⇒ Spotify::SDK::Connect::PlaybackState
Get the currently playing track. Alias to Spotify::SDK::Connect#playback
66 67 68 |
# File 'lib/spotify/sdk/connect/device.rb', line 66 def playback parent.playback end |
#previous! ⇒ Spotify::SDK::Connect::Device
Skip to previous track on device. POST /v1/me/player/previous
157 158 159 160 |
# File 'lib/spotify/sdk/connect/device.rb', line 157 def previous! parent.send_http_request(:post, "/v1/me/player/previous?device_id=%s" % id, http_options: {expect_nil: true}) self end |
#private_session? ⇒ Boolean
Is the device’s session private?
38 |
# File 'lib/spotify/sdk/connect/device.rb', line 38 alias_attribute :private_session?, :is_private_session |
#repeat!(state) ⇒ Spotify::SDK::Connect::Device Also known as: repeat=
Set repeat mode for current device. PUT /v1/me/player/repeat
245 246 247 248 249 250 251 |
# File 'lib/spotify/sdk/connect/device.rb', line 245 def repeat!(state) raise "Must be :track, :context, or :off" unless %i[track context off].include?(state) endpoint = "/v1/me/player/repeat?state=%s&device_id=%s" % [state, id] opts = {http_options: {expect_nil: true}} parent.send_http_request(:put, endpoint, opts) self end |
#restricted? ⇒ Boolean
Is the device restricted?
49 |
# File 'lib/spotify/sdk/connect/device.rb', line 49 alias_attribute :restricted?, :is_restricted |
#resume! ⇒ Spotify::SDK::Connect::Device
Resume the currently playing track on device. PUT /v1/me/player/play
123 124 125 126 |
# File 'lib/spotify/sdk/connect/device.rb', line 123 def resume! parent.send_http_request(:put, "/v1/me/player/play?device_id=%s" % id, http_options: {expect_nil: true}) self end |
#seek_ms!(position_ms) ⇒ Spotify::SDK::Connect::Device Also known as: position_ms=
Seek position (in milliseconds) for the currently playing track on the device. PUT /v1/me/player/seek
220 221 222 223 224 225 226 |
# File 'lib/spotify/sdk/connect/device.rb', line 220 def seek_ms!(position_ms) raise "Must be an integer" unless position_ms.is_a?(Integer) endpoint = "/v1/me/player/seek?position_ms=%i&device_id=%s" % [position_ms, id] opts = {http_options: {expect_nil: true}} parent.send_http_request(:put, endpoint, opts) self end |
#shuffle!(state) ⇒ Spotify::SDK::Connect::Device Also known as: shuffle=
Set shuffle for current device. PUT /v1/me/player/shuffle
268 269 270 271 272 273 274 |
# File 'lib/spotify/sdk/connect/device.rb', line 268 def shuffle!(state) raise "Must be true or false" unless [true, false].include?(state) endpoint = "/v1/me/player/shuffle?state=%s&device_id=%s" % [state, id] opts = {http_options: {expect_nil: true}} parent.send_http_request(:put, endpoint, opts) self end |
#transfer_playback! ⇒ Spotify::SDK::Connect::Device
Transfer a user’s playback to another device, and continue playing. PUT /v1/me/player
290 291 292 293 |
# File 'lib/spotify/sdk/connect/device.rb', line 290 def transfer_playback! transfer_playback_method(playing: true) self end |
#transfer_state! ⇒ Spotify::SDK::Connect::Device
Transfer a user’s playback to another device, and pause. PUT /v1/me/player
307 308 309 310 |
# File 'lib/spotify/sdk/connect/device.rb', line 307 def transfer_state! transfer_playback_method(playing: false) self end |
#volume ⇒ Integer
Get the device’s volume.
16 |
# File 'lib/spotify/sdk/connect/device.rb', line 16 alias_attribute :volume, :volume_percent |