Module: DingBot::Configuration
- Included in:
- DingBot
- Defined in:
- lib/dingbot/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 DingBot::API.
[:endpoint, :access_token, :httparty, :secret].freeze
- DEFAULT_USER_AGENT =
The user agent that will be sent to the API endpoint if none is set.
"DingBot Ruby Gem #{DingBot::VERSION}".freeze
- DEFAULT_ENDPOINT =
"https://oapi.dingtalk.com/robot/send"
Class Method Summary collapse
-
.extended(base) ⇒ Object
Sets all configuration options to their default values when this module is extended.
Instance Method Summary collapse
-
#configure {|_self| ... } ⇒ Object
Convenience method to allow configuration options to be set in a block.
-
#options ⇒ Object
Creates a hash of options and their values.
-
#reset ⇒ Object
Resets all configuration options to the defaults.
Class Method Details
.extended(base) ⇒ Object
Sets all configuration options to their default values when this module is extended.
17 18 19 |
# File 'lib/dingbot/configuration.rb', line 17 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.
22 23 24 |
# File 'lib/dingbot/configuration.rb', line 22 def configure yield self end |
#options ⇒ Object
Creates a hash of options and their values.
27 28 29 30 31 |
# File 'lib/dingbot/configuration.rb', line 27 def VALID_OPTIONS_KEYS.inject({}) do |option, key| option.merge!(key => send(key)) end end |
#reset ⇒ Object
Resets all configuration options to the defaults.
34 35 36 37 38 |
# File 'lib/dingbot/configuration.rb', line 34 def reset self.endpoint = ENV['DINGTALK_ENDPOINT'] || DEFAULT_ENDPOINT self.access_token = ENV['DINGTALK_ACCESS_TOKEN'] self.secret = ENV['DINGTALK_SECRET'] end |