Class: ActiveNotifier::NotifierAdapters::Dingtalk
- Inherits:
-
ActiveAdapter::Implement
- Object
- ActiveAdapter::Implement
- ActiveNotifier::NotifierAdapters::Dingtalk
- Defined in:
- lib/active_notifier/notifier_adapters/dingtalk.rb
Constant Summary collapse
- VALID_TYPES =
%i[text markdown].freeze
Instance Method Summary collapse
-
#notify(token, type, message, **options) ⇒ Object
abstract
Notify message.
Instance Method Details
#notify(token, type, message, **options) ⇒ Object
This method is abstract.
Implement through setting a real adapter, like :dingtalk
Notify message
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/active_notifier/notifier_adapters/dingtalk.rb', line 10 def notify(token, type, , **) webhook = "#{ActiveNotifier.config.adapters_with_base_url.fetch(:dingtalk)}#{token}" unless VALID_TYPES.include?(type) = "The Dingtalk adapter only support types: #{VALID_TYPES.join(', ')}" raise ActiveNotifier::AdapterError, end if .empty? = "Message of the Dingtalk adapter can't be blank, please check template file" raise ActiveNotifier::AdapterError, end at_mobiles = [:at_mobiles].to_a is_at_all = !![:is_at_all] body = case type when :text get_text_body(, at_mobiles, is_at_all) when :markdown title = [:title].to_s raise ActiveNotifier::AdapterError, "Dingtalk adapter require other options: title" if title.empty? get_markdown_body(title, , at_mobiles, is_at_all) end headers = { 'Content-Type' => 'application/json', 'Accept' => 'application/json' } Net::HTTP.post(URI(webhook), body.to_json, headers) end |