Module: DingHook

Defined in:
lib/ding_hook.rb,
lib/ding_hook/valid.rb,
lib/ding_hook/config.rb,
lib/ding_hook/message.rb,
lib/ding_hook/version.rb,
lib/ding_hook/exception.rb

Defined Under Namespace

Modules: Exception, Valid Classes: Config, Message

Constant Summary collapse

VERSION =
"0.1.0"

Class Method Summary collapse

Class Method Details

.configObject



18
19
20
# File 'lib/ding_hook.rb', line 18

def config
  DingHook::Config.instance.configuration
end

.configure {|config_hash| ... } ⇒ Object

Yields:

  • (config_hash)


10
11
12
13
14
15
16
# File 'lib/ding_hook.rb', line 10

def configure
  config_hash = {}
  yield(config_hash)

  config = DingHook::Config.instance
  config.configuration(config_hash)
end

.send_btns_action_card(title, text, btns, options = {}, accounts = [:default]) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/ding_hook.rb', line 73

def send_btns_action_card(title, text, btns, options = {}, accounts = [:default])
  btns = btns.is_a?(Array) ? btns : [btns]
  params = {
      title: title,
      text: text,
      btns: btns,
      btn_orientation: options.fetch(:btn_orientation, nil),
      hide_avator: options.fetch(:hide_avator, nil)
  }

  DingHook::Message.new.send_msg(params, accounts, :action_card)
end

.send_feed_card(links, accounts = [:default]) ⇒ Object



86
87
88
89
90
91
92
93
# File 'lib/ding_hook.rb', line 86

def send_feed_card(links, accounts = [:default])
  links = links.is_a?(Array) ? links : [links]
  params = {
      links: links
  }

  DingHook::Message.new.send_msg(params, accounts, :feed_card)
end


38
39
40
41
42
43
44
45
46
47
# File 'lib/ding_hook.rb', line 38

def send_link_msg(title, text, msg_url, options = {}, accounts = [:default])
  params = {
      text: text,
      title: title,
      message_url: msg_url,
      pic_url: options.fetch(:pic_url, nil)
  }

  DingHook::Message.new.send_msg(params, accounts, :link)
end

.send_markdown_msg(title, text, options = {}, accounts = [:default]) ⇒ Object



49
50
51
52
53
54
55
56
57
58
# File 'lib/ding_hook.rb', line 49

def send_markdown_msg(title, text, options = {}, accounts = [:default])
  params = {
      text: text,
      title: title,
      at_mobiles: options.fetch(:at_mobiles, []),
      is_at_all: options.fetch(:is_at_all, false)
  }

  DingHook::Message.new.send_msg(params, accounts, :markdown)
end

.send_msg(params, type = :text, accounts = [:default]) ⇒ Object



22
23
24
25
26
# File 'lib/ding_hook.rb', line 22

def send_msg(params, type = :text, accounts = [:default])
  ding = DingHook::Message.new

  ding.send_msg(params, accounts, type.to_sym)
end

.send_single_action_card(title, text, single_title, single_url, options = {}, accounts = [:default]) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/ding_hook.rb', line 60

def send_single_action_card(title, text, single_title, single_url, options = {}, accounts = [:default])
  params = {
      title: title,
      text: text,
      single_title: single_title,
      single_url: single_url,
      btn_orientation: options.fetch(:btn_orientation, nil),
      hide_avator: options.fetch(:hide_avator, nil)
  }

  DingHook::Message.new.send_msg(params, accounts, :action_card)
end

.send_text_msg(text, options = {}, accounts = [:default]) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'lib/ding_hook.rb', line 28

def send_text_msg(text, options = {}, accounts = [:default])
  params = {
      text: text,
      at_mobiles: options.fetch(:at_mobiles, []),
      is_at_all: options.fetch(:is_at_all, false)
  }

  DingHook::Message.new.send_msg(params, accounts, :text)
end