Class: SpotifyWebApi::DeviceObject

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/spotify_web_api/models/device_object.rb

Overview

DeviceObject Model.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#to_hash, #to_json

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

#idString

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.

Returns:

  • (String)


16
17
18
# File 'lib/spotify_web_api/models/device_object.rb', line 16

def id
  @id
end

#is_activeTrueClass | FalseClass

If this device is the currently active device.

Returns:

  • (TrueClass | FalseClass)


20
21
22
# File 'lib/spotify_web_api/models/device_object.rb', line 20

def is_active
  @is_active
end

#is_private_sessionTrueClass | FalseClass

If this device is currently in a private session.

Returns:

  • (TrueClass | FalseClass)


24
25
26
# File 'lib/spotify_web_api/models/device_object.rb', line 24

def is_private_session
  @is_private_session
end

#is_restrictedTrueClass | FalseClass

Whether controlling this device is restricted. At present if this is “true” then no Web API commands will be accepted by this device.

Returns:

  • (TrueClass | FalseClass)


29
30
31
# File 'lib/spotify_web_api/models/device_object.rb', line 29

def is_restricted
  @is_restricted
end

#nameString

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.

Returns:

  • (String)


35
36
37
# File 'lib/spotify_web_api/models/device_object.rb', line 35

def name
  @name
end

#supports_volumeTrueClass | FalseClass

If this device can be used to set the volume.

Returns:

  • (TrueClass | FalseClass)


47
48
49
# File 'lib/spotify_web_api/models/device_object.rb', line 47

def supports_volume
  @supports_volume
end

#typeString

Device type, such as “computer”, “smartphone” or “speaker”.

Returns:

  • (String)


39
40
41
# File 'lib/spotify_web_api/models/device_object.rb', line 39

def type
  @type
end

#volume_percentInteger

The current volume in percent.

Returns:

  • (Integer)


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

.namesObject

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

.nullablesObject

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

.optionalsObject

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