class Spotify::API::Artist

Constants

ARTISTS_URL

API endpoint for artists.

Public Class Methods

albums(args = {}) click to toggle source

Get an artist's albums.

@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 [Paging] an array containing the extracted artist's albums.

# File lib/spotify/api/artist.rb, line 107
def self.albums(args = {})
  args[:album_type] = Array(args[:album_type]).join(',')

  args           = args.slice(:id, :album_type, :market, :limit, :offset)
  service_params = args.slice(:timeout, :retries)

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

Gets an artist.

@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::Artist] the extracted artist.

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

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

Gets several artists.

@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::Artist>] an array containing

the extracted artists.
# File lib/spotify/api/artist.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)

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

Get an artist's top 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 artist's top tracks.
# File lib/spotify/api/artist.rb, line 74
def self.top_tracks(args = {})
  args           = args.slice(:id, :country)
  service_params = args.slice(:timeout, :retries)

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

Public Instance Methods

albums(args = {}) click to toggle source

Get an artist's albums.

@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 [Paging] an array containing the extracted artist's

related artists.
# File lib/spotify/api/artist.rb, line 232
def albums(args = {})
  url    = ARTISTS_URL + '/' + args[:id].to_s + '/albums'
  params = args.slice(:album_type, :market, :limit, :offset)

  get(url, params)

  define_response do
    klass = Spotify::Models::Simplified::Album

    Spotify::Models::Paging.new(response, klass)
  end
end
search_by_id(args = {}) click to toggle source

Gets an artist.

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

@return [Full::Artist] the extracted artist.

# File lib/spotify/api/artist.rb, line 148
def search_by_id(args = {})
  url = ARTISTS_URL + '/' + args[:id].to_s

  get(url)

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

Gets several artists.

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

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

the extracted artists.
# File lib/spotify/api/artist.rb, line 167
def search_by_ids(args = {})
  get(ARTISTS_URL, args)

  define_response do
    response["artists"].map do |artist|
      Spotify::Models::Full::Artist.new(artist)
    end
  end
end
top_tracks(args = {}) click to toggle source

Get an artist's top tracks.

@param [Hash] args the search arguments. @option [String] :id the artist id. @option [String] :country the request country.

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

the extracted artist's top tracks.
# File lib/spotify/api/artist.rb, line 187
def top_tracks(args = {})
  url    = ARTISTS_URL + '/' + args[:id].to_s + '/top-tracks'
  params = args.slice(:country)

  get(url, params)

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