Class: SpotifyWebApi::CurrentlyPlayingObject

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

Overview

CurrentlyPlayingObject Model.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#to_hash, #to_json

Constructor Details

#initialize(context = SKIP, timestamp = SKIP, progress_ms = SKIP, is_playing = SKIP, item = SKIP, currently_playing_type = SKIP, actions = SKIP) ⇒ CurrentlyPlayingObject

Returns a new instance of CurrentlyPlayingObject.



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

def initialize(context = SKIP, timestamp = SKIP, progress_ms = SKIP,
               is_playing = SKIP, item = SKIP,
               currently_playing_type = SKIP, actions = 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:



40
41
42
# File 'lib/spotify_web_api/models/currently_playing_object.rb', line 40

def actions
  @actions
end

#contextContextObject

A Context Object. Can be null.

Returns:



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

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)


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

def currently_playing_type
  @currently_playing_type
end

#is_playingTrueClass | FalseClass

If something is currently playing, return true.

Returns:

  • (TrueClass | FalseClass)


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

def is_playing
  @is_playing
end

#itemObject

The currently playing track or episode. Can be null.

Returns:

  • (Object)


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

def item
  @item
end

#progress_msInteger

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

Returns:

  • (Integer)


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

def progress_ms
  @progress_ms
end

#timestampInteger

Unix Millisecond Timestamp when data was fetched

Returns:

  • (Integer)


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

def timestamp
  @timestamp
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/spotify_web_api/models/currently_playing_object.rb', line 86

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  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.
  CurrentlyPlayingObject.new(context,
                             timestamp,
                             progress_ms,
                             is_playing,
                             item,
                             currently_playing_type,
                             actions)
end

.namesObject

A mapping from model property names to API property names.



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/spotify_web_api/models/currently_playing_object.rb', line 43

def self.names
  @_hash = {} if @_hash.nil?
  @_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



69
70
71
# File 'lib/spotify_web_api/models/currently_playing_object.rb', line 69

def self.nullables
  []
end

.optionalsObject

An array for optional fields



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

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