Class: SpotifyWebApi::PlaylistTrackObject

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

Overview

PlaylistTrackObject Model.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#to_hash, #to_json

Constructor Details

#initialize(added_at = SKIP, added_by = SKIP, is_local = SKIP, track = SKIP) ⇒ PlaylistTrackObject

Returns a new instance of PlaylistTrackObject.



57
58
59
60
61
62
63
# File 'lib/spotify_web_api/models/playlist_track_object.rb', line 57

def initialize(added_at = SKIP, added_by = SKIP, is_local = SKIP,
               track = SKIP)
  @added_at = added_at unless added_at == SKIP
  @added_by = added_by unless added_by == SKIP
  @is_local = is_local unless is_local == SKIP
  @track = track unless track == SKIP
end

Instance Attribute Details

#added_atDateTime

The date and time the track or episode was added. _Note: some very old playlists may return ‘null` in this field._

Returns:

  • (DateTime)


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

def added_at
  @added_at
end

#added_byPlaylistUserObject

The Spotify user who added the track or episode. _Note: some very old playlists may return ‘null` in this field._

Returns:



21
22
23
# File 'lib/spotify_web_api/models/playlist_track_object.rb', line 21

def added_by
  @added_by
end

#is_localTrueClass | FalseClass

Whether this track or episode is a [local file](/documentation/web-api/concepts/playlists/#local-files) or not.

Returns:

  • (TrueClass | FalseClass)


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

def is_local
  @is_local
end

#trackObject

Information about the track or episode.

Returns:

  • (Object)


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

def track
  @track
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/spotify_web_api/models/playlist_track_object.rb', line 66

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  added_at = if hash.key?('added_at')
               (DateTimeHelper.from_rfc3339(hash['added_at']) if hash['added_at'])
             else
               SKIP
             end
  added_by = PlaylistUserObject.from_hash(hash['added_by']) if hash['added_by']
  is_local = hash.key?('is_local') ? hash['is_local'] : SKIP
  track = hash.key?('track') ? hash['track'] : SKIP

  # Create object from extracted values.
  PlaylistTrackObject.new(added_at,
                          added_by,
                          is_local,
                          track)
end

.namesObject

A mapping from model property names to API property names.



33
34
35
36
37
38
39
40
# File 'lib/spotify_web_api/models/playlist_track_object.rb', line 33

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['added_at'] = 'added_at'
  @_hash['added_by'] = 'added_by'
  @_hash['is_local'] = 'is_local'
  @_hash['track'] = 'track'
  @_hash
end

.nullablesObject

An array for nullable fields



53
54
55
# File 'lib/spotify_web_api/models/playlist_track_object.rb', line 53

def self.nullables
  []
end

.optionalsObject

An array for optional fields



43
44
45
46
47
48
49
50
# File 'lib/spotify_web_api/models/playlist_track_object.rb', line 43

def self.optionals
  %w[
    added_at
    added_by
    is_local
    track
  ]
end

Instance Method Details

#to_custom_added_atObject



86
87
88
# File 'lib/spotify_web_api/models/playlist_track_object.rb', line 86

def to_custom_added_at
  DateTimeHelper.to_rfc3339(added_at)
end