class RubyFm::Artist
Attributes
images[R]
listeners[R]
mbid[R]
name[R]
streamable[R]
url[R]
Public Class Methods
new(attributes)
click to toggle source
# File lib/ruby_fm/artist.rb, line 8 def initialize(attributes) @name = attributes['name'] @listeners = attributes['listeners'] @mbid = attributes['mbid'] @streamable = attributes['streamable'] @url = attributes['url'] @images = attributes['image'].map do |image| image['#text'] end end
search(phrase)
click to toggle source
# File lib/ruby_fm/artist.rb, line 20 def search(phrase) res = connection.get('/2.0/', { method: 'artist.search', artist: phrase, api_key: RubyFm.api_key, format: 'json' }) parsed_results = JSON.parse(res.body) if parsed_results['results'] && parsed_results['results']['artistmatches'] artist_results = [parsed_results['results']['artistmatches']['artist']].flatten artist_results.map do |artist_attributes| new(artist_attributes) end else [] end end
Protected Class Methods
connection()
click to toggle source
# File lib/ruby_fm/artist.rb, line 39 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