class MusicGraph::Artist
Constants
- API_URL
Attributes
artist_ref_id[R]
country_of_origin[R]
decade[R]
entity_type[R]
gender[R]
id[R]
main_genre[R]
name[R]
rhapsody_id[R]
seven_digital_id[R]
sort_name[R]
vevo_id[R]
Public Class Methods
find(id, filters = nil)
click to toggle source
# File lib/musicgraph/artist.rb, line 44 def self.find(id, filters = nil) request = "#{API_URL}#{id}?#{MusicGraph.key_param}" request += "&fields=#{filters.join(",")}" if filters response = Faraday.get(request) attributes = JSON.parse(response.body) new(attributes["data"]) end
new(attributes)
click to toggle source
# File lib/musicgraph/artist.rb, line 7 def initialize(attributes) @seven_digital_id = attributes["7digital_id"] @main_genre = attributes["main_genre"] @country_of_origin = attributes["country_of_origin"] @entity_type = attributes["entity_type"] @artist_ref_id = attributes["artist_ref_id"] @vevo_id = attributes["vevo_id"] @sort_name = attributes["sort_name"] @gender = attributes["gender"] @rhapsody_id = attributes["rhapsody_id"] @id = attributes["id"] @decade = attributes["decade"] @name = attributes["name"] end
search(params)
click to toggle source
# File lib/musicgraph/artist.rb, line 22 def self.search(params) if params.is_a? String response = Faraday.get("#{API_URL}search?#{MusicGraph.key_param}&name=#{params}") elsif params.is_a? Hash encoded_params = URI.encode_www_form(params) response = Faraday.get("#{API_URL}search?#{MusicGraph.key_param}&#{encoded_params}") end artists = JSON.parse(response.body)["data"] artists.map { |attributes| new(attributes) } end
suggest(params)
click to toggle source
# File lib/musicgraph/artist.rb, line 33 def self.suggest(params) if params.is_a? String response = Faraday.get("#{API_URL}suggest?#{MusicGraph.key_param}&prefix=#{params}") elsif params.is_a? Hash encoded_params = URI.encode_www_form(params) response = Faraday.get("#{API_URL}suggest?#{MusicGraph.key_param}&#{encoded_params}") end artists = JSON.parse(response.body)["data"] artists.map { |attributes| new(attributes) } end
Public Instance Methods
albums()
click to toggle source
# File lib/musicgraph/artist.rb, line 68 def albums response = Faraday.get("#{API_URL}#{id}/albums?#{MusicGraph.key_param}") albums = JSON.parse(response.body)["data"] albums.map { |attributes| Album.new(attributes) } end
edges()
click to toggle source
# File lib/musicgraph/artist.rb, line 52 def edges response = Faraday.get("#{API_URL}#{id}/edges?#{MusicGraph.key_param}") JSON.parse(response.body)["data"] end
metadata()
click to toggle source
# File lib/musicgraph/artist.rb, line 57 def metadata response = Faraday.get("#{API_URL}#{id}?#{MusicGraph.key_param}") JSON.parse(response.body)["data"] end
similar()
click to toggle source
# File lib/musicgraph/artist.rb, line 62 def similar response = Faraday.get("#{API_URL}#{id}/similar?#{MusicGraph.key_param}") artists = JSON.parse(response.body)["data"] artists.map { |attributes| Artist.new(attributes) } end
tracks()
click to toggle source
# File lib/musicgraph/artist.rb, line 74 def tracks response = Faraday.get("#{API_URL}#{id}/albums?#{MusicGraph.key_param}") albums = JSON.parse(response.body)["data"] albums.map { |attributes| Track.new(attributes) } end