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

Instance Method Summary collapse

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.

Yields:

  • (_self)

Yield Parameters:



22
23
24
# File 'lib/dingbot/configuration.rb', line 22

def configure
  yield self
end

#optionsObject

Creates a hash of options and their values.



27
28
29
30
31
# File 'lib/dingbot/configuration.rb', line 27

def options
  VALID_OPTIONS_KEYS.inject({}) do |option, key|
    option.merge!(key => send(key))
  end
end

#resetObject

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