Class: SpotifyWebApi::CurrentlyPlayingContextObject

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

Overview

CurrentlyPlayingContextObject Model.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#to_hash, #to_json

Constructor Details

#initialize(device = SKIP, repeat_state = SKIP, shuffle_state = SKIP, context = SKIP, timestamp = SKIP, progress_ms = SKIP, is_playing = SKIP, item = SKIP, currently_playing_type = SKIP, actions = SKIP) ⇒ CurrentlyPlayingContextObject

Returns a new instance of CurrentlyPlayingContextObject.



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/spotify_web_api/models/currently_playing_context_object.rb', line 91

def initialize(device = SKIP, repeat_state = SKIP, shuffle_state = SKIP,
               context = SKIP, timestamp = SKIP, progress_ms = SKIP,
               is_playing = SKIP, item = SKIP,
               currently_playing_type = SKIP, actions = SKIP)
  @device = device unless device == SKIP
  @repeat_state = repeat_state unless repeat_state == SKIP
  @shuffle_state = shuffle_state unless shuffle_state == SKIP
  @context = context unless context == SKIP
  @timestamp = timestamp unless timestamp == SKIP
  @progress_ms = progress_ms unless progress_ms == SKIP
  @is_playing = is_playing unless is_playing == SKIP
  @item = item unless item == SKIP
  @currently_playing_type = currently_playing_type unless currently_playing_type == SKIP
  @actions = actions unless actions == SKIP
end

Instance Attribute Details

#actionsDisallowsObject

Allows to update the user interface based on which playback actions are available within the current context.

Returns:



52
53
54
# File 'lib/spotify_web_api/models/currently_playing_context_object.rb', line 52

def actions
  @actions
end

#contextContextObject

A Context Object. Can be ‘null`.

Returns:



26
27
28
# File 'lib/spotify_web_api/models/currently_playing_context_object.rb', line 26

def context
  @context
end

#currently_playing_typeString

The object type of the currently playing item. Can be one of ‘track`, `episode`, `ad` or `unknown`.

Returns:

  • (String)


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

def currently_playing_type
  @currently_playing_type
end

#deviceDeviceObject

The device that is currently active.

Returns:



14
15
16
# File 'lib/spotify_web_api/models/currently_playing_context_object.rb', line 14

def device
  @device
end

#is_playingTrueClass | FalseClass

If something is currently playing, return ‘true`.

Returns:

  • (TrueClass | FalseClass)


38
39
40
# File 'lib/spotify_web_api/models/currently_playing_context_object.rb', line 38

def is_playing
  @is_playing
end

#itemObject

The currently playing track or episode. Can be ‘null`.

Returns:

  • (Object)


42
43
44
# File 'lib/spotify_web_api/models/currently_playing_context_object.rb', line 42

def item
  @item
end

#progress_msInteger

Progress into the currently playing track or episode. Can be ‘null`.

Returns:

  • (Integer)


34
35
36
# File 'lib/spotify_web_api/models/currently_playing_context_object.rb', line 34

def progress_ms
  @progress_ms
end

#repeat_stateString

off, track, context

Returns:

  • (String)


18
19
20
# File 'lib/spotify_web_api/models/currently_playing_context_object.rb', line 18

def repeat_state
  @repeat_state
end

#shuffle_stateTrueClass | FalseClass

If shuffle is on or off.

Returns:

  • (TrueClass | FalseClass)


22
23
24
# File 'lib/spotify_web_api/models/currently_playing_context_object.rb', line 22

def shuffle_state
  @shuffle_state
end

#timestampInteger

Unix Millisecond Timestamp when data was fetched.

Returns:

  • (Integer)


30
31
32
# File 'lib/spotify_web_api/models/currently_playing_context_object.rb', line 30

def timestamp
  @timestamp
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/spotify_web_api/models/currently_playing_context_object.rb', line 108

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  device = DeviceObject.from_hash(hash['device']) if hash['device']
  repeat_state = hash.key?('repeat_state') ? hash['repeat_state'] : SKIP
  shuffle_state = hash.key?('shuffle_state') ? hash['shuffle_state'] : SKIP
  context = ContextObject.from_hash(hash['context']) if hash['context']
  timestamp = hash.key?('timestamp') ? hash['timestamp'] : SKIP
  progress_ms = hash.key?('progress_ms') ? hash['progress_ms'] : SKIP
  is_playing = hash.key?('is_playing') ? hash['is_playing'] : SKIP
  item = hash.key?('item') ? hash['item'] : SKIP
  currently_playing_type =
    hash.key?('currently_playing_type') ? hash['currently_playing_type'] : SKIP
  actions = DisallowsObject.from_hash(hash['actions']) if hash['actions']

  # Create object from extracted values.
  CurrentlyPlayingContextObject.new(device,
                                    repeat_state,
                                    shuffle_state,
                                    context,
                                    timestamp,
                                    progress_ms,
                                    is_playing,
                                    item,
                                    currently_playing_type,
                                    actions)
end

.namesObject

A mapping from model property names to API property names.



55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/spotify_web_api/models/currently_playing_context_object.rb', line 55

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['device'] = 'device'
  @_hash['repeat_state'] = 'repeat_state'
  @_hash['shuffle_state'] = 'shuffle_state'
  @_hash['context'] = 'context'
  @_hash['timestamp'] = 'timestamp'
  @_hash['progress_ms'] = 'progress_ms'
  @_hash['is_playing'] = 'is_playing'
  @_hash['item'] = 'item'
  @_hash['currently_playing_type'] = 'currently_playing_type'
  @_hash['actions'] = 'actions'
  @_hash
end

.nullablesObject

An array for nullable fields



87
88
89
# File 'lib/spotify_web_api/models/currently_playing_context_object.rb', line 87

def self.nullables
  []
end

.optionalsObject

An array for optional fields



71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/spotify_web_api/models/currently_playing_context_object.rb', line 71

def self.optionals
  %w[
    device
    repeat_state
    shuffle_state
    context
    timestamp
    progress_ms
    is_playing
    item
    currently_playing_type
    actions
  ]
end