Class: SpotifyWebApi::Client

Inherits:
Object
  • Object
show all
Includes:
CoreLibrary
Defined in:
lib/spotify_web_api/client.rb

Overview

spotify_web_api client class.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection: nil, adapter: :net_http_persistent, timeout: 60, max_retries: 0, retry_interval: 1, backoff_factor: 2, retry_statuses: [408, 413, 429, 500, 502, 503, 504, 521, 522, 524], retry_methods: %i[get put],, http_callback: nil, environment: Environment::PRODUCTION, o_auth_client_id: nil, o_auth_client_secret: nil, o_auth_redirect_uri: nil, o_auth_token: nil, o_auth_scopes: nil, authorization_code_auth_credentials: nil, config: nil) ⇒ Client

Returns a new instance of Client.



107
108
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
135
136
137
138
139
140
141
# File 'lib/spotify_web_api/client.rb', line 107

def initialize(
  connection: nil, adapter: :net_http_persistent, timeout: 60,
  max_retries: 0, retry_interval: 1, backoff_factor: 2,
  retry_statuses: [408, 413, 429, 500, 502, 503, 504, 521, 522, 524],
  retry_methods: %i[get put], http_callback: nil,
  environment: Environment::PRODUCTION, o_auth_client_id: nil,
  o_auth_client_secret: nil, o_auth_redirect_uri: nil, o_auth_token: nil,
  o_auth_scopes: nil, authorization_code_auth_credentials: nil, config: nil
)
  @config = if config.nil?
              Configuration.new(
                connection: connection, adapter: adapter, timeout: timeout,
                max_retries: max_retries, retry_interval: retry_interval,
                backoff_factor: backoff_factor,
                retry_statuses: retry_statuses,
                retry_methods: retry_methods, http_callback: http_callback,
                environment: environment,
                o_auth_client_id: o_auth_client_id,
                o_auth_client_secret: o_auth_client_secret,
                o_auth_redirect_uri: o_auth_redirect_uri,
                o_auth_token: o_auth_token, o_auth_scopes: o_auth_scopes,
                authorization_code_auth_credentials: authorization_code_auth_credentials
              )
            else
              config
            end

  @global_configuration = GlobalConfiguration.new(client_configuration: @config)
                                             .base_uri_executor(@config.method(:get_base_uri))
                                             .global_errors(BaseController::GLOBAL_ERRORS)
                                             .user_agent(BaseController.user_agent)

  initialize_auth_managers(@global_configuration)
  @global_configuration = @global_configuration.auth_managers(@auth_managers)
end

Instance Attribute Details

#auth_managersObject (readonly)

Returns the value of attribute auth_managers.



10
11
12
# File 'lib/spotify_web_api/client.rb', line 10

def auth_managers
  @auth_managers
end

#configObject (readonly)

Returns the value of attribute config.



10
11
12
# File 'lib/spotify_web_api/client.rb', line 10

def config
  @config
end

Instance Method Details

#albumsAlbumsController

Access to albums controller.

Returns:



19
20
21
# File 'lib/spotify_web_api/client.rb', line 19

def albums
  @albums ||= AlbumsController.new @global_configuration
end

#artistsArtistsController

Access to artists controller.

Returns:



25
26
27
# File 'lib/spotify_web_api/client.rb', line 25

def artists
  @artists ||= ArtistsController.new @global_configuration
end

#audiobooksAudiobooksController

Access to audiobooks controller.

Returns:



31
32
33
# File 'lib/spotify_web_api/client.rb', line 31

def audiobooks
  @audiobooks ||= AudiobooksController.new @global_configuration
end

#categoriesCategoriesController

Access to categories controller.

Returns:



37
38
39
# File 'lib/spotify_web_api/client.rb', line 37

def categories
  @categories ||= CategoriesController.new @global_configuration
end

#chaptersChaptersController

Access to chapters controller.

Returns:



43
44
45
# File 'lib/spotify_web_api/client.rb', line 43

def chapters
  @chapters ||= ChaptersController.new @global_configuration
end

#episodesEpisodesController

Access to episodes controller.

Returns:



49
50
51
# File 'lib/spotify_web_api/client.rb', line 49

def episodes
  @episodes ||= EpisodesController.new @global_configuration
end

#genresGenresController

Access to genres controller.

Returns:



55
56
57
# File 'lib/spotify_web_api/client.rb', line 55

def genres
  @genres ||= GenresController.new @global_configuration
end

#initialize_auth_managers(global_config) ⇒ Object

Initializes the auth managers hash used for authenticating API calls.

Parameters:

  • global_config (GlobalConfiguration)

    The global configuration of the SDK)



145
146
147
148
149
150
151
152
# File 'lib/spotify_web_api/client.rb', line 145

def initialize_auth_managers(global_config)
  @auth_managers = {}
  http_client_config = global_config.client_configuration
  %w[oauth_2_0].each { |auth| @auth_managers[auth] = nil }
  @auth_managers['oauth_2_0'] = OAuth2.new(
    http_client_config.authorization_code_auth_credentials, global_config
  )
end

#marketsMarketsController

Access to markets controller.

Returns:



61
62
63
# File 'lib/spotify_web_api/client.rb', line 61

def markets
  @markets ||= MarketsController.new @global_configuration
end

#o_auth_authorizationOAuthAuthorizationController

Access to o_auth_authorization controller.

Returns:



103
104
105
# File 'lib/spotify_web_api/client.rb', line 103

def o_auth_authorization
  @o_auth_authorization ||= OAuthAuthorizationController.new @global_configuration
end

#oauth_2_0Object

Returns the configured authentication oauth_2_0 instance.



13
14
15
# File 'lib/spotify_web_api/client.rb', line 13

def oauth_2_0
  @auth_managers['oauth_2_0']
end

#playerPlayerController

Access to player controller.

Returns:



67
68
69
# File 'lib/spotify_web_api/client.rb', line 67

def player
  @player ||= PlayerController.new @global_configuration
end

#playlistsPlaylistsController

Access to playlists controller.

Returns:



73
74
75
# File 'lib/spotify_web_api/client.rb', line 73

def playlists
  @playlists ||= PlaylistsController.new @global_configuration
end

#searchSearchController

Access to search controller.

Returns:



79
80
81
# File 'lib/spotify_web_api/client.rb', line 79

def search
  @search ||= SearchController.new @global_configuration
end

#showsShowsController

Access to shows controller.

Returns:



85
86
87
# File 'lib/spotify_web_api/client.rb', line 85

def shows
  @shows ||= ShowsController.new @global_configuration
end

#tracksTracksController

Access to tracks controller.

Returns:



91
92
93
# File 'lib/spotify_web_api/client.rb', line 91

def tracks
  @tracks ||= TracksController.new @global_configuration
end

#usersUsersController

Access to users controller.

Returns:



97
98
99
# File 'lib/spotify_web_api/client.rb', line 97

def users
  @users ||= UsersController.new @global_configuration
end