Class: Dingtalk::Robot::FeedCardStrategy

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

Overview

Markdown type strategy for sending message

Defined Under Namespace

Classes: Link

Instance Method Summary collapse

Constructor Details

#initialize(webhook_url, message) ⇒ FeedCardStrategy

Returns a new instance of FeedCardStrategy.



9
10
11
12
# File 'lib/dingtalk/robot/strategies/feed_card_strategy.rb', line 9

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):

Raises:

  • (ArgumentError)


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

def notify(**options)
  links = Array.wrap(options[:links])
  all_present = links.all? { |link| link.all?(&:present?) }
  raise ArgumentError, 'All items of links must be present, strategy: feed_card' unless all_present
  body = generate_body(links)
  headers = {
    'Content-Type': 'application/json',
    Accept: 'application/json'
  }
  Net::HTTP.post(URI(webhook_url), body.to_json, headers).body
end