Class: RSpotify::Artist
Instance Attribute Summary collapse
-
#genres ⇒ Array<String>
A list of the genres used to classify the album.
-
#images ⇒ Array<Hash>
The cover art for the album in various sizes, widest first.
-
#name ⇒ String
The name of the album.
-
#popularity ⇒ Integer
The popularity of the album.
Attributes inherited from Base
#external_urls, #href, #id, #type, #uri
Class Method Summary collapse
-
.find(ids) ⇒ Artist+
Returns Artist object(s) with id(s) provided.
-
.search(query, limit = 20, offset = 0) ⇒ Array<Artist>
Returns array of Artist objects matching the query, ordered by popularity.
Instance Method Summary collapse
-
#albums ⇒ Array<Album>
Returns all albums from artist.
-
#initialize(options = {}) ⇒ Artist
constructor
A new instance of Artist.
-
#top_tracks(country) ⇒ Array<Track>
Returns artist’s 10 top tracks by country.
Methods inherited from Base
#complete!, #method_missing, #respond_to?
Constructor Details
#initialize(options = {}) ⇒ Artist
Returns a new instance of Artist.
46 47 48 49 50 51 52 53 54 |
# File 'lib/rspotify/artist.rb', line 46 def initialize( = {}) @genres = ['genres'] @images = ['images'] @name = ['name'] @popularity = ['popularity'] @top_tracks = {} super() end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class RSpotify::Base
Instance Attribute Details
#genres ⇒ Array<String>
A list of the genres used to classify the album. If not yet classified, the array is empty.
7 8 9 |
# File 'lib/rspotify/artist.rb', line 7 def genres @genres end |
#images ⇒ Array<Hash>
The cover art for the album in various sizes, widest first
7 8 9 |
# File 'lib/rspotify/artist.rb', line 7 def images @images end |
#name ⇒ String
The name of the album
7 8 9 |
# File 'lib/rspotify/artist.rb', line 7 def name @name end |
#popularity ⇒ Integer
The popularity of the album. The value will be between 0 and 100, with 100 being the most popular
7 8 9 |
# File 'lib/rspotify/artist.rb', line 7 def popularity @popularity end |
Class Method Details
.find(ids) ⇒ Artist+
Returns Artist object(s) with id(s) provided
23 24 25 |
# File 'lib/rspotify/artist.rb', line 23 def self.find(ids) super(ids, 'artist') end |
.search(query, limit = 20, offset = 0) ⇒ Array<Artist>
Returns array of Artist objects matching the query, ordered by popularity
42 43 44 |
# File 'lib/rspotify/artist.rb', line 42 def self.search(query, limit = 20, offset = 0) super(query, 'artist', limit, offset) end |
Instance Method Details
#albums ⇒ Array<Album>
Returns all albums from artist
65 66 67 68 69 |
# File 'lib/rspotify/artist.rb', line 65 def albums return @albums unless @albums.nil? json = RSpotify.get("artists/#{@id}/albums") @albums = json['items'].map { |a| Album.new a } end |
#top_tracks(country) ⇒ Array<Track>
Returns artist’s 10 top tracks by country.
81 82 83 84 85 |
# File 'lib/rspotify/artist.rb', line 81 def top_tracks(country) return @top_tracks[country] unless @top_tracks[country].nil? json = RSpotify.get("artists/#{@id}/top-tracks?country=#{country}") @top_tracks[country] = json['tracks'].map { |t| Track.new t } end |