class Spotify::API::Track

Constants

TRACKS_URL

API endpoint for tracks.

Public Class Methods

search_by_id(args = {}) click to toggle source

Gets a track.

@param [Hash] args the search arguments. @option [Fixnum] :timeout the max time a request can take. @option [Fixnum] :retries the number of retries if necessary.

@return [Full::Track] the extracted track.

# File lib/spotify/api/track.rb, line 38
def self.search_by_id(args = {})
  service_params = args.slice(:timeout, :retries)
  args           = args.slice(:id, :market)

  self.new(service_params).search_by_id(args)
end
search_by_ids(args = {}) click to toggle source

Gets several tracks.

@param [Hash] args the search arguments. @option [Fixnum] :timeout the max time a request can take. @option [Fixnum] :retries the number of retries if necessary.

@return [Array<Full::Track>] an array containing

the extracted tracks.
# File lib/spotify/api/track.rb, line 55
def self.search_by_ids(args = {})
  args[:ids] = Array(args[:ids]).join(',')

  service_params = args.slice(:timeout, :retries)
  args           = args.slice(:ids, :market)

  self.new(service_params).search_by_ids(args)
end

Public Instance Methods

search_by_id(args = {}) click to toggle source

Gets a track.

@param [Hash] args the search arguments. @option [String] :id the track id. @option [String] :market the market.

@return [Full::Track] the extracted track.

# File lib/spotify/api/track.rb, line 97
def search_by_id(args = {})
  get(TRACKS_URL + '/' + args[:id].to_s, args.slice(:market))

  define_response do
    Spotify::Models::Full::Track.new(response)
  end
end
search_by_ids(args = {}) click to toggle source

Gets several tracks.

@param [Hash] args the search arguments. @option [String] :ids the tracks ids between “,”. @option [String] :market the market.

@return [Array<Full::Track>] an array containing

the extracted tracks.
# File lib/spotify/api/track.rb, line 115
def search_by_ids(args = {})
  get(TRACKS_URL, args)

  define_response do
    response["tracks"].map do |track|
      Spotify::Models::Full::Track.new(track)
    end
  end
end