Module: WOTC::Configuration
- Included in:
- WOTC
- Defined in:
- lib/wotc/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
[ :access_token, :adapter, :connection_options, :host, :endpoint, :format, :proxy, :user_agent, :auto_paginate, :per_page, :timeout, :open_timeout, ].freeze
- DEFAULT_ACCESS_TOKEN =
By default, don’t set an access token
nil
- DEFAULT_AUTO_PAGINATE =
By default, enable auto-paginate
true
- DEFAULT_PER_PAGE =
By default, return 20 resources per page when there is an pagination.
20
- DEFAULT_ADAPTER =
Note:
The default faraday adapter is Net::HTTP.
The adapter that will be used to connect if none is set
Faraday.default_adapter
- DEFAULT_CONNECTION_OPTIONS =
By default, don’t set connection options.
{}
- DEFAULT_TIMEOUT =
Default timeout time is 20 seconds
20
- DEFAULT_OPEN_TIMEOUT =
By default, the open timeout is 20 seconds.
20
- DEFAULT_HOST =
By default, use sandbox environment
'https://sandbox.wotc.com'.freeze
- DEFAULT_ENDPOINT =
The endpoint that will be used to connect if none is set
'https://sandbox.wotc.com/portal/api/v1/'.freeze
- DEFAULT_FORMAT =
Note:
JSON is the only available format at this time
The response format appended to the path and sent in the ‘Accept’ header if none is set
:json
- DEFAULT_PROXY =
By default, don’t use a proxy server
nil
- DEFAULT_USER_AGENT =
The user agent that will be sent to the API endpoint if none is set
"WOTC Ruby Gem #{WOTC::VERSION}".freeze
- VALID_FORMATS =
An array of valid request/response formats
[:json].freeze
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
70 71 72 |
# File 'lib/wotc/configuration.rb', line 70 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
75 76 77 |
# File 'lib/wotc/configuration.rb', line 75 def configure yield self end |
#options ⇒ Object
Create a hash of options and their values
80 81 82 83 84 |
# File 'lib/wotc/configuration.rb', line 80 def VALID_OPTIONS_KEYS.inject({}) do |option, key| option.merge!(key => send(key)) end end |
#reset ⇒ Object
Reset all configuration options to defaults
87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/wotc/configuration.rb', line 87 def reset self.access_token = DEFAULT_ACCESS_TOKEN self.adapter = DEFAULT_ADAPTER self. = DEFAULT_CONNECTION_OPTIONS self.host = DEFAULT_HOST self.endpoint = DEFAULT_ENDPOINT self.format = DEFAULT_FORMAT self.proxy = DEFAULT_PROXY self.user_agent = DEFAULT_USER_AGENT self.auto_paginate = DEFAULT_AUTO_PAGINATE self.per_page = DEFAULT_PER_PAGE self.timeout = DEFAULT_TIMEOUT self.open_timeout = DEFAULT_OPEN_TIMEOUT end |