Class: SpotifyWebApi::TrackObject
- Defined in:
- lib/spotify_web_api/models/track_object.rb
Overview
TrackObject Model.
Instance Attribute Summary collapse
-
#album ⇒ SimplifiedAlbumObject
The album on which the track appears.
-
#artists ⇒ Array[ArtistObject]
The artists who performed the track.
-
#available_markets ⇒ Array[String]
A list of the countries in which the track can be played, identified by their [ISO 3166-1 alpha-2](en.wikipedia.org/wiki/ISO_3166-1_alpha-2) code.
-
#disc_number ⇒ Integer
The disc number (usually ‘1` unless the album consists of more than one disc).
-
#duration_ms ⇒ Integer
The track length in milliseconds.
-
#explicit ⇒ TrueClass | FalseClass
Whether or not the track has explicit lyrics ( ‘true` = yes it does; `false` = no it does not OR unknown).
-
#external_ids ⇒ ExternalIdObject
Known external IDs for the track.
-
#external_urls ⇒ ExternalUrlObject
Known external URLs for this track.
-
#href ⇒ String
A link to the Web API endpoint providing full details of the track.
-
#id ⇒ String
The [Spotify ID](/documentation/web-api/concepts/spotify-uris-ids) for the track.
-
#is_local ⇒ TrueClass | FalseClass
Whether or not the track is from a local file.
-
#is_playable ⇒ TrueClass | FalseClass
Part of the response when [Track Relinking](/documentation/web-api/concepts/track-relinking) is applied.
-
#linked_from ⇒ LinkedTrackObject
Part of the response when [Track Relinking](/documentation/web-api/concepts/track-relinking) is applied, and the requested track has been replaced with different track.
-
#name ⇒ String
The name of the track.
-
#popularity ⇒ Integer
The popularity of the track.
-
#preview_url ⇒ String
A link to a 30 second preview (MP3 format) of the track.
-
#restrictions ⇒ TrackRestrictionObject
Included in the response when a content restriction is applied.
-
#track_number ⇒ Integer
The number of the track.
-
#type ⇒ Type3Enum
The object type: “track”.
-
#uri ⇒ String
The [Spotify URI](/documentation/web-api/concepts/spotify-uris-ids) for the track.
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(album = SKIP, artists = SKIP, available_markets = SKIP, disc_number = SKIP, duration_ms = SKIP, explicit = SKIP, external_ids = SKIP, external_urls = SKIP, href = SKIP, id = SKIP, is_playable = SKIP, linked_from = SKIP, restrictions = SKIP, name = SKIP, popularity = SKIP, preview_url = SKIP, track_number = SKIP, type = SKIP, uri = SKIP, is_local = SKIP) ⇒ TrackObject
constructor
A new instance of TrackObject.
Methods inherited from BaseModel
Constructor Details
#initialize(album = SKIP, artists = SKIP, available_markets = SKIP, disc_number = SKIP, duration_ms = SKIP, explicit = SKIP, external_ids = SKIP, external_urls = SKIP, href = SKIP, id = SKIP, is_playable = SKIP, linked_from = SKIP, restrictions = SKIP, name = SKIP, popularity = SKIP, preview_url = SKIP, track_number = SKIP, type = SKIP, uri = SKIP, is_local = SKIP) ⇒ TrackObject
Returns a new instance of TrackObject.
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/spotify_web_api/models/track_object.rb', line 176 def initialize(album = SKIP, artists = SKIP, available_markets = SKIP, disc_number = SKIP, duration_ms = SKIP, explicit = SKIP, external_ids = SKIP, external_urls = SKIP, href = SKIP, id = SKIP, is_playable = SKIP, linked_from = SKIP, restrictions = SKIP, name = SKIP, popularity = SKIP, preview_url = SKIP, track_number = SKIP, type = SKIP, uri = SKIP, is_local = SKIP) @album = album unless album == SKIP @artists = artists unless artists == SKIP @available_markets = available_markets unless available_markets == SKIP @disc_number = disc_number unless disc_number == SKIP @duration_ms = duration_ms unless duration_ms == SKIP @explicit = explicit unless explicit == SKIP @external_ids = external_ids unless external_ids == SKIP @external_urls = external_urls unless external_urls == SKIP @href = href unless href == SKIP @id = id unless id == SKIP @is_playable = is_playable unless is_playable == SKIP @linked_from = linked_from unless linked_from == SKIP @restrictions = restrictions unless restrictions == SKIP @name = name unless name == SKIP @popularity = popularity unless popularity == SKIP @preview_url = preview_url unless preview_url == SKIP @track_number = track_number unless track_number == SKIP @type = type unless type == SKIP @uri = uri unless uri == SKIP @is_local = is_local unless is_local == SKIP end |
Instance Attribute Details
#album ⇒ SimplifiedAlbumObject
The album on which the track appears. The album object includes a link in ‘href` to full information about the album.
15 16 17 |
# File 'lib/spotify_web_api/models/track_object.rb', line 15 def album @album end |
#artists ⇒ Array[ArtistObject]
The artists who performed the track. Each artist object includes a link in ‘href` to more detailed information about the artist.
20 21 22 |
# File 'lib/spotify_web_api/models/track_object.rb', line 20 def artists @artists end |
#available_markets ⇒ Array[String]
A list of the countries in which the track can be played, identified by their [ISO 3166-1 alpha-2](en.wikipedia.org/wiki/ISO_3166-1_alpha-2) code.
26 27 28 |
# File 'lib/spotify_web_api/models/track_object.rb', line 26 def available_markets @available_markets end |
#disc_number ⇒ Integer
The disc number (usually ‘1` unless the album consists of more than one disc).
31 32 33 |
# File 'lib/spotify_web_api/models/track_object.rb', line 31 def disc_number @disc_number end |
#duration_ms ⇒ Integer
The track length in milliseconds.
35 36 37 |
# File 'lib/spotify_web_api/models/track_object.rb', line 35 def duration_ms @duration_ms end |
#explicit ⇒ TrueClass | FalseClass
Whether or not the track has explicit lyrics ( ‘true` = yes it does; `false` = no it does not OR unknown).
40 41 42 |
# File 'lib/spotify_web_api/models/track_object.rb', line 40 def explicit @explicit end |
#external_ids ⇒ ExternalIdObject
Known external IDs for the track.
44 45 46 |
# File 'lib/spotify_web_api/models/track_object.rb', line 44 def external_ids @external_ids end |
#external_urls ⇒ ExternalUrlObject
Known external URLs for this track.
48 49 50 |
# File 'lib/spotify_web_api/models/track_object.rb', line 48 def external_urls @external_urls end |
#href ⇒ String
A link to the Web API endpoint providing full details of the track.
52 53 54 |
# File 'lib/spotify_web_api/models/track_object.rb', line 52 def href @href end |
#id ⇒ String
The [Spotify ID](/documentation/web-api/concepts/spotify-uris-ids) for the track.
57 58 59 |
# File 'lib/spotify_web_api/models/track_object.rb', line 57 def id @id end |
#is_local ⇒ TrueClass | FalseClass
Whether or not the track is from a local file.
115 116 117 |
# File 'lib/spotify_web_api/models/track_object.rb', line 115 def is_local @is_local end |
#is_playable ⇒ TrueClass | FalseClass
Part of the response when [Track Relinking](/documentation/web-api/concepts/track-relinking) is applied. If ‘true`, the track is playable in the given market. Otherwise `false`.
63 64 65 |
# File 'lib/spotify_web_api/models/track_object.rb', line 63 def is_playable @is_playable end |
#linked_from ⇒ LinkedTrackObject
Part of the response when [Track Relinking](/documentation/web-api/concepts/track-relinking) is applied, and the requested track has been replaced with different track. The track in the ‘linked_from` object contains information about the originally requested track.
71 72 73 |
# File 'lib/spotify_web_api/models/track_object.rb', line 71 def linked_from @linked_from end |
#name ⇒ String
The name of the track.
79 80 81 |
# File 'lib/spotify_web_api/models/track_object.rb', line 79 def name @name end |
#popularity ⇒ Integer
The popularity of the track. The value will be between 0 and 100, with 100 being the most popular.<br/>The popularity of a track is a value between 0 and 100, with 100 being the most popular. The popularity is calculated by algorithm and is based, in the most part, on the total number of plays the track has had and how recent those plays are.<br/>Generally speaking, songs that are being played a lot now will have a higher popularity than songs that were played a lot in the past. Duplicate tracks (e.g. the same track from a single and an album) are rated independently. Artist and album popularity is derived mathematically from track popularity. _Note: the popularity value may lag actual popularity by a few days: the value is not updated in real time._
93 94 95 |
# File 'lib/spotify_web_api/models/track_object.rb', line 93 def popularity @popularity end |
#preview_url ⇒ String
A link to a 30 second preview (MP3 format) of the track. Can be ‘null`
97 98 99 |
# File 'lib/spotify_web_api/models/track_object.rb', line 97 def preview_url @preview_url end |
#restrictions ⇒ TrackRestrictionObject
Included in the response when a content restriction is applied.
75 76 77 |
# File 'lib/spotify_web_api/models/track_object.rb', line 75 def restrictions @restrictions end |
#track_number ⇒ Integer
The number of the track. If an album has several discs, the track number is the number on the specified disc.
102 103 104 |
# File 'lib/spotify_web_api/models/track_object.rb', line 102 def track_number @track_number end |
#type ⇒ Type3Enum
The object type: “track”.
106 107 108 |
# File 'lib/spotify_web_api/models/track_object.rb', line 106 def type @type end |
#uri ⇒ String
The [Spotify URI](/documentation/web-api/concepts/spotify-uris-ids) for the track.
111 112 113 |
# File 'lib/spotify_web_api/models/track_object.rb', line 111 def uri @uri end |
Class Method Details
.from_hash(hash) ⇒ Object
Creates an instance of the object from a hash.
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 |
# File 'lib/spotify_web_api/models/track_object.rb', line 206 def self.from_hash(hash) return nil unless hash # Extract variables from the hash. album = SimplifiedAlbumObject.from_hash(hash['album']) if hash['album'] # Parameter is an array, so we need to iterate through it artists = nil unless hash['artists'].nil? artists = [] hash['artists'].each do |structure| artists << (ArtistObject.from_hash(structure) if structure) end end artists = SKIP unless hash.key?('artists') available_markets = hash.key?('available_markets') ? hash['available_markets'] : SKIP disc_number = hash.key?('disc_number') ? hash['disc_number'] : SKIP duration_ms = hash.key?('duration_ms') ? hash['duration_ms'] : SKIP explicit = hash.key?('explicit') ? hash['explicit'] : SKIP external_ids = ExternalIdObject.from_hash(hash['external_ids']) if hash['external_ids'] external_urls = ExternalUrlObject.from_hash(hash['external_urls']) if hash['external_urls'] href = hash.key?('href') ? hash['href'] : SKIP id = hash.key?('id') ? hash['id'] : SKIP is_playable = hash.key?('is_playable') ? hash['is_playable'] : SKIP linked_from = LinkedTrackObject.from_hash(hash['linked_from']) if hash['linked_from'] restrictions = TrackRestrictionObject.from_hash(hash['restrictions']) if hash['restrictions'] name = hash.key?('name') ? hash['name'] : SKIP popularity = hash.key?('popularity') ? hash['popularity'] : SKIP preview_url = hash.key?('preview_url') ? hash['preview_url'] : SKIP track_number = hash.key?('track_number') ? hash['track_number'] : SKIP type = hash.key?('type') ? hash['type'] : SKIP uri = hash.key?('uri') ? hash['uri'] : SKIP is_local = hash.key?('is_local') ? hash['is_local'] : SKIP # Create object from extracted values. TrackObject.new(album, artists, available_markets, disc_number, duration_ms, explicit, external_ids, external_urls, href, id, is_playable, linked_from, restrictions, name, popularity, preview_url, track_number, type, uri, is_local) end |
.names ⇒ Object
A mapping from model property names to API property names.
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/spotify_web_api/models/track_object.rb', line 118 def self.names @_hash = {} if @_hash.nil? @_hash['album'] = 'album' @_hash['artists'] = 'artists' @_hash['available_markets'] = 'available_markets' @_hash['disc_number'] = 'disc_number' @_hash['duration_ms'] = 'duration_ms' @_hash['explicit'] = 'explicit' @_hash['external_ids'] = 'external_ids' @_hash['external_urls'] = 'external_urls' @_hash['href'] = 'href' @_hash['id'] = 'id' @_hash['is_playable'] = 'is_playable' @_hash['linked_from'] = 'linked_from' @_hash['restrictions'] = 'restrictions' @_hash['name'] = 'name' @_hash['popularity'] = 'popularity' @_hash['preview_url'] = 'preview_url' @_hash['track_number'] = 'track_number' @_hash['type'] = 'type' @_hash['uri'] = 'uri' @_hash['is_local'] = 'is_local' @_hash end |
.nullables ⇒ Object
An array for nullable fields
170 171 172 173 174 |
# File 'lib/spotify_web_api/models/track_object.rb', line 170 def self.nullables %w[ preview_url ] end |
.optionals ⇒ Object
An array for optional fields
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/spotify_web_api/models/track_object.rb', line 144 def self.optionals %w[ album artists available_markets disc_number duration_ms explicit external_ids external_urls href id is_playable linked_from restrictions name popularity preview_url track_number type uri is_local ] end |