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.
-
#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) ⇒ 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.
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/rspotify/track.rb', line 59 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'] @album = if ['album'] Album.new ['album'] end @artists = if ['artists'] ['artists'].map { |a| Artist.new a } 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
16 17 18 |
# File 'lib/rspotify/track.rb', line 16 def album @album end |
#artists ⇒ Array<Artist>
The artists who performed the track
16 17 18 |
# File 'lib/rspotify/track.rb', line 16 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
16 17 18 |
# File 'lib/rspotify/track.rb', line 16 def available_markets @available_markets end |
#context_type ⇒ String
The context the track was played from. Only present when pulled from /recently-played
16 17 18 |
# File 'lib/rspotify/track.rb', line 16 def context_type @context_type end |
#disc_number ⇒ Integer
The disc number. Usually 1 unless the album consists of more than one disc
16 17 18 |
# File 'lib/rspotify/track.rb', line 16 def disc_number @disc_number end |
#duration_ms ⇒ Integer
The track length in milliseconds
16 17 18 |
# File 'lib/rspotify/track.rb', line 16 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
16 17 18 |
# File 'lib/rspotify/track.rb', line 16 def explicit @explicit end |
#external_ids ⇒ Hash
Known external IDs for the track
16 17 18 |
# File 'lib/rspotify/track.rb', line 16 def external_ids @external_ids end |
#name ⇒ String
The name of the track
16 17 18 |
# File 'lib/rspotify/track.rb', line 16 def name @name end |
#played_at ⇒ String
The date and time the track was played. Only present when pulled from /recently-played
16 17 18 |
# File 'lib/rspotify/track.rb', line 16 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
16 17 18 |
# File 'lib/rspotify/track.rb', line 16 def popularity @popularity end |
#preview_url ⇒ String
A link to a 30 second preview (MP3 format) of the track
16 17 18 |
# File 'lib/rspotify/track.rb', line 16 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
16 17 18 |
# File 'lib/rspotify/track.rb', line 16 def track_number @track_number end |
Class Method Details
.find(ids) ⇒ Track+
Returns Track object(s) with id(s) provided
32 33 34 |
# File 'lib/rspotify/track.rb', line 32 def self.find(ids) super(ids, 'track') 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
50 51 52 |
# File 'lib/rspotify/track.rb', line 50 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
55 56 57 |
# File 'lib/rspotify/track.rb', line 55 def audio_features RSpotify::AudioFeatures.find(@id) end |