Class: Boppers::Notifier::Slack
- Inherits:
-
Object
- Object
- Boppers::Notifier::Slack
- Defined in:
- lib/boppers/notifier/slack.rb
Constant Summary collapse
- COLORS =
{ green: "good", red: "danger" }.freeze
Instance Attribute Summary collapse
-
#api_token ⇒ Object
readonly
Returns the value of attribute api_token.
-
#channel ⇒ Object
readonly
Returns the value of attribute channel.
-
#subscribe ⇒ Object
readonly
Returns the value of attribute subscribe.
Instance Method Summary collapse
- #call(subject, message, options) ⇒ Object
-
#initialize(api_token:, channel:, subscribe: nil) ⇒ Slack
constructor
A new instance of Slack.
Constructor Details
#initialize(api_token:, channel:, subscribe: nil) ⇒ Slack
Returns a new instance of Slack.
13 14 15 16 17 |
# File 'lib/boppers/notifier/slack.rb', line 13 def initialize(api_token:, channel:, subscribe: nil) @api_token = api_token @channel = channel @subscribe = subscribe end |
Instance Attribute Details
#api_token ⇒ Object (readonly)
Returns the value of attribute api_token.
11 12 13 |
# File 'lib/boppers/notifier/slack.rb', line 11 def api_token @api_token end |
#channel ⇒ Object (readonly)
Returns the value of attribute channel.
11 12 13 |
# File 'lib/boppers/notifier/slack.rb', line 11 def channel @channel end |
#subscribe ⇒ Object (readonly)
Returns the value of attribute subscribe.
11 12 13 |
# File 'lib/boppers/notifier/slack.rb', line 11 def subscribe @subscribe end |
Instance Method Details
#call(subject, message, options) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/boppers/notifier/slack.rb', line 19 def call(subject, , ) params = { token: api_token, text: "", channel: channel, attachments: JSON.dump( [ { fallback: , title: subject, text: , color: COLORS.fetch([:color]) } ] ) } HttpClient.post("https://slack.com/api/chat.postMessage", params) end |