Sha256: 2d82855ad1d933e2b79c18dad87f9482f29d6a03665a364abd0260fbbbf6bddb
Contents?: true
Size: 1.26 KB
Versions: 4
Compression:
Stored size: 1.26 KB
Contents
# encoding: utf-8 module RapGenius class Artist include RapGenius::Client def self.find(id) self.new(id: id).tap { |artist| artist.document } end def initialize(kwargs = {}) @id = kwargs.delete(:id) @name = kwargs.delete(:name) @type = kwargs.delete(:type) self.url = "artists/#{@id}" end def response document["response"]["artist"] end def name @name ||= response["name"] end def image @image ||= response["image_url"] end def url response["url"] end def description @description ||= response["description"]["plain"] end # 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. 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 end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
rapgenius-1.1.2 | lib/rapgenius/artist.rb |
rapgenius-1.1.1 | lib/rapgenius/artist.rb |
rapgenius-1.1.0 | lib/rapgenius/artist.rb |
rapgenius-1.0.5 | lib/rapgenius/artist.rb |