Class: Spotify::SDK::Artist

Inherits:
Model
  • Object
show all
Defined in:
lib/spotify/sdk/artist.rb

Instance Attribute Summary

Attributes inherited from Model

#parent

Instance Method Summary collapse

Methods inherited from Model

alias_attribute, hash_selector, #initialize, #to_h, #to_json

Constructor Details

This class inherits a constructor from Spotify::SDK::Model

Instance Method Details

#follow!Spotify::SDK::Artist

Follow the artist. Requires the ‘user-follow-modify` scope. PUT /v1/me/following

Examples:

@sdk.playback.item.artist.follow!

Returns:



63
64
65
66
# 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

#followersInteger

Return the followers on Spotify for this artist.

Examples:

artist = @sdk.connect.playback.artist
artist.followers # => 13913

Returns:

  • (Integer)

    followers The number of users following this artist.



158
159
160
# File 'lib/spotify/sdk/artist.rb', line 158

def followers
  super[:total]
end

#following=(should_follow) ⇒ Object

Helper method for setting the following status. Requires the ‘user-follow-modify` scope. If true, PUT /v1/me/following otherwise DELETE /v1/me/following

Examples:

@sdk.playback.item.artist.following = true
@sdk.playback.item.artist.following = false


47
48
49
50
51
# 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?FalseClass, TrueClass

Do we have the full information for this artist?

Examples:

artist = @sdk.connect.playback.artist
artist.full_information? # => false

Returns:

  • (FalseClass, TrueClass)

    is_full_info Does this contain everything?



15
16
17
# File 'lib/spotify/sdk/artist.rb', line 15

def full_information?
  to_h.key?(:images)
end

#genresArray

Display the artist’s genres. If not obtained, request them from the API.

Examples:

artist = @sdk.connect.playback.artist
artist.genres # => ["hip hop", "pop rap", "rap", ...]

Returns:

  • (Array)

    genres An array of genres, denoted in strings.



120
121
122
123
# File 'lib/spotify/sdk/artist.rb', line 120

def genres
  retrieve_full_information! unless full_information?
  super
end

#imagesArray

Display the artist’s images. If not obtained, request them from the API.

Examples:

artist = @sdk.connect.playback.artist
artist.images[0] # => [#<Spotify::SDK::Image>, #<Spotify::SDK::Image>, ...]

Returns:

  • (Array)

    images Contains a list of images, wrapped in Spotify::SDK::Image



92
93
94
95
# 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

#popularityInteger

Display the artist’s popularity. If not obtained, request them from the API.

Examples:

artist = @sdk.connect.playback.artist
artist.popularity # => 90

Returns:

  • (Integer)

    popularity The number of popularity, between 0-100.



106
107
108
109
# File 'lib/spotify/sdk/artist.rb', line 106

def popularity
  retrieve_full_information! unless full_information?
  super
end

#retrieve_full_information!TrueClass

Get full information for this artist by calling /v1/artists/:id

Examples:

artist = @sdk.connect.playback.artist
artist.retrieve_full_information! unless artist.full_information?

Returns:

  • (TrueClass)

    success Always returns true.



28
29
30
31
32
33
34
35
36
# 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_uriString

Return the Spotify URI for this artist.

Examples:

artist = @sdk.connect.playback.artist
artist.spotify_uri # => "spotify:uri:..."

Returns:

  • (String)

    spotify_uri The URI to open this artist in official apps.



147
# File 'lib/spotify/sdk/artist.rb', line 147

alias_attribute :spotify_uri, :uri

#spotify_urlString

Return the Spotify URL for this artist.

Examples:

artist = @sdk.connect.playback.artist
artist.spotify_url # => "https://open.spotify.com/artist/..."

Returns:

  • (String)

    spotify_url The URL to open this artist on open.spotify.com



134
135
136
# File 'lib/spotify/sdk/artist.rb', line 134

def spotify_url
  external_urls[:spotify]
end

#unfollow!Spotify::SDK::Artist

Unfollow the artist. Requires the ‘user-follow-modify` scope. DELETE /v1/me/following

Examples:

@sdk.playback.item.artist.unfollow!

Returns:



78
79
80
81
# 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