Class: Spotify::SDK::Artist
- Defined in:
- lib/spotify/sdk/artist.rb
Instance Attribute Summary
Attributes inherited from Model
Instance Method Summary collapse
-
#follow! ⇒ Spotify::SDK::Artist
Follow the artist.
-
#followers ⇒ Integer
Return the followers on Spotify for this artist.
-
#following=(should_follow) ⇒ Object
Helper method for setting the following status.
-
#full_information? ⇒ FalseClass, TrueClass
Do we have the full information for this artist?.
-
#genres ⇒ Array
Display the artist's genres.
-
#images ⇒ Array
Display the artist's images.
-
#popularity ⇒ Integer
Display the artist's popularity.
-
#retrieve_full_information! ⇒ TrueClass
Get full information for this artist by calling /v1/artists/:id.
-
#spotify_uri ⇒ String
Return the Spotify URI for this artist.
-
#spotify_url ⇒ String
Return the Spotify URL for this artist.
-
#unfollow! ⇒ Spotify::SDK::Artist
Unfollow the artist.
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
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 |
#followers ⇒ Integer
Return the followers on Spotify for 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
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?
15 16 17 |
# File 'lib/spotify/sdk/artist.rb', line 15 def full_information? to_h.key?(:images) end |
#genres ⇒ Array
Display the artist's genres. If not obtained, request them from the API.
120 121 122 123 |
# File 'lib/spotify/sdk/artist.rb', line 120 def genres retrieve_full_information! unless full_information? super end |
#images ⇒ Array
Display the artist's images. If not obtained, request them from the API.
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 |
#popularity ⇒ Integer
Display the artist's popularity. If not obtained, request them from the API.
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
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_uri ⇒ String
Return the Spotify URI for this artist.
147 |
# File 'lib/spotify/sdk/artist.rb', line 147 alias_attribute :spotify_uri, :uri |
#spotify_url ⇒ String
Return the Spotify URL for this artist.
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
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 |