Class: SpotifyWebApi::UsersController
- Inherits:
-
BaseController
- Object
- BaseController
- SpotifyWebApi::UsersController
- Defined in:
- lib/spotify_web_api/controllers/users_controller.rb
Overview
UsersController
Constant Summary
Constants inherited from BaseController
Instance Attribute Summary
Attributes inherited from BaseController
Instance Method Summary collapse
-
#check_current_user_follows(type, ids) ⇒ Array[TrueClass | FalseClass]
Check to see if the current user is following one or more artists or other Spotify users.
-
#check_if_user_follows_playlist(playlist_id, ids) ⇒ Array[TrueClass | FalseClass]
Check to see if one or more Spotify users are following a specified playlist.
-
#follow_artists_users(type, ids, body: nil) ⇒ void
Add the current user as a follower of one or more artists or other Spotify users.
-
#follow_playlist(playlist_id, body: nil) ⇒ void
Add the current user as a follower of a playlist.
-
#get_current_users_profile ⇒ PrivateUserObject
Get detailed profile information about the current user (including the current user’s username).
-
#get_followed(type, after: nil, limit: 20) ⇒ CursorPagedArtists
Get the current user’s followed artists.
-
#get_users_profile(user_id) ⇒ PublicUserObject
Get public profile information about a Spotify user.
-
#get_users_top_artists(time_range: 'medium_term', limit: 20, offset: 0) ⇒ PagingArtistObject
Get the current user’s top artists based on calculated affinity.
-
#get_users_top_tracks(time_range: 'medium_term', limit: 20, offset: 0) ⇒ PagingTrackObject
Get the current user’s top tracks based on calculated affinity.
-
#unfollow_artists_users(type, ids, body: nil) ⇒ void
Remove the current user as a follower of one or more artists or other Spotify users.
-
#unfollow_playlist(playlist_id) ⇒ void
Remove the current user as a follower of a playlist.
Methods inherited from BaseController
#initialize, #new_api_call_builder, #new_parameter, #new_request_builder, #new_response_handler, user_agent
Constructor Details
This class inherits a constructor from SpotifyWebApi::BaseController
Instance Method Details
#check_current_user_follows(type, ids) ⇒ Array[TrueClass | FalseClass]
Check to see if the current user is following one or more artists or other Spotify users.
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 |
# File 'lib/spotify_web_api/controllers/users_controller.rb', line 254 def check_current_user_follows(type, ids) new_api_call_builder .request(new_request_builder(HttpMethodEnum::GET, '/me/following/contains', Server::DEFAULT) .query_param(new_parameter(type, key: 'type')) .query_param(new_parameter(ids, key: 'ids')) .header_param(new_parameter('application/json', key: 'accept')) .auth(Single.new('oauth_2_0'))) .response(new_response_handler .deserializer(APIHelper.method(:deserialize_primitive_types)) .is_api_response(true) .is_response_array(true) .is_primitive_response(true) .local_error('401', "Bad or expired token. This can happen if the user revoked a'\ ' token or\nthe access token has expired. You should'\ ' re-authenticate the user.\n", UnauthorizedException) .local_error('403', "Bad OAuth request (wrong consumer key, bad nonce, expired'\ '\ntimestamp...). Unfortunately, re-authenticating the user'\ ' won't help here.\n", ForbiddenException) .local_error('429', "The app has exceeded its rate limits.\n", TooManyRequestsException)) .execute end |
#check_if_user_follows_playlist(playlist_id, ids) ⇒ Array[TrueClass | FalseClass]
Check to see if one or more Spotify users are following a specified playlist.
290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 |
# File 'lib/spotify_web_api/controllers/users_controller.rb', line 290 def check_if_user_follows_playlist(playlist_id, ids) new_api_call_builder .request(new_request_builder(HttpMethodEnum::GET, '/playlists/{playlist_id}/followers/contains', Server::DEFAULT) .template_param(new_parameter(playlist_id, key: 'playlist_id') .should_encode(true)) .query_param(new_parameter(ids, key: 'ids')) .header_param(new_parameter('application/json', key: 'accept')) .auth(Single.new('oauth_2_0'))) .response(new_response_handler .deserializer(APIHelper.method(:deserialize_primitive_types)) .is_api_response(true) .is_response_array(true) .is_primitive_response(true) .local_error('401', "Bad or expired token. This can happen if the user revoked a'\ ' token or\nthe access token has expired. You should'\ ' re-authenticate the user.\n", UnauthorizedException) .local_error('403', "Bad OAuth request (wrong consumer key, bad nonce, expired'\ '\ntimestamp...). Unfortunately, re-authenticating the user'\ ' won't help here.\n", ForbiddenException) .local_error('429', "The app has exceeded its rate limits.\n", TooManyRequestsException)) .execute end |
#follow_artists_users(type, ids, body: nil) ⇒ void
This method returns an undefined value.
Add the current user as a follower of one or more artists or other Spotify users.
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
# File 'lib/spotify_web_api/controllers/users_controller.rb', line 179 def follow_artists_users(type, ids, body: nil) new_api_call_builder .request(new_request_builder(HttpMethodEnum::PUT, '/me/following', Server::DEFAULT) .query_param(new_parameter(type, key: 'type')) .query_param(new_parameter(ids, key: 'ids')) .header_param(new_parameter('application/json', key: 'Content-Type')) .body_param(new_parameter(body)) .body_serializer(proc do |param| param.to_json unless param.nil? end) .auth(Single.new('oauth_2_0'))) .response(new_response_handler .is_response_void(true) .is_api_response(true) .local_error('401', "Bad or expired token. This can happen if the user revoked a'\ ' token or\nthe access token has expired. You should'\ ' re-authenticate the user.\n", UnauthorizedException) .local_error('403', "Bad OAuth request (wrong consumer key, bad nonce, expired'\ '\ntimestamp...). Unfortunately, re-authenticating the user'\ ' won't help here.\n", ForbiddenException) .local_error('429', "The app has exceeded its rate limits.\n", TooManyRequestsException)) .execute end |
#follow_playlist(playlist_id, body: nil) ⇒ void
This method returns an undefined value.
Add the current user as a follower of a playlist.
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/spotify_web_api/controllers/users_controller.rb', line 75 def follow_playlist(playlist_id, body: nil) new_api_call_builder .request(new_request_builder(HttpMethodEnum::PUT, '/playlists/{playlist_id}/followers', Server::DEFAULT) .template_param(new_parameter(playlist_id, key: 'playlist_id') .should_encode(true)) .header_param(new_parameter('application/json', key: 'Content-Type')) .body_param(new_parameter(body)) .body_serializer(proc do |param| param.to_json unless param.nil? end) .auth(Single.new('oauth_2_0'))) .response(new_response_handler .is_response_void(true) .is_api_response(true) .local_error('401', "Bad or expired token. This can happen if the user revoked a'\ ' token or\nthe access token has expired. You should'\ ' re-authenticate the user.\n", UnauthorizedException) .local_error('403', "Bad OAuth request (wrong consumer key, bad nonce, expired'\ '\ntimestamp...). Unfortunately, re-authenticating the user'\ ' won't help here.\n", ForbiddenException) .local_error('429', "The app has exceeded its rate limits.\n", TooManyRequestsException)) .execute end |
#get_current_users_profile ⇒ PrivateUserObject
Get detailed profile information about the current user (including the current user’s username).
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/spotify_web_api/controllers/users_controller.rb', line 12 def get_current_users_profile new_api_call_builder .request(new_request_builder(HttpMethodEnum::GET, '/me', Server::DEFAULT) .header_param(new_parameter('application/json', key: 'accept')) .auth(Single.new('oauth_2_0'))) .response(new_response_handler .deserializer(APIHelper.method(:custom_type_deserializer)) .deserialize_into(PrivateUserObject.method(:from_hash)) .is_api_response(true) .local_error('401', "Bad or expired token. This can happen if the user revoked a'\ ' token or\nthe access token has expired. You should'\ ' re-authenticate the user.\n", UnauthorizedException) .local_error('403', "Bad OAuth request (wrong consumer key, bad nonce, expired'\ '\ntimestamp...). Unfortunately, re-authenticating the user'\ ' won't help here.\n", ForbiddenException) .local_error('429', "The app has exceeded its rate limits.\n", TooManyRequestsException)) .execute end |
#get_followed(type, after: nil, limit: 20) ⇒ CursorPagedArtists
Get the current user’s followed artists.
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/spotify_web_api/controllers/users_controller.rb', line 141 def get_followed(type, after: nil, limit: 20) new_api_call_builder .request(new_request_builder(HttpMethodEnum::GET, '/me/following', Server::DEFAULT) .query_param(new_parameter(type, key: 'type')) .query_param(new_parameter(after, key: 'after')) .query_param(new_parameter(limit, key: 'limit')) .header_param(new_parameter('application/json', key: 'accept')) .auth(Single.new('oauth_2_0'))) .response(new_response_handler .deserializer(APIHelper.method(:custom_type_deserializer)) .deserialize_into(CursorPagedArtists.method(:from_hash)) .is_api_response(true) .local_error('401', "Bad or expired token. This can happen if the user revoked a'\ ' token or\nthe access token has expired. You should'\ ' re-authenticate the user.\n", UnauthorizedException) .local_error('403', "Bad OAuth request (wrong consumer key, bad nonce, expired'\ '\ntimestamp...). Unfortunately, re-authenticating the user'\ ' won't help here.\n", ForbiddenException) .local_error('429', "The app has exceeded its rate limits.\n", TooManyRequestsException)) .execute end |
#get_users_profile(user_id) ⇒ PublicUserObject
Get public profile information about a Spotify user.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/spotify_web_api/controllers/users_controller.rb', line 42 def get_users_profile(user_id) new_api_call_builder .request(new_request_builder(HttpMethodEnum::GET, '/users/{user_id}', Server::DEFAULT) .template_param(new_parameter(user_id, key: 'user_id') .should_encode(true)) .header_param(new_parameter('application/json', key: 'accept')) .auth(Single.new('oauth_2_0'))) .response(new_response_handler .deserializer(APIHelper.method(:custom_type_deserializer)) .deserialize_into(PublicUserObject.method(:from_hash)) .is_api_response(true) .local_error('401', "Bad or expired token. This can happen if the user revoked a'\ ' token or\nthe access token has expired. You should'\ ' re-authenticate the user.\n", UnauthorizedException) .local_error('403', "Bad OAuth request (wrong consumer key, bad nonce, expired'\ '\ntimestamp...). Unfortunately, re-authenticating the user'\ ' won't help here.\n", ForbiddenException) .local_error('429', "The app has exceeded its rate limits.\n", TooManyRequestsException)) .execute end |
#get_users_top_artists(time_range: 'medium_term', limit: 20, offset: 0) ⇒ PagingArtistObject
Get the current user’s top artists based on calculated affinity.
327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 |
# File 'lib/spotify_web_api/controllers/users_controller.rb', line 327 def get_users_top_artists(time_range: 'medium_term', limit: 20, offset: 0) new_api_call_builder .request(new_request_builder(HttpMethodEnum::GET, '/me/top/artists', Server::DEFAULT) .query_param(new_parameter(time_range, key: 'time_range')) .query_param(new_parameter(limit, key: 'limit')) .query_param(new_parameter(offset, key: 'offset')) .header_param(new_parameter('application/json', key: 'accept')) .auth(Single.new('oauth_2_0'))) .response(new_response_handler .deserializer(APIHelper.method(:custom_type_deserializer)) .deserialize_into(PagingArtistObject.method(:from_hash)) .is_api_response(true) .local_error('401', "Bad or expired token. This can happen if the user revoked a'\ ' token or\nthe access token has expired. You should'\ ' re-authenticate the user.\n", UnauthorizedException) .local_error('403', "Bad OAuth request (wrong consumer key, bad nonce, expired'\ '\ntimestamp...). Unfortunately, re-authenticating the user'\ ' won't help here.\n", ForbiddenException) .local_error('429', "The app has exceeded its rate limits.\n", TooManyRequestsException)) .execute end |
#get_users_top_tracks(time_range: 'medium_term', limit: 20, offset: 0) ⇒ PagingTrackObject
Get the current user’s top tracks based on calculated affinity.
364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 |
# File 'lib/spotify_web_api/controllers/users_controller.rb', line 364 def get_users_top_tracks(time_range: 'medium_term', limit: 20, offset: 0) new_api_call_builder .request(new_request_builder(HttpMethodEnum::GET, '/me/top/tracks', Server::DEFAULT) .query_param(new_parameter(time_range, key: 'time_range')) .query_param(new_parameter(limit, key: 'limit')) .query_param(new_parameter(offset, key: 'offset')) .header_param(new_parameter('application/json', key: 'accept')) .auth(Single.new('oauth_2_0'))) .response(new_response_handler .deserializer(APIHelper.method(:custom_type_deserializer)) .deserialize_into(PagingTrackObject.method(:from_hash)) .is_api_response(true) .local_error('401', "Bad or expired token. This can happen if the user revoked a'\ ' token or\nthe access token has expired. You should'\ ' re-authenticate the user.\n", UnauthorizedException) .local_error('403', "Bad OAuth request (wrong consumer key, bad nonce, expired'\ '\ntimestamp...). Unfortunately, re-authenticating the user'\ ' won't help here.\n", ForbiddenException) .local_error('429', "The app has exceeded its rate limits.\n", TooManyRequestsException)) .execute end |
#unfollow_artists_users(type, ids, body: nil) ⇒ void
This method returns an undefined value.
Remove the current user as a follower of one or more artists or other Spotify users.
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 |
# File 'lib/spotify_web_api/controllers/users_controller.rb', line 217 def unfollow_artists_users(type, ids, body: nil) new_api_call_builder .request(new_request_builder(HttpMethodEnum::DELETE, '/me/following', Server::DEFAULT) .query_param(new_parameter(type, key: 'type')) .query_param(new_parameter(ids, key: 'ids')) .header_param(new_parameter('application/json', key: 'Content-Type')) .body_param(new_parameter(body)) .body_serializer(proc do |param| param.to_json unless param.nil? end) .auth(Single.new('oauth_2_0'))) .response(new_response_handler .is_response_void(true) .is_api_response(true) .local_error('401', "Bad or expired token. This can happen if the user revoked a'\ ' token or\nthe access token has expired. You should'\ ' re-authenticate the user.\n", UnauthorizedException) .local_error('403', "Bad OAuth request (wrong consumer key, bad nonce, expired'\ '\ntimestamp...). Unfortunately, re-authenticating the user'\ ' won't help here.\n", ForbiddenException) .local_error('429', "The app has exceeded its rate limits.\n", TooManyRequestsException)) .execute end |
#unfollow_playlist(playlist_id) ⇒ void
This method returns an undefined value.
Remove the current user as a follower of a playlist.
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/spotify_web_api/controllers/users_controller.rb', line 109 def unfollow_playlist(playlist_id) new_api_call_builder .request(new_request_builder(HttpMethodEnum::DELETE, '/playlists/{playlist_id}/followers', Server::DEFAULT) .template_param(new_parameter(playlist_id, key: 'playlist_id') .should_encode(true)) .auth(Single.new('oauth_2_0'))) .response(new_response_handler .is_response_void(true) .is_api_response(true) .local_error('401', "Bad or expired token. This can happen if the user revoked a'\ ' token or\nthe access token has expired. You should'\ ' re-authenticate the user.\n", UnauthorizedException) .local_error('403', "Bad OAuth request (wrong consumer key, bad nonce, expired'\ '\ntimestamp...). Unfortunately, re-authenticating the user'\ ' won't help here.\n", ForbiddenException) .local_error('429', "The app has exceeded its rate limits.\n", TooManyRequestsException)) .execute end |