Module: Wdt::Configuration
- Included in:
- Wdt
- Defined in:
- lib/wdt/configuration.rb
Overview
Defines constants and methods related to configuration
Constant Summary collapse
- VALID_OPTIONS_KEYS =
An array of Wangdiantong keys in the options hash when configuring a API
[ :sid, :appkey, :appsecret, :endpoint, :shop_no, :format, :user_agent ].freeze
- DEFAULT_SID =
By default, don’t set a seller ID
nil
- DEFAULT_APP_KEY =
By default, don’t set an application key.
nil
- DEFAULT_ENDPOINT =
Note:
There is no reason to use any other endpoint at this time
todo 补充旺店通默认的 endpoint The endpoint that will be used to connect if none is set
'https://api..com/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_SHOP_NO =
By defalut, don’t set a shop number
nil
- DEFAULT_APP_SECRET =
By default, don’t set a app secret
nil
- DEFAULT_USER_AGENT =
The user agent that will be sent to the API endpoint if none is set
"Wang Dian Tong Ruby Gem #{Wdt::VERSION}".freeze
- VALID_FORMATS =
Note:
Not all methods support the XML format.
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
54 55 56 |
# File 'lib/wdt/configuration.rb', line 54 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
59 60 61 |
# File 'lib/wdt/configuration.rb', line 59 def configure yield self end |
#options ⇒ Object
Create a hash of options and their values
64 65 66 67 68 |
# File 'lib/wdt/configuration.rb', line 64 def VALID_OPTIONS_KEYS.inject({}) do |option, key| option.merge!(key => send(key)) end end |
#reset ⇒ Object
Reset all configuration options to defaults
71 72 73 74 75 76 77 78 79 |
# File 'lib/wdt/configuration.rb', line 71 def reset self.sid = DEFAULT_SID self.appkey = DEFAULT_APP_KEY self.appsecret = DEFAULT_APP_SECRET self.endpoint = DEFAULT_ENDPOINT self.shop_no = DEFAULT_SHOP_NO self.format = DEFAULT_FORMAT self.user_agent = DEFAULT_USER_AGENT end |