Class: RSpotify::Track
Instance Attribute Summary collapse
-
#album ⇒ Album
The album on which the track appears.
-
#artists ⇒ Array<Artist>
The artists who performed the track.
-
#available_markets ⇒ Array<String>
The markets in which the track can be played.
-
#context_type ⇒ String
The context the track was played from.
-
#disc_number ⇒ Integer
The disc number.
-
#duration_ms ⇒ Integer
The track length in milliseconds.
-
#explicit ⇒ Boolean
Whether or not the track has explicit lyrics.
-
#external_ids ⇒ Hash
Known external IDs for the track.
-
#is_playable ⇒ Boolean
Whether or not the track is playable in the given market.
-
#linked_from ⇒ TrackLink
Details of the requested track.
-
#name ⇒ String
The name of the track.
-
#played_at ⇒ String
The date and time the track was played.
-
#popularity ⇒ Integer
The popularity of the track.
-
#preview_url ⇒ String
A link to a 30 second preview (MP3 format) of the track.
-
#track_number ⇒ Integer
The number of the track.
Attributes inherited from Base
#external_urls, #href, #id, #type, #uri
Class Method Summary collapse
-
.find(ids, market: nil) ⇒ Track+
Returns Track object(s) with id(s) provided.
-
.search(query, limit: 20, offset: 0, market: nil) ⇒ Array<Track>
Returns array of Track objects matching the query, ordered by popularity.
Instance Method Summary collapse
-
#audio_features ⇒ Object
Retrieves the audio features for the track.
-
#initialize(options = {}) ⇒ Track
constructor
A new instance of Track.
Methods inherited from Base
#complete!, #embed, #method_missing, #respond_to?
Constructor Details
#initialize(options = {}) ⇒ Track
Returns a new instance of Track.
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/rspotify/track.rb', line 62 def initialize( = {}) @available_markets = ['available_markets'] @disc_number = ['disc_number'] @duration_ms = ['duration_ms'] @explicit = ['explicit'] @external_ids = ['external_ids'] @uri = ['uri'] @name = ['name'] @popularity = ['popularity'] @preview_url = ['preview_url'] @track_number = ['track_number'] @played_at = ['played_at'] @context_type = ['context_type'] @is_playable = ['is_playable'] @album = if ['album'] Album.new ['album'] end @artists = if ['artists'] ['artists'].map { |a| Artist.new a } end @linked_from = if ['linked_from'] TrackLink.new ['linked_from'] end super() end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class RSpotify::Base
Instance Attribute Details
#album ⇒ Album
The album on which the track appears
18 19 20 |
# File 'lib/rspotify/track.rb', line 18 def album @album end |
#artists ⇒ Array<Artist>
The artists who performed the track
18 19 20 |
# File 'lib/rspotify/track.rb', line 18 def artists @artists end |
#available_markets ⇒ Array<String>
The markets in which the track can be played. See ISO 3166-1 alpha-2 country codes
18 19 20 |
# File 'lib/rspotify/track.rb', line 18 def available_markets @available_markets end |
#context_type ⇒ String
The context the track was played from. Only present when pulled from /recently-played
18 19 20 |
# File 'lib/rspotify/track.rb', line 18 def context_type @context_type end |
#disc_number ⇒ Integer
The disc number. Usually 1 unless the album consists of more than one disc
18 19 20 |
# File 'lib/rspotify/track.rb', line 18 def disc_number @disc_number end |
#duration_ms ⇒ Integer
The track length in milliseconds
18 19 20 |
# File 'lib/rspotify/track.rb', line 18 def duration_ms @duration_ms end |
#explicit ⇒ Boolean
Whether or not the track has explicit lyrics. true = yes it does; false = no it does not OR unknown
18 19 20 |
# File 'lib/rspotify/track.rb', line 18 def explicit @explicit end |
#external_ids ⇒ Hash
Known external IDs for the track
18 19 20 |
# File 'lib/rspotify/track.rb', line 18 def external_ids @external_ids end |
#is_playable ⇒ Boolean
Whether or not the track is playable in the given market. Only present when track relinking is applied by specifying a market when looking up the track
18 19 20 |
# File 'lib/rspotify/track.rb', line 18 def is_playable @is_playable end |
#linked_from ⇒ TrackLink
Details of the requested track. Only present when track relinking is applied and the returned track is different to the one requested because the latter is not available in the given market
18 19 20 |
# File 'lib/rspotify/track.rb', line 18 def linked_from @linked_from end |
#name ⇒ String
The name of the track
18 19 20 |
# File 'lib/rspotify/track.rb', line 18 def name @name end |
#played_at ⇒ String
The date and time the track was played. Only present when pulled from /recently-played
18 19 20 |
# File 'lib/rspotify/track.rb', line 18 def played_at @played_at end |
#popularity ⇒ Integer
The popularity of the track. The value will be between 0 and 100, with 100 being the most popular
18 19 20 |
# File 'lib/rspotify/track.rb', line 18 def popularity @popularity end |
#preview_url ⇒ String
A link to a 30 second preview (MP3 format) of the track
18 19 20 |
# File 'lib/rspotify/track.rb', line 18 def preview_url @preview_url 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
18 19 20 |
# File 'lib/rspotify/track.rb', line 18 def track_number @track_number end |
Class Method Details
.find(ids, market: nil) ⇒ Track+
Returns Track object(s) with id(s) provided
35 36 37 |
# File 'lib/rspotify/track.rb', line 35 def self.find(ids, market: nil) super(ids, 'track', market: market) end |
.search(query, limit: 20, offset: 0, market: nil) ⇒ Array<Track>
Returns array of Track objects matching the query, ordered by popularity. It’s also possible to find the total number of search results for the query
53 54 55 |
# File 'lib/rspotify/track.rb', line 53 def self.search(query, limit: 20, offset: 0, market: nil) super(query, 'track', limit: limit, offset: offset, market: market) end |
Instance Method Details
#audio_features ⇒ Object
Retrieves the audio features for the track
58 59 60 |
# File 'lib/rspotify/track.rb', line 58 def audio_features RSpotify::AudioFeatures.find(@id) end |