class RubyDeezer::Track

Attributes

album[RW]
artist[RW]
duration[RW]
id[RW]
name[RW]
rank[RW]
url[RW]

Public Class Methods

find(id) click to toggle source
# File lib/ruby_deezer/track.rb, line 11
def self.find(id)
  response = get("/lookup/track/", {:query => {:id => id, :output => 'json'}})
  artist = response ? Track.init_from_hash(response['track']) : nil
end
init_from_hash(hash) click to toggle source
# File lib/ruby_deezer/track.rb, line 32
def self.init_from_hash(hash)
  return nil unless hash.is_a?(Hash)
  Track.new.tap do |track|
    track.id = hash["id"].to_i
    track.name = hash["name"]
    track.url = hash["url"]
    track.duration = hash["duration"].to_i
    track.rank = hash["rank"].to_i
    if hash["artist"]
      track.artist = Artist.init_from_hash(hash["artist"])
    end
    if hash["album"]
      track.album = Album.init_from_hash(hash["album"])
    end
  end
end