Class: Dingtalk::Robot::ActionCardStrategy

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

Overview

Markdown type strategy for sending message

Instance Method Summary collapse

Constructor Details

#initialize(webhook_url, message) ⇒ ActionCardStrategy

Returns a new instance of ActionCardStrategy.



7
8
9
10
# File 'lib/dingtalk/robot/strategies/action_card_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):

  • :title (String)
  • :single_title (String)
  • :single_url (String)
  • :hide_avatar (Integer) — default: 0

    0-show, 1-hide

Raises:

  • (ArgumentError)


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/dingtalk/robot/strategies/action_card_strategy.rb', line 16

def notify(**options)
  title = options[:title].to_s
  raise ArgumentError, 'title must be present, strategy: action_card' if title.empty?
  single_title = options[:single_title].to_s
  raise ArgumentError, 'single_title must be present, strategy: action_card' if single_title.empty?
  single_url = options[:single_url].to_s
  raise ArgumentError, 'single_url must be present, strategy: action_card' if single_url.empty?
  hide_avatar = options[:hide_avatar].to_i
  body = generate_body(title, single_title, single_url, hide_avatar)
  headers = {
    'Content-Type': 'application/json',
    Accept: 'application/json'
  }
  Net::HTTP.post(URI(webhook_url), body.to_json, headers).body
end