class Spotify::SDK::Artist

Public Instance Methods

follow!() click to toggle source

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 63
def follow!
  parent.send_http_request(:put, "/v1/me/following?type=artist&ids=%s" % id, http_options: {expect_nil: true})
  self
end
followers() click to toggle source

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.

Calls superclass method
# File lib/spotify/sdk/artist.rb, line 158
def followers
  super[:total]
end
following=(should_follow) click to toggle source

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
full_information?() click to toggle source

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
genres() click to toggle source

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.

Calls superclass method
# File lib/spotify/sdk/artist.rb, line 120
def genres
  retrieve_full_information! unless full_information?
  super
end
images() click to toggle source

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

Calls superclass method
# File lib/spotify/sdk/artist.rb, line 92
def images
  retrieve_full_information! unless full_information?
  super.map {|image| Spotify::SDK::Image.new(image, parent) }
end
popularity() click to toggle source

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.

Calls superclass method
# File lib/spotify/sdk/artist.rb, line 106
def popularity
  retrieve_full_information! unless full_information?
  super
end
retrieve_full_information!() click to toggle source

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
spotify_uri() click to toggle source

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 147
alias_attribute :spotify_uri, :uri
spotify_url() click to toggle source

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 134
def spotify_url
  external_urls[:spotify]
end
unfollow!() click to toggle source

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 78
def unfollow!
  parent.send_http_request(:delete, "/v1/me/following?type=artist&ids=%s" % id, http_options: {expect_nil: true})
  self
end