Class: Dingding::Notifier
- Inherits:
-
Object
- Object
- Dingding::Notifier
- Defined in:
- lib/dingding-notifier.rb,
lib/dingding-notifier/config.rb,
lib/dingding-notifier/version.rb,
lib/dingding-notifier/util/http_client.rb,
lib/dingding-notifier/payload_middleware.rb,
lib/dingding-notifier/payload_middleware/base.rb,
lib/dingding-notifier/payload_middleware/stack.rb,
lib/dingding-notifier/payload_middleware/format_link.rb,
lib/dingding-notifier/payload_middleware/format_text.rb,
lib/dingding-notifier/payload_middleware/format_markdown.rb,
lib/dingding-notifier/payload_middleware/format_feed_card.rb,
lib/dingding-notifier/payload_middleware/format_action_card.rb
Defined Under Namespace
Modules: Util Classes: APIError, Config, PayloadMiddleware
Constant Summary collapse
- VERSION =
rubocop:disable Style/RedundantFreeze
"0.0.1.1".freeze
Instance Attribute Summary collapse
-
#atMobiles ⇒ Object
readonly
Returns the value of attribute atMobiles.
-
#atUserIds ⇒ Object
readonly
Returns the value of attribute atUserIds.
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#isAtAll ⇒ Object
readonly
Returns the value of attribute isAtAll.
-
#middleware_name ⇒ Object
readonly
Returns the value of attribute middleware_name.
-
#webhook_url ⇒ Object
readonly
Returns the value of attribute webhook_url.
Instance Method Summary collapse
- #call(message, options = {}) ⇒ Object
- #config ⇒ Object
-
#initialize(options = {}) ⇒ Notifier
constructor
A new instance of Notifier.
- #post(payload = {}) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Notifier
Returns a new instance of Notifier.
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/dingding-notifier.rb', line 17 def initialize(={}) @webhook_url = .delete(:webhook_url) @client = config.http_client @atMobiles = .delete(:atMobiles) || [] @atUserIds = .delete(:atUserIds) || [] @isAtAll = .delete(:isAtAll) || false @middleware_name = config.middleware(.delete(:middleware)) if @middleware_name.is_a?(Array) @middleware_name = @middleware_name.first end middleware.set (@middleware_name) end |
Instance Attribute Details
#atMobiles ⇒ Object (readonly)
Returns the value of attribute atMobiles.
15 16 17 |
# File 'lib/dingding-notifier.rb', line 15 def atMobiles @atMobiles end |
#atUserIds ⇒ Object (readonly)
Returns the value of attribute atUserIds.
15 16 17 |
# File 'lib/dingding-notifier.rb', line 15 def atUserIds @atUserIds end |
#client ⇒ Object (readonly)
Returns the value of attribute client.
15 16 17 |
# File 'lib/dingding-notifier.rb', line 15 def client @client end |
#isAtAll ⇒ Object (readonly)
Returns the value of attribute isAtAll.
15 16 17 |
# File 'lib/dingding-notifier.rb', line 15 def isAtAll @isAtAll end |
#middleware_name ⇒ Object (readonly)
Returns the value of attribute middleware_name.
15 16 17 |
# File 'lib/dingding-notifier.rb', line 15 def middleware_name @middleware_name end |
#webhook_url ⇒ Object (readonly)
Returns the value of attribute webhook_url.
15 16 17 |
# File 'lib/dingding-notifier.rb', line 15 def webhook_url @webhook_url end |
Instance Method Details
#call(message, options = {}) ⇒ Object
34 35 36 37 38 |
# File 'lib/dingding-notifier.rb', line 34 def call , ={} [:format_text] ||= {} [:format_text][:text] = .to_json post end |
#config ⇒ Object
30 31 32 |
# File 'lib/dingding-notifier.rb', line 30 def config @_config ||= Config.new end |
#post(payload = {}) ⇒ Object
40 41 42 43 44 |
# File 'lib/dingding-notifier.rb', line 40 def post payload={} payload = {middleware_name.to_sym => payload} unless payload.key?(middleware_name) payload.merge!({atMobiles: atMobiles, atUserIds: atUserIds,isAtAll: isAtAll}) client.post webhook_url, middleware.call(payload).to_json end |