Class: Dingtalk::Robot::TextStrategy

Inherits:
Object
  • Object
show all
Defined in:
lib/dingtalk/robot/strategies/text_strategy.rb

Overview

Text type strategy for sending message

Instance Method Summary collapse

Constructor Details

#initialize(webhook_url, message) ⇒ TextStrategy

Returns a new instance of TextStrategy.



7
8
9
10
# File 'lib/dingtalk/robot/strategies/text_strategy.rb', line 7

def initialize(webhook_url, message)
  @webhook_url = webhook_url
  @message = message
end

Instance Method Details

#notify(**options) ⇒ Object

Parameters:

  • options (Hash)

    a customizable set of options

Options Hash (**options):

  • :at_mobiles (Array<String>)
  • :is_at_all (Boolean)


14
15
16
17
18
19
20
21
22
23
# File 'lib/dingtalk/robot/strategies/text_strategy.rb', line 14

def notify(**options)
  at_mobiles = options[:at_mobiles].to_a
  is_at_all  = options[:is_at_all] ? true : false
  body = generate_body(at_mobiles, is_at_all)
  headers = {
    'Content-Type': 'application/json',
    Accept: 'application/json'
  }
  Net::HTTP.post(URI(webhook_url), body.to_json, headers).body
end