Class: Spotify::SDK::Me
- Defined in:
- lib/spotify/sdk/me.rb,
lib/spotify/sdk/me/info.rb
Defined Under Namespace
Classes: Info
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#following(limit = 50, override_opts = {}) ⇒ Array
Get the current user's followed artists.
-
#following?(list, type = :artist, override_opts = {}) ⇒ Hash
Check if the current user is following N users.
- #following_artists?(list, override_opts = {}) ⇒ Boolean
- #following_users?(list, override_opts = {}) ⇒ Boolean
-
#history(limit = 10, override_opts = {}) ⇒ Array
Check what tracks a user has recently played.
-
#info(override_opts = {}) ⇒ Spotify::SDK::Me::Info
Get the current user's information.
Methods inherited from Base
#initialize, #inspect, #send_http_request
Constructor Details
This class inherits a constructor from Spotify::SDK::Base
Instance Method Details
#following(limit = 50, override_opts = {}) ⇒ Array
Get the current user's followed artists. Requires the `user-read-follow` scope. GET /v1/me/following
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# 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 |
#following?(list, type = :artist, override_opts = {}) ⇒ Hash
Check if the current user is following N users.
66 67 68 69 70 71 72 |
# 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 |
#following_artists?(list, override_opts = {}) ⇒ Boolean
74 75 76 |
# File 'lib/spotify/sdk/me.rb', line 74 def following_artists?(list, override_opts={}) following?(list, :artist, override_opts) end |
#following_users?(list, override_opts = {}) ⇒ Boolean
78 79 80 |
# File 'lib/spotify/sdk/me.rb', line 78 def following_users?(list, override_opts={}) following?(list, :user, override_opts) end |
#history(limit = 10, override_opts = {}) ⇒ Array
Check what tracks a user has recently played.
36 37 38 39 40 41 42 43 44 45 46 47 |
# 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 |
#info(override_opts = {}) ⇒ Spotify::SDK::Me::Info
Get the current user's information. Respective information requires the `user-read-private user-read-email user-read-birthdate` scopes. GET /v1/me
20 21 22 23 |
# 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 |