Class: SpotifyWebApi::Configuration
- Inherits:
-
CoreLibrary::HttpClientConfiguration
- Object
- CoreLibrary::HttpClientConfiguration
- SpotifyWebApi::Configuration
- Defined in:
- lib/spotify_web_api/configuration.rb
Overview
All configuration including auth info and base URI for the API access are configured in this class.
Constant Summary collapse
- ENVIRONMENTS =
All the environments the SDK can run in.
{ Environment::PRODUCTION => { Server::DEFAULT => 'https://api.spotify.com/v1', Server::AUTH_SERVER => 'https://accounts.spotify.com' } }.freeze
Class Attribute Summary collapse
-
.environments ⇒ Object
readonly
Returns the value of attribute environments.
Instance Attribute Summary collapse
-
#authorization_code_auth_credentials ⇒ Object
readonly
The attribute readers for properties.
-
#environment ⇒ Object
readonly
The attribute readers for properties.
Instance Method Summary collapse
- #clone_with(connection: nil, adapter: nil, timeout: nil, max_retries: nil, retry_interval: nil, backoff_factor: nil, retry_statuses: nil, retry_methods: nil, http_callback: nil, environment: nil, 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) ⇒ Object
- #create_auth_credentials_object(o_auth_client_id, o_auth_client_secret, o_auth_redirect_uri, o_auth_token, o_auth_scopes, authorization_code_auth_credentials) ⇒ Object
-
#get_base_uri(server = Server::DEFAULT) ⇒ String
Generates the appropriate base URI for the environment and the server.
-
#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) ⇒ Configuration
constructor
A new instance of Configuration.
- #o_auth_client_id ⇒ Object
- #o_auth_client_secret ⇒ Object
- #o_auth_redirect_uri ⇒ Object
- #o_auth_scopes ⇒ Object
- #o_auth_token ⇒ Object
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) ⇒ Configuration
Returns a new instance of Configuration.
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/spotify_web_api/configuration.rb', line 52 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 ) super 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 # Current API environment @environment = String(environment) # OAuth 2 Client ID @o_auth_client_id = o_auth_client_id # OAuth 2 Client Secret @o_auth_client_secret = o_auth_client_secret # OAuth 2 Redirection endpoint or Callback Uri @o_auth_redirect_uri = o_auth_redirect_uri # Object for storing information about the OAuth token @o_auth_token = if o_auth_token.is_a? OAuthToken OAuthToken.from_hash o_auth_token.to_hash else o_auth_token end # List of scopes that apply to the OAuth token @o_auth_scopes = o_auth_scopes # Initializing OAuth 2 Authorization Code Grant credentials with the provided auth parameters @authorization_code_auth_credentials = create_auth_credentials_object( o_auth_client_id, o_auth_client_secret, o_auth_redirect_uri, o_auth_token, o_auth_scopes, ) # The Http Client to use for making requests. set_http_client CoreLibrary::FaradayClient.new(self) end |
Class Attribute Details
.environments ⇒ Object (readonly)
Returns the value of attribute environments.
49 50 51 |
# File 'lib/spotify_web_api/configuration.rb', line 49 def environments @environments end |
Instance Attribute Details
#authorization_code_auth_credentials ⇒ Object (readonly)
The attribute readers for properties.
46 47 48 |
# File 'lib/spotify_web_api/configuration.rb', line 46 def @authorization_code_auth_credentials end |
#environment ⇒ Object (readonly)
The attribute readers for properties.
46 47 48 |
# File 'lib/spotify_web_api/configuration.rb', line 46 def environment @environment end |
Instance Method Details
#clone_with(connection: nil, adapter: nil, timeout: nil, max_retries: nil, retry_interval: nil, backoff_factor: nil, retry_statuses: nil, retry_methods: nil, http_callback: nil, environment: nil, 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) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/spotify_web_api/configuration.rb', line 99 def clone_with(connection: nil, adapter: nil, timeout: nil, max_retries: nil, retry_interval: nil, backoff_factor: nil, retry_statuses: nil, retry_methods: nil, http_callback: nil, environment: nil, 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) connection ||= self.connection adapter ||= self.adapter timeout ||= self.timeout max_retries ||= self.max_retries retry_interval ||= self.retry_interval backoff_factor ||= self.backoff_factor retry_statuses ||= self.retry_statuses retry_methods ||= self.retry_methods http_callback ||= self.http_callback environment ||= self.environment = create_auth_credentials_object( o_auth_client_id, o_auth_client_secret, o_auth_redirect_uri, o_auth_token, o_auth_scopes, || self. ) 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, authorization_code_auth_credentials: ) end |
#create_auth_credentials_object(o_auth_client_id, o_auth_client_secret, o_auth_redirect_uri, o_auth_token, o_auth_scopes, authorization_code_auth_credentials) ⇒ Object
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/spotify_web_api/configuration.rb', line 132 def create_auth_credentials_object(o_auth_client_id, o_auth_client_secret, o_auth_redirect_uri, o_auth_token, o_auth_scopes, ) return if o_auth_client_id.nil? && o_auth_client_secret.nil? && o_auth_redirect_uri.nil? && o_auth_token.nil? && o_auth_scopes.nil? warn('The \'o_auth_client_id\', \'o_auth_client_secret\', \'o_auth_redir'\ 'ect_uri\', \'o_auth_token\', \'o_auth_scopes\' params are deprecat'\ 'ed. Use \'authorization_code_auth_credentials\' param instead.') unless .nil? return .clone_with( 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 ) end AuthorizationCodeAuthCredentials.new( 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 ) end |
#get_base_uri(server = Server::DEFAULT) ⇒ String
Generates the appropriate base URI for the environment and the server. required.
176 177 178 |
# File 'lib/spotify_web_api/configuration.rb', line 176 def get_base_uri(server = Server::DEFAULT) ENVIRONMENTS[environment][server].clone end |
#o_auth_client_id ⇒ Object
25 26 27 |
# File 'lib/spotify_web_api/configuration.rb', line 25 def o_auth_client_id @authorization_code_auth_credentials.o_auth_client_id end |
#o_auth_client_secret ⇒ Object
29 30 31 |
# File 'lib/spotify_web_api/configuration.rb', line 29 def o_auth_client_secret @authorization_code_auth_credentials.o_auth_client_secret end |
#o_auth_redirect_uri ⇒ Object
33 34 35 |
# File 'lib/spotify_web_api/configuration.rb', line 33 def o_auth_redirect_uri @authorization_code_auth_credentials.o_auth_redirect_uri end |
#o_auth_scopes ⇒ Object
41 42 43 |
# File 'lib/spotify_web_api/configuration.rb', line 41 def o_auth_scopes @authorization_code_auth_credentials.o_auth_scopes end |
#o_auth_token ⇒ Object
37 38 39 |
# File 'lib/spotify_web_api/configuration.rb', line 37 def o_auth_token @authorization_code_auth_credentials.o_auth_token end |