Class: MusicGraph::Artist
- Inherits:
-
Object
- Object
- MusicGraph::Artist
- Defined in:
- lib/musicgraph/artist.rb
Constant Summary collapse
- API_URL =
"http://api.musicgraph.com/api/v2/artist/"
Instance Attribute Summary collapse
-
#artist_ref_id ⇒ Object
readonly
Returns the value of attribute artist_ref_id.
-
#country_of_origin ⇒ Object
readonly
Returns the value of attribute country_of_origin.
-
#decade ⇒ Object
readonly
Returns the value of attribute decade.
-
#entity_type ⇒ Object
readonly
Returns the value of attribute entity_type.
-
#gender ⇒ Object
readonly
Returns the value of attribute gender.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#main_genre ⇒ Object
readonly
Returns the value of attribute main_genre.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#rhapsody_id ⇒ Object
readonly
Returns the value of attribute rhapsody_id.
-
#seven_digital_id ⇒ Object
readonly
Returns the value of attribute seven_digital_id.
-
#sort_name ⇒ Object
readonly
Returns the value of attribute sort_name.
-
#vevo_id ⇒ Object
readonly
Returns the value of attribute vevo_id.
Class Method Summary collapse
Instance Method Summary collapse
- #albums ⇒ Object
- #edges ⇒ Object
-
#initialize(attributes) ⇒ Artist
constructor
A new instance of Artist.
- #metadata ⇒ Object
- #similar ⇒ Object
- #tracks ⇒ Object
Constructor Details
#initialize(attributes) ⇒ Artist
Returns a new instance of Artist.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# 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 |
Instance Attribute Details
#artist_ref_id ⇒ Object (readonly)
Returns the value of attribute artist_ref_id.
3 4 5 |
# File 'lib/musicgraph/artist.rb', line 3 def artist_ref_id @artist_ref_id end |
#country_of_origin ⇒ Object (readonly)
Returns the value of attribute country_of_origin.
3 4 5 |
# File 'lib/musicgraph/artist.rb', line 3 def country_of_origin @country_of_origin end |
#decade ⇒ Object (readonly)
Returns the value of attribute decade.
3 4 5 |
# File 'lib/musicgraph/artist.rb', line 3 def decade @decade end |
#entity_type ⇒ Object (readonly)
Returns the value of attribute entity_type.
3 4 5 |
# File 'lib/musicgraph/artist.rb', line 3 def entity_type @entity_type end |
#gender ⇒ Object (readonly)
Returns the value of attribute gender.
3 4 5 |
# File 'lib/musicgraph/artist.rb', line 3 def gender @gender end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
3 4 5 |
# File 'lib/musicgraph/artist.rb', line 3 def id @id end |
#main_genre ⇒ Object (readonly)
Returns the value of attribute main_genre.
3 4 5 |
# File 'lib/musicgraph/artist.rb', line 3 def main_genre @main_genre end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/musicgraph/artist.rb', line 3 def name @name end |
#rhapsody_id ⇒ Object (readonly)
Returns the value of attribute rhapsody_id.
3 4 5 |
# File 'lib/musicgraph/artist.rb', line 3 def rhapsody_id @rhapsody_id end |
#seven_digital_id ⇒ Object (readonly)
Returns the value of attribute seven_digital_id.
3 4 5 |
# File 'lib/musicgraph/artist.rb', line 3 def seven_digital_id @seven_digital_id end |
#sort_name ⇒ Object (readonly)
Returns the value of attribute sort_name.
3 4 5 |
# File 'lib/musicgraph/artist.rb', line 3 def sort_name @sort_name end |
#vevo_id ⇒ Object (readonly)
Returns the value of attribute vevo_id.
3 4 5 |
# File 'lib/musicgraph/artist.rb', line 3 def vevo_id @vevo_id end |
Class Method Details
.find(id, filters = nil) ⇒ Object
44 45 46 47 48 49 50 |
# 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 |
.search(params) ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# 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) ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# 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 |
Instance Method Details
#albums ⇒ Object
68 69 70 71 72 |
# 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 ⇒ Object
52 53 54 55 |
# 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 ⇒ Object
57 58 59 60 |
# File 'lib/musicgraph/artist.rb', line 57 def response = Faraday.get("#{API_URL}#{id}?#{MusicGraph.key_param}") JSON.parse(response.body)["data"] end |
#similar ⇒ Object
62 63 64 65 66 |
# 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 ⇒ Object
74 75 76 77 78 |
# 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 |