Class: SpotifyWebApi::CurrentlyPlayingContextObject
- Inherits:
-
BaseModel
- Object
- CoreLibrary::BaseModel
- BaseModel
- SpotifyWebApi::CurrentlyPlayingContextObject
- Defined in:
- lib/spotify_web_api/models/currently_playing_context_object.rb
Overview
CurrentlyPlayingContextObject Model.
Instance Attribute Summary collapse
-
#actions ⇒ DisallowsObject
Allows to update the user interface based on which playback actions are available within the current context.
-
#context ⇒ ContextObject
A Context Object.
-
#currently_playing_type ⇒ String
The object type of the currently playing item.
-
#device ⇒ DeviceObject
The device that is currently active.
-
#is_playing ⇒ TrueClass | FalseClass
If something is currently playing, return ‘true`.
-
#item ⇒ Object
The currently playing track or episode.
-
#progress_ms ⇒ Integer
Progress into the currently playing track or episode.
-
#repeat_state ⇒ String
off, track, context.
-
#shuffle_state ⇒ TrueClass | FalseClass
If shuffle is on or off.
-
#timestamp ⇒ Integer
Unix Millisecond Timestamp when data was fetched.
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(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
constructor
A new instance of CurrentlyPlayingContextObject.
Methods inherited from BaseModel
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, = SKIP, progress_ms = SKIP, = SKIP, item = SKIP, = 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 = unless == SKIP @progress_ms = progress_ms unless progress_ms == SKIP @is_playing = unless == SKIP @item = item unless item == SKIP @currently_playing_type = unless == SKIP @actions = actions unless actions == SKIP end |
Instance Attribute Details
#actions ⇒ DisallowsObject
Allows to update the user interface based on which playback actions are available within the current context.
52 53 54 |
# File 'lib/spotify_web_api/models/currently_playing_context_object.rb', line 52 def actions @actions end |
#context ⇒ ContextObject
A Context Object. Can be ‘null`.
26 27 28 |
# File 'lib/spotify_web_api/models/currently_playing_context_object.rb', line 26 def context @context end |
#currently_playing_type ⇒ String
The object type of the currently playing item. Can be one of ‘track`, `episode`, `ad` or `unknown`.
47 48 49 |
# File 'lib/spotify_web_api/models/currently_playing_context_object.rb', line 47 def @currently_playing_type end |
#device ⇒ DeviceObject
The device that is currently active.
14 15 16 |
# File 'lib/spotify_web_api/models/currently_playing_context_object.rb', line 14 def device @device end |
#is_playing ⇒ TrueClass | FalseClass
If something is currently playing, return ‘true`.
38 39 40 |
# File 'lib/spotify_web_api/models/currently_playing_context_object.rb', line 38 def @is_playing end |
#item ⇒ Object
The currently playing track or episode. Can be ‘null`.
42 43 44 |
# File 'lib/spotify_web_api/models/currently_playing_context_object.rb', line 42 def item @item end |
#progress_ms ⇒ Integer
Progress into the currently playing track or episode. Can be ‘null`.
34 35 36 |
# File 'lib/spotify_web_api/models/currently_playing_context_object.rb', line 34 def progress_ms @progress_ms end |
#repeat_state ⇒ String
off, track, context
18 19 20 |
# File 'lib/spotify_web_api/models/currently_playing_context_object.rb', line 18 def repeat_state @repeat_state end |
#shuffle_state ⇒ TrueClass | FalseClass
If shuffle is on or off.
22 23 24 |
# File 'lib/spotify_web_api/models/currently_playing_context_object.rb', line 22 def shuffle_state @shuffle_state end |
#timestamp ⇒ Integer
Unix Millisecond Timestamp when data was fetched.
30 31 32 |
# File 'lib/spotify_web_api/models/currently_playing_context_object.rb', line 30 def @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'] = hash.key?('timestamp') ? hash['timestamp'] : SKIP progress_ms = hash.key?('progress_ms') ? hash['progress_ms'] : SKIP = hash.key?('is_playing') ? hash['is_playing'] : SKIP item = hash.key?('item') ? hash['item'] : SKIP = 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, , progress_ms, , item, , actions) end |
.names ⇒ Object
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 |
.nullables ⇒ Object
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 |
.optionals ⇒ Object
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 |