class RapGenius::Artist

Public Class Methods

find(id) click to toggle source
# File lib/rapgenius/artist.rb, line 6
def self.find(id)
  self.new(id: id).tap { |artist| artist.document }
end
new(kwargs = {}) click to toggle source
# File lib/rapgenius/artist.rb, line 10
def initialize(kwargs = {})
  @id = kwargs.delete(:id)
  @name = kwargs.delete(:name)
  @type = kwargs.delete(:type)
  self.url = "artists/#{@id}"
end

Public Instance Methods

description() click to toggle source
# File lib/rapgenius/artist.rb, line 33
def description
  @description ||= response["description"]["plain"]
end
image() click to toggle source
# File lib/rapgenius/artist.rb, line 25
def image
  @image ||= response["image_url"]
end
name() click to toggle source
# File lib/rapgenius/artist.rb, line 21
def name
  @name ||= response["name"]
end
response() click to toggle source
# File lib/rapgenius/artist.rb, line 17
def response
  document["response"]["artist"]
end
songs(options = {page: 1}) click to toggle source

You seem to be able to load 20 songs at a time for an artist. I haven’t found a way to vary the number you get back from the query, but you can paginate through in blocks of 20 songs.

# File lib/rapgenius/artist.rb, line 40
def songs(options = {page: 1})
  songs_url = "/artists/#{@id}/songs/?page=#{options[:page]}"

  fetch(songs_url)["response"]["songs"].map do |song|
    Song.new(
      artist: Artist.new(
        name: song["primary_artist"]["name"],
        id: song["primary_artist"]["id"],
        type: :primary
      ),
      title: song["title"],
      id: song["id"]
    )
  end
end
url() click to toggle source
# File lib/rapgenius/artist.rb, line 29
def url
  response["url"]
end