Class: SpotifyWebApi::PlayHistoryObject
- Inherits:
-
BaseModel
- Object
- CoreLibrary::BaseModel
- BaseModel
- SpotifyWebApi::PlayHistoryObject
- Defined in:
- lib/spotify_web_api/models/play_history_object.rb
Overview
PlayHistoryObject Model.
Instance Attribute Summary collapse
-
#context ⇒ ContextObject
The context the track was played from.
-
#played_at ⇒ DateTime
The date and time the track was played.
-
#track ⇒ TrackObject
The track the user listened to.
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(track = SKIP, played_at = SKIP, context = SKIP) ⇒ PlayHistoryObject
constructor
A new instance of PlayHistoryObject.
- #to_custom_played_at ⇒ Object
Methods inherited from BaseModel
Constructor Details
#initialize(track = SKIP, played_at = SKIP, context = SKIP) ⇒ PlayHistoryObject
Returns a new instance of PlayHistoryObject.
48 49 50 51 52 |
# File 'lib/spotify_web_api/models/play_history_object.rb', line 48 def initialize(track = SKIP, played_at = SKIP, context = SKIP) @track = track unless track == SKIP @played_at = played_at unless played_at == SKIP @context = context unless context == SKIP end |
Instance Attribute Details
#context ⇒ ContextObject
The context the track was played from.
23 24 25 |
# File 'lib/spotify_web_api/models/play_history_object.rb', line 23 def context @context end |
#played_at ⇒ DateTime
The date and time the track was played.
19 20 21 |
# File 'lib/spotify_web_api/models/play_history_object.rb', line 19 def played_at @played_at end |
#track ⇒ TrackObject
The track the user listened to.
15 16 17 |
# File 'lib/spotify_web_api/models/play_history_object.rb', line 15 def track @track end |
Class Method Details
.from_hash(hash) ⇒ Object
Creates an instance of the object from a hash.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/spotify_web_api/models/play_history_object.rb', line 55 def self.from_hash(hash) return nil unless hash # Extract variables from the hash. track = TrackObject.from_hash(hash['track']) if hash['track'] played_at = if hash.key?('played_at') (DateTimeHelper.from_rfc3339(hash['played_at']) if hash['played_at']) else SKIP end context = ContextObject.from_hash(hash['context']) if hash['context'] # Create object from extracted values. PlayHistoryObject.new(track, played_at, context) end |
.names ⇒ Object
A mapping from model property names to API property names.
26 27 28 29 30 31 32 |
# File 'lib/spotify_web_api/models/play_history_object.rb', line 26 def self.names @_hash = {} if @_hash.nil? @_hash['track'] = 'track' @_hash['played_at'] = 'played_at' @_hash['context'] = 'context' @_hash end |
.nullables ⇒ Object
An array for nullable fields
44 45 46 |
# File 'lib/spotify_web_api/models/play_history_object.rb', line 44 def self.nullables [] end |
.optionals ⇒ Object
An array for optional fields
35 36 37 38 39 40 41 |
# File 'lib/spotify_web_api/models/play_history_object.rb', line 35 def self.optionals %w[ track played_at context ] end |
Instance Method Details
#to_custom_played_at ⇒ Object
73 74 75 |
# File 'lib/spotify_web_api/models/play_history_object.rb', line 73 def to_custom_played_at DateTimeHelper.to_rfc3339(played_at) end |