Class: DingHook::Message
- Inherits:
-
Object
- Object
- DingHook::Message
- Includes:
- Valid
- Defined in:
- lib/ding_hook/message.rb
Constant Summary collapse
- BASE_URL =
'https://oapi.dingtalk.com/robot/send?access_token='.freeze
Constants included from Valid
Instance Method Summary collapse
Methods included from Valid
#check_account_valid, #check_msg_type_valid
Instance Method Details
#send_msg(params, accounts, type = :text) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/ding_hook/message.rb', line 12 def send_msg(params, accounts, type = :text) accounts = accounts.is_a?(Array) ? accounts : [accounts] check_msg_type_valid(type) check_account_valid(accounts) result = [] body = send("#{type}_body_params".to_sym, params) accounts.each do |account| hook_url = BASE_URL + DingHook.config.fetch(account.to_sym) res = post(hook_url, body) res = JSON.parse(res.body.force_encoding('UTF-8')) result << [res['errcode'] == 0, res['errmsg']] end result.inject([true, '']) {|res, arr| [res.first && arr.first, res.last + arr.last]} end |