class Spotify::SDK::Artist
Public Instance Methods
Follow the artist. Requires the `user-follow-modify` scope. PUT /v1/me/following
@example
@sdk.playback.item.artist.follow!
@return [Spotify::SDK::Artist] self Return the artist object, for chaining methods.
# File lib/spotify/sdk/artist.rb, line 62 def follow! parent.send_http_request(:put, "/v1/me/following?type=artist&ids=%s" % id, http_options: {expect_nil: true}) self end
Return the followers on Spotify
for this artist.
@example
artist = @sdk.connect.playback.artist artist.followers # => 13913
@return [Integer] followers The number of users following this artist.
# File lib/spotify/sdk/artist.rb, line 157 def followers super[:total] end
Helper method for setting the following status. Requires the `user-follow-modify` scope. If true, PUT /v1/me/following otherwise DELETE /v1/me/following
@example
@sdk.playback.item.artist.following = true @sdk.playback.item.artist.following = false
# File lib/spotify/sdk/artist.rb, line 47 def following=(should_follow) raise "#following= must be true or false" unless [true, false].include?(should_follow) should_follow ? follow! : unfollow! end
Do we have the full information for this artist?
@example
artist = @sdk.connect.playback.artist artist.full_information? # => false
@return [FalseClass,TrueClass] is_full_info Does this contain everything?
# File lib/spotify/sdk/artist.rb, line 15 def full_information? to_h.key?(:images) end
Display the artist's genres. If not obtained, request them from the API.
@example
artist = @sdk.connect.playback.artist artist.genres # => ["hip hop", "pop rap", "rap", ...]
@return [Array] genres An array of genres, denoted in strings.
# File lib/spotify/sdk/artist.rb, line 119 def genres retrieve_full_information! unless full_information? super end
Display the artist's images. If not obtained, request them from the API.
@example
artist = @sdk.connect.playback.artist artist.images[0] # => [#<Spotify::SDK::Image>, #<Spotify::SDK::Image>, ...]
@return [Array] images Contains a list of images, wrapped in Spotify::SDK::Image
# File lib/spotify/sdk/artist.rb, line 91 def images retrieve_full_information! unless full_information? super.map {|image| Spotify::SDK::Image.new(image, parent) } end
Display the artist's popularity. If not obtained, request them from the API.
@example
artist = @sdk.connect.playback.artist artist.popularity # => 90
@return [Integer] popularity The number of popularity, between 0-100.
# File lib/spotify/sdk/artist.rb, line 105 def popularity retrieve_full_information! unless full_information? super end
Get full information for this artist by calling /v1/artists/:id
@example
artist = @sdk.connect.playback.artist artist.retrieve_full_information! unless artist.full_information?
@return [TrueClass] success Always returns true.
# File lib/spotify/sdk/artist.rb, line 28 def retrieve_full_information! unless full_information? parent.send_http_request(:get, "/v1/artists/%s" % id).map do |key, value| send("%s=" % key, value) end end true end
Return the Spotify
URI for this artist.
@example
artist = @sdk.connect.playback.artist artist.spotify_uri # => "spotify:uri:..."
@return [String] spotify_uri
The URI to open this artist in official apps.
# File lib/spotify/sdk/artist.rb, line 146 alias_attribute :spotify_uri, :uri
Return the Spotify
URL for this artist.
@example
artist = @sdk.connect.playback.artist artist.spotify_url # => "https://open.spotify.com/artist/..."
@return [String] spotify_url
The URL to open this artist on open.spotify.com
# File lib/spotify/sdk/artist.rb, line 133 def spotify_url external_urls[:spotify] end
Unfollow the artist. Requires the `user-follow-modify` scope. DELETE /v1/me/following
@example
@sdk.playback.item.artist.unfollow!
@return [Spotify::SDK::Artist] self Return the artist object, for chaining methods.
# File lib/spotify/sdk/artist.rb, line 77 def unfollow! parent.send_http_request(:delete, "/v1/me/following?type=artist&ids=%s" % id, http_options: {expect_nil: true}) self end