Class: Noticed::BulkDeliveryMethods::Slack
Constant Summary
collapse
- DEFAULT_URL =
"https://slack.com/api/chat.postMessage"
Instance Attribute Summary
#config, #event
Instance Method Summary
collapse
#evaluate_option, #fetch_constant, #perform
Methods included from ApiClient
#post_request
Instance Method Details
#deliver ⇒ Object
8
9
10
11
12
13
14
15
16
17
18
|
# File 'lib/noticed/bulk_delivery_methods/slack.rb', line 8
def deliver
= evaluate_option(:headers)
json = evaluate_option(:json)
response = post_request url, headers: , json: json
if raise_if_not_ok? && !success?(response)
raise ResponseUnsuccessful.new(response, url, {headers: , json: json})
end
response
end
|
#raise_if_not_ok? ⇒ Boolean
24
25
26
27
|
# File 'lib/noticed/bulk_delivery_methods/slack.rb', line 24
def raise_if_not_ok?
value = evaluate_option(:raise_if_not_ok)
value.nil? || value
end
|
#success?(response) ⇒ Boolean
29
30
31
32
33
34
35
36
|
# File 'lib/noticed/bulk_delivery_methods/slack.rb', line 29
def success?(response)
if response.content_type == "application/json"
JSON.parse(response.body).dig("ok")
else
response.is_a?(Net::HTTPSuccess)
end
end
|
#url ⇒ Object
20
21
22
|
# File 'lib/noticed/bulk_delivery_methods/slack.rb', line 20
def url
evaluate_option(:url) || DEFAULT_URL
end
|