Module: Stamps::Configuration
- Included in:
- Stamps
- Defined in:
- lib/stamps/configuration.rb
Overview
Defines constants and methods related to configuration
Constant Summary collapse
- VALID_OPTIONS_KEYS =
An array of valid keys in the options hash when configuring a API
[ :integration_id, :username, :password, :namespace, :format, :return_address, :test_mode, :raise_errors, :log_messages, :open_timeout, :read_timeout, :endpoint].freeze
- DEFAULT_ENDPOINT =
The endpoint that will be used to connect if none is set
'https://swsim.stamps.com/swsim/swsimv29.asmx'.freeze
- DEFAULT_NAMESPACE =
The default namespace used on Stamps.com wsdl
'http://stamps.com/xml/namespace/2010/11/swsim/swsimv29'
- DEFAULT_FORMAT =
Note:
JSON is preferred over XML because it is more concise and faster to parse.
:hash
- DEFAULT_USER_AGENT =
The user agent that will be sent to the API endpoint if none is set
"Stamps Ruby Gem".freeze
- DEFAULT_RAISE_ERRORS =
Do not raise errors by default
false
- DEFAULT_LOG_MESSAGES =
Do not log requests and response by default
false
Class Method Summary collapse
-
.extended(base) ⇒ Object
When this module is extended, set all configuration options to their default values.
Instance Method Summary collapse
-
#configure {|_self| ... } ⇒ Object
Convenience method to allow configuration options to be set in a block.
-
#options ⇒ Object
Create a hash of options and their values.
-
#reset ⇒ Object
Reset all configuration options to defaults.
Class Method Details
.extended(base) ⇒ Object
When this module is extended, set all configuration options to their default values
42 43 44 |
# File 'lib/stamps/configuration.rb', line 42 def self.extended(base) base.reset end |
Instance Method Details
#configure {|_self| ... } ⇒ Object
Convenience method to allow configuration options to be set in a block
47 48 49 50 51 52 53 54 55 |
# File 'lib/stamps/configuration.rb', line 47 def configure yield self HTTPI.log = false # Savon.configure do |config| # config.log = self.log_messages # config.raise_errors = self.raise_errors # end end |
#options ⇒ Object
Create a hash of options and their values
58 59 60 |
# File 'lib/stamps/configuration.rb', line 58 def Hash[VALID_OPTIONS_KEYS.map {|key| [key, send(key)] }] end |
#reset ⇒ Object
Reset all configuration options to defaults
63 64 65 66 67 68 69 70 71 |
# File 'lib/stamps/configuration.rb', line 63 def reset self.endpoint = DEFAULT_ENDPOINT self.namespace = DEFAULT_NAMESPACE self.format = DEFAULT_FORMAT self. = DEFAULT_LOG_MESSAGES self.raise_errors = DEFAULT_RAISE_ERRORS self.open_timeout = 30 self.read_timeout = 30 end |