Class: ActiveNotifier::DingtalkAdapter
- Inherits:
-
Object
- Object
- ActiveNotifier::DingtalkAdapter
- Defined in:
- lib/active_notifier/adapters/dingtalk_adapter.rb
Constant Summary collapse
- VALID_TYPES =
i[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
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/active_notifier/adapters/dingtalk_adapter.rb', line 6 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::AdapterTypeInvalidError, end raise ActiveNotifier::MessageBlankError, "message can't be blank, please check template file" if .empty? title = [:title]&.to_s raise ActiveNotifier::AdapterOptionsInvalidError, "Dingtalk adapter require other options: title" if title.empty? body = { 'msgtype' => type, type => { 'title': title, 'text': } } headers = { 'Content-Type' => 'application/json', 'Accept' => 'application/json' } Net::HTTP.post(URI(webhook), body.to_json, headers) end |