Class: RSpotify::Artist
Instance Attribute Summary collapse
-
#followers ⇒ Hash
Information about the followers of the artist.
-
#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, market: nil) ⇒ 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!, #embed, #method_missing, #respond_to?
Constructor Details
#initialize(options = {}) ⇒ Artist
Returns a new instance of Artist.
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/rspotify/artist.rb', line 46 def initialize( = {}) @followers = ['followers'] @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
#followers ⇒ Hash
Information about the followers of the artist
8 9 10 |
# File 'lib/rspotify/artist.rb', line 8 def followers @followers end |
#genres ⇒ Array<String>
A list of the genres the artist is associated with. If not yet classified, the array is empty
8 9 10 |
# File 'lib/rspotify/artist.rb', line 8 def genres @genres end |
#images ⇒ Array<Hash>
Images of the artist in various sizes, widest first
8 9 10 |
# File 'lib/rspotify/artist.rb', line 8 def images @images end |
#name ⇒ String
The name of the artist
8 9 10 |
# File 'lib/rspotify/artist.rb', line 8 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
8 9 10 |
# File 'lib/rspotify/artist.rb', line 8 def popularity @popularity end |
Class Method Details
.find(ids) ⇒ Artist+
Returns Artist object(s) with id(s) provided
24 25 26 |
# File 'lib/rspotify/artist.rb', line 24 def self.find(ids) super(ids, 'artist') end |
.search(query, limit: 20, offset: 0, market: nil) ⇒ Array<Artist>
Returns array of Artist objects matching the query, ordered by popularity. It’s also possible to find the total number of search results for the query
42 43 44 |
# File 'lib/rspotify/artist.rb', line 42 def self.search(query, limit: 20, offset: 0, market: nil) super(query, 'artist', limit: limit, offset: offset, market: market) end |
Instance Method Details
#albums(limit: 20, offset: 0, **filters) ⇒ Array<Album>
Returns array of albums from artist
69 70 71 72 73 74 75 76 77 78 |
# File 'lib/rspotify/artist.rb', line 69 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 response = RSpotify.get(url) return response if RSpotify.raw_response response['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.
90 91 92 93 94 95 96 |
# File 'lib/rspotify/artist.rb', line 90 def return @related_artists unless @related_artists.nil? || RSpotify.raw_response response = RSpotify.get("artists/#{@id}/related-artists") return response if RSpotify.raw_response @related_artists = response['artists'].map { |a| Artist.new a } end |
#top_tracks(country) ⇒ Array<Track>
Returns artist’s 10 top tracks by country.
108 109 110 111 112 113 114 |
# File 'lib/rspotify/artist.rb', line 108 def top_tracks(country) return @top_tracks[country] unless @top_tracks[country].nil? || RSpotify.raw_response response = RSpotify.get("artists/#{@id}/top-tracks?country=#{country}") return response if RSpotify.raw_response @top_tracks[country] = response['tracks'].map { |t| Track.new t } end |