Class: SpotifyWebApi::MarketsController

Inherits:
BaseController show all
Defined in:
lib/spotify_web_api/controllers/markets_controller.rb

Overview

MarketsController

Constant Summary

Constants inherited from BaseController

BaseController::GLOBAL_ERRORS

Instance Attribute Summary

Attributes inherited from BaseController

#config, #http_call_back

Instance Method Summary collapse

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

#get_available_marketsMarkets

Get the list of markets where Spotify is available.

Returns:

  • (Markets)

    response from the API call



11
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
# File 'lib/spotify_web_api/controllers/markets_controller.rb', line 11

def get_available_markets
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/markets',
                                 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(Markets.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