Class: SpotifyWebApi::DeviceObject
- Defined in:
- lib/spotify_web_api/models/device_object.rb
Overview
DeviceObject Model.
Instance Attribute Summary collapse
-
#id ⇒ String
The device ID.
-
#is_active ⇒ TrueClass | FalseClass
If this device is the currently active device.
-
#is_private_session ⇒ TrueClass | FalseClass
If this device is currently in a private session.
-
#is_restricted ⇒ TrueClass | FalseClass
Whether controlling this device is restricted.
-
#name ⇒ String
A human-readable name for the device.
-
#supports_volume ⇒ TrueClass | FalseClass
If this device can be used to set the volume.
-
#type ⇒ String
Device type, such as “computer”, “smartphone” or “speaker”.
-
#volume_percent ⇒ Integer
The current volume in percent.
Class Method Summary collapse
-
.from_hash(hash) ⇒ Object
Creates an instance of the object from a hash.
-
.names ⇒ Object
A mapping from model property names to API property names.
-
.nullables ⇒ Object
An array for nullable fields.
-
.optionals ⇒ Object
An array for optional fields.
Instance Method Summary collapse
-
#initialize(id = SKIP, is_active = SKIP, is_private_session = SKIP, is_restricted = SKIP, name = SKIP, type = SKIP, volume_percent = SKIP, supports_volume = SKIP) ⇒ DeviceObject
constructor
A new instance of DeviceObject.
Methods inherited from BaseModel
Constructor Details
#initialize(id = SKIP, is_active = SKIP, is_private_session = SKIP, is_restricted = SKIP, name = SKIP, type = SKIP, volume_percent = SKIP, supports_volume = SKIP) ⇒ DeviceObject
Returns a new instance of DeviceObject.
85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/spotify_web_api/models/device_object.rb', line 85 def initialize(id = SKIP, is_active = SKIP, is_private_session = SKIP, is_restricted = SKIP, name = SKIP, type = SKIP, volume_percent = SKIP, supports_volume = SKIP) @id = id unless id == SKIP @is_active = is_active unless is_active == SKIP @is_private_session = is_private_session unless is_private_session == SKIP @is_restricted = is_restricted unless is_restricted == SKIP @name = name unless name == SKIP @type = type unless type == SKIP @volume_percent = volume_percent unless volume_percent == SKIP @supports_volume = supports_volume unless supports_volume == SKIP end |
Instance Attribute Details
#id ⇒ String
The device ID. This ID is unique and persistent to some extent. However, this is not guaranteed and any cached ‘device_id` should periodically be cleared out and refetched as necessary.
16 17 18 |
# File 'lib/spotify_web_api/models/device_object.rb', line 16 def id @id end |
#is_active ⇒ TrueClass | FalseClass
If this device is the currently active device.
20 21 22 |
# File 'lib/spotify_web_api/models/device_object.rb', line 20 def is_active @is_active end |
#is_private_session ⇒ TrueClass | FalseClass
If this device is currently in a private session.
24 25 26 |
# File 'lib/spotify_web_api/models/device_object.rb', line 24 def is_private_session @is_private_session end |
#is_restricted ⇒ TrueClass | FalseClass
Whether controlling this device is restricted. At present if this is “true” then no Web API commands will be accepted by this device.
29 30 31 |
# File 'lib/spotify_web_api/models/device_object.rb', line 29 def is_restricted @is_restricted end |
#name ⇒ String
A human-readable name for the device. Some devices have a name that the user can configure (e.g. "Loudest speaker") and some devices have a generic name associated with the manufacturer or device model.
35 36 37 |
# File 'lib/spotify_web_api/models/device_object.rb', line 35 def name @name end |
#supports_volume ⇒ TrueClass | FalseClass
If this device can be used to set the volume.
47 48 49 |
# File 'lib/spotify_web_api/models/device_object.rb', line 47 def supports_volume @supports_volume end |
#type ⇒ String
Device type, such as “computer”, “smartphone” or “speaker”.
39 40 41 |
# File 'lib/spotify_web_api/models/device_object.rb', line 39 def type @type end |
#volume_percent ⇒ Integer
The current volume in percent.
43 44 45 |
# File 'lib/spotify_web_api/models/device_object.rb', line 43 def volume_percent @volume_percent end |
Class Method Details
.from_hash(hash) ⇒ Object
Creates an instance of the object from a hash.
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/spotify_web_api/models/device_object.rb', line 99 def self.from_hash(hash) return nil unless hash # Extract variables from the hash. id = hash.key?('id') ? hash['id'] : SKIP is_active = hash.key?('is_active') ? hash['is_active'] : SKIP is_private_session = hash.key?('is_private_session') ? hash['is_private_session'] : SKIP is_restricted = hash.key?('is_restricted') ? hash['is_restricted'] : SKIP name = hash.key?('name') ? hash['name'] : SKIP type = hash.key?('type') ? hash['type'] : SKIP volume_percent = hash.key?('volume_percent') ? hash['volume_percent'] : SKIP supports_volume = hash.key?('supports_volume') ? hash['supports_volume'] : SKIP # Create object from extracted values. DeviceObject.new(id, is_active, is_private_session, is_restricted, name, type, volume_percent, supports_volume) end |
.names ⇒ Object
A mapping from model property names to API property names.
50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/spotify_web_api/models/device_object.rb', line 50 def self.names @_hash = {} if @_hash.nil? @_hash['id'] = 'id' @_hash['is_active'] = 'is_active' @_hash['is_private_session'] = 'is_private_session' @_hash['is_restricted'] = 'is_restricted' @_hash['name'] = 'name' @_hash['type'] = 'type' @_hash['volume_percent'] = 'volume_percent' @_hash['supports_volume'] = 'supports_volume' @_hash end |
.nullables ⇒ Object
An array for nullable fields
78 79 80 81 82 83 |
# File 'lib/spotify_web_api/models/device_object.rb', line 78 def self.nullables %w[ id volume_percent ] end |
.optionals ⇒ Object
An array for optional fields
64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/spotify_web_api/models/device_object.rb', line 64 def self.optionals %w[ id is_active is_private_session is_restricted name type volume_percent supports_volume ] end |