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
225 226 227 228 229 230 231 232 |
# File 'lib/spotify/sdk/connect/device.rb', line 225 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
202 203 204 205 |
# File 'lib/spotify/sdk/connect/device.rb', line 202 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
168 169 170 171 |
# File 'lib/spotify/sdk/connect/device.rb', line 168 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
rubocop:disable AbcSize
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/spotify/sdk/connect/device.rb', line 113 def play!(config) payload = case config.keys when %i[index context position_ms] {context_uri: config[:context], offset: {position: config[:index]}, position_ms: config[:position_ms]} when %i[uri position_ms] {uris: [config[:uri]], position_ms: config[:position_ms]} when %i[uri context position_ms] {context_uri: config[:context], offset: {uri: config[:uri]}, position_ms: config[:position_ms]} else raise <<-ERROR.strip_heredoc.strip Unrecognized play instructions. See https://www.rubydoc.info/github/bih/spotify-ruby/Spotify/SDK/Connect/Device#play!-instance_method for details. ERROR 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
185 186 187 188 |
# File 'lib/spotify/sdk/connect/device.rb', line 185 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
275 276 277 278 279 280 281 282 |
# File 'lib/spotify/sdk/connect/device.rb', line 275 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
151 152 153 154 |
# File 'lib/spotify/sdk/connect/device.rb', line 151 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
249 250 251 252 253 254 255 256 |
# File 'lib/spotify/sdk/connect/device.rb', line 249 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
299 300 301 302 303 304 305 306 |
# File 'lib/spotify/sdk/connect/device.rb', line 299 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
322 323 324 325 |
# File 'lib/spotify/sdk/connect/device.rb', line 322 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
339 340 341 342 |
# File 'lib/spotify/sdk/connect/device.rb', line 339 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 |