class RubyFm::Track

Attributes

artist[R]
duration[R]
image[R]
listeners[R]
mbid[R]
name[R]
rank[R]
streamable[R]
url[R]

Public Class Methods

new(attributes) click to toggle source
# File lib/ruby_fm/track.rb, line 7
def initialize(attributes)
  @name = attributes['name']
  @duration = attributes['duration']
  @mbid = attributes['mbid']
  @url = attributes['url']
  @streamable = attributes['streamable']
  @artist = attributes['artist']['name'].nil? ? attributes['artist'] : attributes['artist']['name']
  @rank = attributes['@attr']['rank'] unless attributes['@attr'].nil?
  @listeners = attributes['listeners']
  if attributes['image']
    @images = attributes['image'].map do |image|
      image['#text']
    end
  end
end

Protected Class Methods

connection() click to toggle source
# File lib/ruby_fm/track.rb, line 43
def connection
  conn ||= Faraday.new(:url => 'http://ws.audioscrobbler.com') do |faraday|
    faraday.request  :url_encoded             # form-encode POST params
    faraday.adapter  Faraday.default_adapter  # make requests with Net::HTTP
  end
end