Class: RSpotify::Artist
Instance Attribute Summary collapse
-
#genres ⇒ Array<String>
A list of the genres the artist is associated with.
-
#images ⇒ Array<Hash>
Images of the artist in various sizes, widest first.
-
#name ⇒ String
The name of the artist.
-
#popularity ⇒ Integer
The popularity of the artist.
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(limit: 20, offset: 0, **filters) ⇒ Array<Album>
Returns array of albums from artist.
-
#initialize(options = {}) ⇒ Artist
constructor
A new instance of Artist.
-
#related_artists ⇒ Array<Artist>
Returns array of similar artists.
-
#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 the artist is associated with. 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>
Images of the artist 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 artist
7 8 9 |
# File 'lib/rspotify/artist.rb', line 7 def name @name end |
#popularity ⇒ Integer
The popularity of the artist. 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: limit, offset: offset) end |
Instance Method Details
#albums(limit: 20, offset: 0, **filters) ⇒ Array<Album>
Returns array of albums from artist
68 69 70 71 72 73 74 75 76 |
# File 'lib/rspotify/artist.rb', line 68 def albums(limit: 20, offset: 0, **filters) url = "artists/#{@id}/albums?limit=#{limit}&offset=#{offset}" filters.each do |filter_name, filter_value| url << "&#{filter_name}=#{filter_value}" end json = RSpotify.get(url) json['items'].map { |i| Album.new i } end |
#related_artists ⇒ Array<Artist>
Returns array of similar artists. Similarity is based on analysis of the Spotify community’s listening history.
88 89 90 91 92 |
# File 'lib/rspotify/artist.rb', line 88 def return @related_artists unless @related_artists.nil? json = RSpotify.get("artists/#{@id}/related-artists") @related_artists = json['artists'].map { |a| Artist.new a } end |
#top_tracks(country) ⇒ Array<Track>
Returns artist’s 10 top tracks by country.
104 105 106 107 108 |
# File 'lib/rspotify/artist.rb', line 104 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 |