Class: DPay::Config
- Inherits:
-
Object
- Object
- DPay::Config
- Defined in:
- lib/dpay/config.rb,
sig/dpay/config.rbs
Constant Summary collapse
- DEFAULT_TIMEOUT =
30
Instance Attribute Summary collapse
-
#base_urls ⇒ Internal::BaseUrls
readonly
Returns the value of attribute base_urls.
-
#http_client ⇒ Object
readonly
Returns the value of attribute http_client.
-
#secret_hash ⇒ String
readonly
Returns the value of attribute secret_hash.
-
#service ⇒ String
readonly
Returns the value of attribute service.
-
#timeout ⇒ Integer
readonly
Returns the value of attribute timeout.
Instance Method Summary collapse
-
#initialize(service:, secret_hash:, timeout: DEFAULT_TIMEOUT, http_client: nil, base_urls: nil) ⇒ Config
constructor
A new instance of Config.
- #non_empty_string(value, name) ⇒ String
- #positive_integer(value) ⇒ Integer
- #transport(value) ⇒ Object
Constructor Details
#initialize(service:, secret_hash:, timeout: DEFAULT_TIMEOUT, http_client: nil, base_urls: nil) ⇒ Config
Returns a new instance of Config.
9 10 11 12 13 14 15 16 |
# File 'lib/dpay/config.rb', line 9 def initialize(service:, secret_hash:, timeout: DEFAULT_TIMEOUT, http_client: nil, base_urls: nil) @service = non_empty_string(service, "service") @secret_hash = non_empty_string(secret_hash, "secret_hash") @timeout = positive_integer(timeout) @http_client = transport(http_client) @base_urls = Internal::BaseUrls.new(base_urls || {}) freeze end |
Instance Attribute Details
#base_urls ⇒ Internal::BaseUrls (readonly)
Returns the value of attribute base_urls.
7 8 9 |
# File 'lib/dpay/config.rb', line 7 def base_urls @base_urls end |
#http_client ⇒ Object (readonly)
Returns the value of attribute http_client.
7 8 9 |
# File 'lib/dpay/config.rb', line 7 def http_client @http_client end |
#secret_hash ⇒ String (readonly)
Returns the value of attribute secret_hash.
7 8 9 |
# File 'lib/dpay/config.rb', line 7 def secret_hash @secret_hash end |
#service ⇒ String (readonly)
Returns the value of attribute service.
7 8 9 |
# File 'lib/dpay/config.rb', line 7 def service @service end |
#timeout ⇒ Integer (readonly)
Returns the value of attribute timeout.
7 8 9 |
# File 'lib/dpay/config.rb', line 7 def timeout @timeout end |
Instance Method Details
#non_empty_string(value, name) ⇒ String
20 21 22 23 24 |
# File 'lib/dpay/config.rb', line 20 def non_empty_string(value, name) raise InvalidArgumentError, "#{name} must be a non-empty String" unless value.is_a?(String) && !value.empty? value end |
#positive_integer(value) ⇒ Integer
26 27 28 29 30 |
# File 'lib/dpay/config.rb', line 26 def positive_integer(value) raise InvalidArgumentError, "timeout must be an Integer >= 1" unless value.is_a?(Integer) && value >= 1 value end |
#transport(value) ⇒ Object
32 33 34 35 36 37 |
# File 'lib/dpay/config.rb', line 32 def transport(value) return nil if value.nil? raise InvalidArgumentError, "http_client must respond to #request" unless value.respond_to?(:request) value end |