class RubyDeezer::Artist

Attributes

albums[RW]
discography[RW]
id[RW]
image[RW]
name[RW]
similar_artists[RW]
url[RW]

Public Class Methods

find(id, options = []) click to toggle source
# File lib/ruby_deezer/artist.rb, line 13
def self.find(id, options = [])
  response = get("/lookup/artist/", {:query => {:id => id, :output => 'json', :options => options.join(",")}})
  artist = response ? Artist.init_from_hash(response['artist']) : nil
end
init_from_hash(hash) click to toggle source
# File lib/ruby_deezer/artist.rb, line 34
def self.init_from_hash(hash)
  return nil unless hash.is_a?(Hash)
  similar_artists = hash["similar_artists"] || {}
  similar_artists_array = similar_artists["artist"] || []
  discography = hash["discography"] || {}
  discography_array = discography["album"] || []
  Artist.new.tap do |artist|
    artist.id = hash["id"].to_i
    artist.name = hash["name"]
    artist.url = hash["url"]
    artist.image = hash["image"]
    artist.similar_artists = similar_artists_array.inject([]) {|arr, hash| arr << init_from_hash(hash); arr}
    artist.discography = discography_array.inject([]) {|arr, hash| arr << Album.init_from_hash(hash); arr}
  end
end