Class: Schwab::Configuration
- Inherits:
-
Object
- Object
- Schwab::Configuration
- Defined in:
- lib/schwab/configuration.rb
Overview
Configuration storage for Schwab SDK
Instance Attribute Summary collapse
-
#api_base_url ⇒ String
Base URL for Schwab API (default: api.schwabapi.com).
-
#api_version ⇒ String
API version to use (default: v1).
-
#client_id ⇒ String
OAuth client ID from Schwab developer portal.
-
#client_secret ⇒ String
OAuth client secret from Schwab developer portal.
-
#faraday_adapter ⇒ Symbol
Faraday adapter to use (default: Faraday.default_adapter).
-
#logger ⇒ Logger?
Logger instance for debugging.
-
#max_retries ⇒ Integer
Maximum number of retries for failed requests (default: 3).
-
#open_timeout ⇒ Integer
Connection open timeout in seconds (default: 30).
-
#redirect_uri ⇒ String
OAuth callback URL configured in Schwab developer portal.
-
#response_format ⇒ Symbol
Response format (:hash or :resource, default: :hash) - :hash returns plain Ruby hashes (default, backward compatible) - :resource returns Sawyer::Resource-like objects with method access.
-
#retry_delay ⇒ Integer
Delay in seconds between retries (default: 1).
-
#timeout ⇒ Integer
Request timeout in seconds (default: 30).
Instance Method Summary collapse
-
#api_endpoint ⇒ Object
Get the full API endpoint URL with version.
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
-
#oauth_authorize_url ⇒ String
OAuth-specific endpoints.
-
#oauth_configured? ⇒ Boolean
Check if OAuth credentials are configured.
-
#oauth_token_url ⇒ String
Get the OAuth token endpoint URL.
-
#to_h ⇒ Object
Convert configuration to a hash.
-
#validate! ⇒ Object
Validate that required OAuth parameters are present.
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/schwab/configuration.rb', line 54 def initialize @api_base_url = "https://api.schwabapi.com" @api_version = "v1" @timeout = 30 @open_timeout = 30 @faraday_adapter = Faraday.default_adapter @max_retries = 3 @retry_delay = 1 @logger = nil @response_format = :hash end |
Instance Attribute Details
#api_base_url ⇒ String
Returns Base URL for Schwab API (default: api.schwabapi.com).
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/schwab/configuration.rb', line 40 attr_accessor :client_id, :client_secret, :redirect_uri, :api_base_url, :api_version, :logger, :timeout, :open_timeout, :faraday_adapter, :max_retries, :retry_delay |
#api_version ⇒ String
Returns API version to use (default: v1).
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/schwab/configuration.rb', line 40 attr_accessor :client_id, :client_secret, :redirect_uri, :api_base_url, :api_version, :logger, :timeout, :open_timeout, :faraday_adapter, :max_retries, :retry_delay |
#client_id ⇒ String
Returns OAuth client ID from Schwab developer portal.
40 41 42 |
# File 'lib/schwab/configuration.rb', line 40 def client_id @client_id end |
#client_secret ⇒ String
Returns OAuth client secret from Schwab developer portal.
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/schwab/configuration.rb', line 40 attr_accessor :client_id, :client_secret, :redirect_uri, :api_base_url, :api_version, :logger, :timeout, :open_timeout, :faraday_adapter, :max_retries, :retry_delay |
#faraday_adapter ⇒ Symbol
Returns Faraday adapter to use (default: Faraday.default_adapter).
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/schwab/configuration.rb', line 40 attr_accessor :client_id, :client_secret, :redirect_uri, :api_base_url, :api_version, :logger, :timeout, :open_timeout, :faraday_adapter, :max_retries, :retry_delay |
#logger ⇒ Logger?
Returns Logger instance for debugging.
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/schwab/configuration.rb', line 40 attr_accessor :client_id, :client_secret, :redirect_uri, :api_base_url, :api_version, :logger, :timeout, :open_timeout, :faraday_adapter, :max_retries, :retry_delay |
#max_retries ⇒ Integer
Returns Maximum number of retries for failed requests (default: 3).
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/schwab/configuration.rb', line 40 attr_accessor :client_id, :client_secret, :redirect_uri, :api_base_url, :api_version, :logger, :timeout, :open_timeout, :faraday_adapter, :max_retries, :retry_delay |
#open_timeout ⇒ Integer
Returns Connection open timeout in seconds (default: 30).
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/schwab/configuration.rb', line 40 attr_accessor :client_id, :client_secret, :redirect_uri, :api_base_url, :api_version, :logger, :timeout, :open_timeout, :faraday_adapter, :max_retries, :retry_delay |
#redirect_uri ⇒ String
Returns OAuth callback URL configured in Schwab developer portal.
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/schwab/configuration.rb', line 40 attr_accessor :client_id, :client_secret, :redirect_uri, :api_base_url, :api_version, :logger, :timeout, :open_timeout, :faraday_adapter, :max_retries, :retry_delay |
#response_format ⇒ Symbol
Returns Response format (:hash or :resource, default: :hash)
-
:hash returns plain Ruby hashes (default, backward compatible)
-
:resource returns Sawyer::Resource-like objects with method access.
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/schwab/configuration.rb', line 40 attr_accessor :client_id, :client_secret, :redirect_uri, :api_base_url, :api_version, :logger, :timeout, :open_timeout, :faraday_adapter, :max_retries, :retry_delay |
#retry_delay ⇒ Integer
Returns Delay in seconds between retries (default: 1).
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/schwab/configuration.rb', line 40 attr_accessor :client_id, :client_secret, :redirect_uri, :api_base_url, :api_version, :logger, :timeout, :open_timeout, :faraday_adapter, :max_retries, :retry_delay |
#timeout ⇒ Integer
Returns Request timeout in seconds (default: 30).
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/schwab/configuration.rb', line 40 attr_accessor :client_id, :client_secret, :redirect_uri, :api_base_url, :api_version, :logger, :timeout, :open_timeout, :faraday_adapter, :max_retries, :retry_delay |
Instance Method Details
#api_endpoint ⇒ Object
Get the full API endpoint URL with version
82 83 84 |
# File 'lib/schwab/configuration.rb', line 82 def api_endpoint "#{api_base_url}/#{api_version}" end |
#oauth_authorize_url ⇒ String
OAuth-specific endpoints
88 89 90 |
# File 'lib/schwab/configuration.rb', line 88 def "#{api_base_url}/v1/oauth/authorize" end |
#oauth_configured? ⇒ Boolean
Check if OAuth credentials are configured
119 120 121 |
# File 'lib/schwab/configuration.rb', line 119 def oauth_configured? !client_id.nil? && !client_secret.nil? && !redirect_uri.nil? end |
#oauth_token_url ⇒ String
Get the OAuth token endpoint URL
94 95 96 |
# File 'lib/schwab/configuration.rb', line 94 def oauth_token_url "#{api_base_url}/v1/oauth/token" end |
#to_h ⇒ Object
Convert configuration to a hash
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/schwab/configuration.rb', line 124 def to_h { client_id: client_id, client_secret: client_secret, redirect_uri: redirect_uri, api_base_url: api_base_url, timeout: timeout, open_timeout: open_timeout, faraday_adapter: faraday_adapter, max_retries: max_retries, retry_delay: retry_delay, logger: logger, response_format: response_format, } end |
#validate! ⇒ Object
Validate that required OAuth parameters are present
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/schwab/configuration.rb', line 99 def validate! missing = [] missing << "client_id" if client_id.nil? || client_id.empty? missing << "client_secret" if client_secret.nil? || client_secret.empty? missing << "redirect_uri" if redirect_uri.nil? || redirect_uri.empty? unless missing.empty? raise Error, "Missing required configuration: #{missing.join(", ")}" end # Validate response_format valid_formats = [:hash, :resource] unless valid_formats.include?(response_format) raise Error, "Invalid response_format: #{response_format}. Must be :hash or :resource" end true end |