Class: Billrb::Configuration
- Inherits:
-
Object
- Object
- Billrb::Configuration
- Defined in:
- lib/billrb/configuration.rb
Constant Summary collapse
- ENVIRONMENTS =
{ production: "https://gateway.prod.bill.com", sandbox: "https://gateway.stage.bill.com", }.freeze
- SECRET_ATTRS =
%i[password dev_key].freeze
Instance Attribute Summary collapse
-
#adapter ⇒ Object
Returns the value of attribute adapter.
-
#dev_key ⇒ Object
Returns the value of attribute dev_key.
-
#environment ⇒ Object
Returns the value of attribute environment.
-
#faraday ⇒ Object
Returns the value of attribute faraday.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#max_retries ⇒ Object
Returns the value of attribute max_retries.
-
#open_timeout ⇒ Object
Returns the value of attribute open_timeout.
-
#organization_id ⇒ Object
Returns the value of attribute organization_id.
-
#password ⇒ Object
Returns the value of attribute password.
-
#retry_backoff ⇒ Object
Returns the value of attribute retry_backoff.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
-
#username ⇒ Object
Returns the value of attribute username.
Instance Method Summary collapse
- #base_url ⇒ Object
-
#initialize(username: nil, password: nil, organization_id: nil, dev_key: nil, environment: :sandbox, timeout: 30, open_timeout: 5, logger: nil, max_retries: 2, retry_backoff: 0.5, adapter: nil, faraday: nil) ⇒ Configuration
constructor
A new instance of Configuration.
-
#inspect ⇒ Object
Redact credentials so they never leak into logs or error dumps.
- #validate! ⇒ Object
Constructor Details
#initialize(username: nil, password: nil, organization_id: nil, dev_key: nil, environment: :sandbox, timeout: 30, open_timeout: 5, logger: nil, max_retries: 2, retry_backoff: 0.5, adapter: nil, faraday: nil) ⇒ Configuration
Returns a new instance of Configuration.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/billrb/configuration.rb', line 17 def initialize(username: nil, password: nil, organization_id: nil, dev_key: nil, environment: :sandbox, timeout: 30, open_timeout: 5, logger: nil, max_retries: 2, retry_backoff: 0.5, adapter: nil, faraday: nil) self.environment = environment @username = username @password = password @organization_id = organization_id @dev_key = dev_key @timeout = timeout @open_timeout = open_timeout @logger = logger @max_retries = max_retries @retry_backoff = retry_backoff @adapter = adapter @faraday = faraday end |
Instance Attribute Details
#adapter ⇒ Object
Returns the value of attribute adapter.
12 13 14 |
# File 'lib/billrb/configuration.rb', line 12 def adapter @adapter end |
#dev_key ⇒ Object
Returns the value of attribute dev_key.
12 13 14 |
# File 'lib/billrb/configuration.rb', line 12 def dev_key @dev_key end |
#environment ⇒ Object
Returns the value of attribute environment.
15 16 17 |
# File 'lib/billrb/configuration.rb', line 15 def environment @environment end |
#faraday ⇒ Object
Returns the value of attribute faraday.
12 13 14 |
# File 'lib/billrb/configuration.rb', line 12 def faraday @faraday end |
#logger ⇒ Object
Returns the value of attribute logger.
12 13 14 |
# File 'lib/billrb/configuration.rb', line 12 def logger @logger end |
#max_retries ⇒ Object
Returns the value of attribute max_retries.
12 13 14 |
# File 'lib/billrb/configuration.rb', line 12 def max_retries @max_retries end |
#open_timeout ⇒ Object
Returns the value of attribute open_timeout.
12 13 14 |
# File 'lib/billrb/configuration.rb', line 12 def open_timeout @open_timeout end |
#organization_id ⇒ Object
Returns the value of attribute organization_id.
12 13 14 |
# File 'lib/billrb/configuration.rb', line 12 def organization_id @organization_id end |
#password ⇒ Object
Returns the value of attribute password.
12 13 14 |
# File 'lib/billrb/configuration.rb', line 12 def password @password end |
#retry_backoff ⇒ Object
Returns the value of attribute retry_backoff.
12 13 14 |
# File 'lib/billrb/configuration.rb', line 12 def retry_backoff @retry_backoff end |
#timeout ⇒ Object
Returns the value of attribute timeout.
12 13 14 |
# File 'lib/billrb/configuration.rb', line 12 def timeout @timeout end |
#username ⇒ Object
Returns the value of attribute username.
12 13 14 |
# File 'lib/billrb/configuration.rb', line 12 def username @username end |
Instance Method Details
#base_url ⇒ Object
43 44 45 |
# File 'lib/billrb/configuration.rb', line 43 def base_url ENVIRONMENTS.fetch(environment) end |
#inspect ⇒ Object
Redact credentials so they never leak into logs or error dumps.
57 58 59 60 61 |
# File 'lib/billrb/configuration.rb', line 57 def inspect "#<#{self.class.name} environment=#{environment.inspect} " \ "username=#{username.inspect} organization_id=#{organization_id.inspect} " \ "password=#{redacted(password)} dev_key=#{redacted(dev_key)}>" end |
#validate! ⇒ Object
47 48 49 50 51 52 53 54 |
# File 'lib/billrb/configuration.rb', line 47 def validate! missing = %i[username password organization_id dev_key].select do |key| public_send(key).to_s.empty? end return if missing.empty? raise ConfigurationError, "missing required configuration: #{missing.join(", ")}" end |