class Spotify::SDK::Me
Public Instance Methods
Get the current user's followed artists. Requires the `user-read-follow` scope. GET /v1/me/following
@example
@sdk.me.following
@param [Integer] n Number of results to return. @param [Hash] override_opts Custom options for HTTParty. @return [Array] artists A list of followed artists, wrapped in Spotify::SDK::Artist
# File lib/spotify/sdk/me.rb, line 93 def following(limit=50, override_opts={}) request = { method: :get, # TODO: Spotify API bug - `limit={n}` returns n-1 artists. # ^ Example: `limit=5` returns 4 artists. # TODO: Support `type=users` as well as `type=artists`. http_path: "/v1/me/following?type=artist&limit=#{[limit, 50].min}", keys: %i[artists items], limit: limit } send_multiple_http_requests(request, override_opts).map do |artist| Spotify::SDK::Artist.new(artist, self) end end
Check if the current user is following N users.
@example
artists = %w(3q7HBObVc0L8jNeTe5Gofh 0NbfKEOTQCcwd6o7wSDOHI 3TVXtAsR1Inumwj472S9r4) @sdk.me.following?(artists, :artist) # => {"3q7HBObVc0L8jNeTe5Gofh" => false, "0NbfKEOTQCcwd6o7wSDOHI" => false, ...} users = %w(3q7HBObVc0L8jNeTe5Gofh 0NbfKEOTQCcwd6o7wSDOHI 3TVXtAsR1Inumwj472S9r4) @sdk.me.following?(users, :user) # => {"3q7HBObVc0L8jNeTe5Gofh" => false, "0NbfKEOTQCcwd6o7wSDOHI" => false, ...}
@param [Array] list List of Spotify
user/artist IDs. Cannot mix user and artist IDs in single request. @param [Symbol] type Either :user or :artist. Checks if follows respective type of account. @param [Hash] override_opts Custom options for HTTParty. @return [Hash] hash A hash containing a key with the ID, and a value that equals is_following (boolean).
# File lib/spotify/sdk/me.rb, line 66 def following?(list, type=:artist, override_opts={}) raise "Must contain an array" unless list.is_a?(Array) raise "Must contain an array of String or Spotify::SDK::Artist" if any_of?(list, [String, Spotify::SDK::Artist]) raise "type must be either 'artist' or 'user'" unless %i[artist user].include?(type) send_is_following_http_requests(list.map {|id| id.try(:id) || id }, type, override_opts) end
# File lib/spotify/sdk/me.rb, line 74 def following_artists?(list, override_opts={}) following?(list, :artist, override_opts) end
# File lib/spotify/sdk/me.rb, line 78 def following_users?(list, override_opts={}) following?(list, :user, override_opts) end
Check what tracks a user has recently played.
@example
@sdk.me.history @sdk.me.history(20)
@param [Integer] limit How many results to request. Defaults to 10. @param [Hash] override_opts Custom options for HTTParty. @return [Array] response List of recently played tracked, in chronological order.
# File lib/spotify/sdk/me.rb, line 36 def history(limit=10, override_opts={}) request = { method: :get, http_path: "/v1/me/player/recently-played", keys: %i[items], limit: limit } send_multiple_http_requests(request, override_opts).map do |item| Spotify::SDK::Item.new(item, self) end end
Get the current user's information. Respective information requires the `user-read-private user-read-email user-read-birthdate` scopes. GET /v1/me
@example
me = @sdk.me.info
@see developer.spotify.com/console/get-current-user/ @see developer.spotify.com/documentation/web-api/reference/users-profile/get-current-users-profile/
@param [Hash] override_opts Custom options for HTTParty. @return [Spotify::SDK::Me::Info] user_info Return the user's information.
# File lib/spotify/sdk/me.rb, line 20 def info(override_opts={}) me_info = send_http_request(:get, "/v1/me", override_opts) Spotify::SDK::Me::Info.new(me_info, self) end