Class: Postscale::Configuration
- Inherits:
-
Object
- Object
- Postscale::Configuration
- Defined in:
- lib/postscale/configuration.rb
Constant Summary collapse
- DEFAULT_BASE_URL =
"https://api.postscale.io"- DEFAULT_TIMEOUT =
30- DEFAULT_MAX_RETRIES =
3
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#base_url ⇒ Object
readonly
Returns the value of attribute base_url.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#max_retries ⇒ Object
readonly
Returns the value of attribute max_retries.
-
#sleeper ⇒ Object
readonly
Returns the value of attribute sleeper.
-
#timeout ⇒ Object
readonly
Returns the value of attribute timeout.
-
#transport ⇒ Object
readonly
Returns the value of attribute transport.
Instance Method Summary collapse
-
#initialize(api_key:, base_url: DEFAULT_BASE_URL, timeout: DEFAULT_TIMEOUT, max_retries: DEFAULT_MAX_RETRIES, headers: nil, transport: nil, sleeper: nil) ⇒ Configuration
constructor
A new instance of Configuration.
- #live? ⇒ Boolean
- #test? ⇒ Boolean
- #validate! ⇒ Object
Constructor Details
#initialize(api_key:, base_url: DEFAULT_BASE_URL, timeout: DEFAULT_TIMEOUT, max_retries: DEFAULT_MAX_RETRIES, headers: nil, transport: nil, sleeper: nil) ⇒ Configuration
Returns a new instance of Configuration.
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/postscale/configuration.rb', line 11 def initialize(api_key:, base_url: DEFAULT_BASE_URL, timeout: DEFAULT_TIMEOUT, max_retries: DEFAULT_MAX_RETRIES, headers: nil, transport: nil, sleeper: nil) @api_key = api_key @base_url = base_url.chomp("/") @timeout = timeout @max_retries = max_retries @headers = headers || {} @transport = transport @sleeper = sleeper || Kernel.method(:sleep) validate! end |
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
9 10 11 |
# File 'lib/postscale/configuration.rb', line 9 def api_key @api_key end |
#base_url ⇒ Object (readonly)
Returns the value of attribute base_url.
9 10 11 |
# File 'lib/postscale/configuration.rb', line 9 def base_url @base_url end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
9 10 11 |
# File 'lib/postscale/configuration.rb', line 9 def headers @headers end |
#max_retries ⇒ Object (readonly)
Returns the value of attribute max_retries.
9 10 11 |
# File 'lib/postscale/configuration.rb', line 9 def max_retries @max_retries end |
#sleeper ⇒ Object (readonly)
Returns the value of attribute sleeper.
9 10 11 |
# File 'lib/postscale/configuration.rb', line 9 def sleeper @sleeper end |
#timeout ⇒ Object (readonly)
Returns the value of attribute timeout.
9 10 11 |
# File 'lib/postscale/configuration.rb', line 9 def timeout @timeout end |
#transport ⇒ Object (readonly)
Returns the value of attribute transport.
9 10 11 |
# File 'lib/postscale/configuration.rb', line 9 def transport @transport end |
Instance Method Details
#live? ⇒ Boolean
32 33 34 |
# File 'lib/postscale/configuration.rb', line 32 def live? @api_key.start_with?("ps_live_") end |
#test? ⇒ Boolean
36 37 38 |
# File 'lib/postscale/configuration.rb', line 36 def test? @api_key.start_with?("ps_test_") end |
#validate! ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/postscale/configuration.rb', line 23 def validate! raise ConfigurationError, "API key is required" if @api_key.nil? || @api_key.strip.empty? raise ConfigurationError, "Timeout must be a positive number" unless @timeout.is_a?(Numeric) && @timeout.positive? unless @max_retries.is_a?(Integer) && @max_retries >= 0 raise ConfigurationError, "max_retries must be a non-negative integer" end end |