Class: MusicGraph::Album
- Inherits:
-
Object
- Object
- MusicGraph::Album
- Defined in:
- lib/musicgraph/album.rb
Constant Summary collapse
- API_URL =
"http://api.musicgraph.com/api/v2/album/"
Instance Attribute Summary collapse
-
#album_artist_id ⇒ Object
readonly
Returns the value of attribute album_artist_id.
-
#album_ref_id ⇒ Object
readonly
Returns the value of attribute album_ref_id.
-
#entity_type ⇒ Object
readonly
Returns the value of attribute entity_type.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#main_genre ⇒ Object
readonly
Returns the value of attribute main_genre.
-
#number_of_tracks ⇒ Object
readonly
Returns the value of attribute number_of_tracks.
-
#performer_name ⇒ Object
readonly
Returns the value of attribute performer_name.
-
#product_form ⇒ Object
readonly
Returns the value of attribute product_form.
-
#release_year ⇒ Object
readonly
Returns the value of attribute release_year.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Class Method Summary collapse
Instance Method Summary collapse
- #artists ⇒ Object
- #edges ⇒ Object
-
#initialize(attributes) ⇒ Album
constructor
A new instance of Album.
- #metadata ⇒ Object
- #tracks ⇒ Object
Constructor Details
#initialize(attributes) ⇒ Album
Returns a new instance of Album.
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/musicgraph/album.rb', line 7 def initialize(attributes) @title = attributes["title"] @title = attributes["name"] if attributes["name"] @release_year = attributes["release_year"] @entity_type = attributes["entity_type"] @album_artist_id = attributes["album_artist_id"] @id = attributes["id"] @number_of_tracks = attributes["number_of_tracks"] @album_ref_id = attributes["album_ref_id"] @performer_name = attributes["performer_name"] @main_genre = attributes["main_genre"] @product_form = attributes["product_form"] end |
Instance Attribute Details
#album_artist_id ⇒ Object (readonly)
Returns the value of attribute album_artist_id.
3 4 5 |
# File 'lib/musicgraph/album.rb', line 3 def album_artist_id @album_artist_id end |
#album_ref_id ⇒ Object (readonly)
Returns the value of attribute album_ref_id.
3 4 5 |
# File 'lib/musicgraph/album.rb', line 3 def album_ref_id @album_ref_id end |
#entity_type ⇒ Object (readonly)
Returns the value of attribute entity_type.
3 4 5 |
# File 'lib/musicgraph/album.rb', line 3 def entity_type @entity_type end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
3 4 5 |
# File 'lib/musicgraph/album.rb', line 3 def id @id end |
#main_genre ⇒ Object (readonly)
Returns the value of attribute main_genre.
3 4 5 |
# File 'lib/musicgraph/album.rb', line 3 def main_genre @main_genre end |
#number_of_tracks ⇒ Object (readonly)
Returns the value of attribute number_of_tracks.
3 4 5 |
# File 'lib/musicgraph/album.rb', line 3 def number_of_tracks @number_of_tracks end |
#performer_name ⇒ Object (readonly)
Returns the value of attribute performer_name.
3 4 5 |
# File 'lib/musicgraph/album.rb', line 3 def performer_name @performer_name end |
#product_form ⇒ Object (readonly)
Returns the value of attribute product_form.
3 4 5 |
# File 'lib/musicgraph/album.rb', line 3 def product_form @product_form end |
#release_year ⇒ Object (readonly)
Returns the value of attribute release_year.
3 4 5 |
# File 'lib/musicgraph/album.rb', line 3 def release_year @release_year end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
3 4 5 |
# File 'lib/musicgraph/album.rb', line 3 def title @title end |
Class Method Details
.find(id, filters = nil) ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/musicgraph/album.rb', line 43 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
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/musicgraph/album.rb', line 21 def self.search(params) if params.is_a? String response = Faraday.get("#{API_URL}search?#{MusicGraph.key_param}&title=#{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 albums = JSON.parse(response.body)["data"] albums.map { |attributes| new(attributes) } end |
.suggest(params) ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/musicgraph/album.rb', line 32 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 albums = JSON.parse(response.body)["data"] albums.map { |attributes| new(attributes) } end |
Instance Method Details
#artists ⇒ Object
61 62 63 64 65 |
# File 'lib/musicgraph/album.rb', line 61 def artists response = Faraday.get("#{API_URL}#{id}/artists?#{MusicGraph.key_param}") artists = JSON.parse(response.body)["data"] artists.map { |attributes| Artist.new(attributes) } end |
#edges ⇒ Object
51 52 53 54 |
# File 'lib/musicgraph/album.rb', line 51 def edges response = Faraday.get("#{API_URL}#{id}/edges?#{MusicGraph.key_param}") JSON.parse(response.body)["data"] end |
#metadata ⇒ Object
56 57 58 59 |
# File 'lib/musicgraph/album.rb', line 56 def response = Faraday.get("#{API_URL}#{id}?#{MusicGraph.key_param}") JSON.parse(response.body)["data"] end |
#tracks ⇒ Object
67 68 69 70 71 |
# File 'lib/musicgraph/album.rb', line 67 def tracks response = Faraday.get("#{API_URL}#{id}/tracks?#{MusicGraph.key_param}") tracks = JSON.parse(response.body)["data"] tracks.map { |attributes| Track.new(attributes) } end |