class MusicGraph::Album

Constants

API_URL

Attributes

album_artist_id[R]
album_ref_id[R]
entity_type[R]
id[R]
main_genre[R]
number_of_tracks[R]
performer_name[R]
product_form[R]
release_year[R]
title[R]

Public Class Methods

find(id, filters = nil) click to toggle source
# 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
new(attributes) click to toggle source
# 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
suggest(params) click to toggle source
# 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

Public Instance Methods

artists() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# File lib/musicgraph/album.rb, line 56
def metadata
  response = Faraday.get("#{API_URL}#{id}?#{MusicGraph.key_param}")
  JSON.parse(response.body)["data"]
end
tracks() click to toggle source
# 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