Class: RailsEventStore::EventHandlers::SlackEventHandler
- Inherits:
-
Object
- Object
- RailsEventStore::EventHandlers::SlackEventHandler
- Defined in:
- lib/rails_event_store/event_handlers/slack_event_handler.rb
Defined Under Namespace
Classes: HTTPClient
Instance Attribute Summary collapse
-
#http_client ⇒ Object
readonly
Returns the value of attribute http_client.
-
#webhook_url ⇒ Object
readonly
Returns the value of attribute webhook_url.
Instance Method Summary collapse
- #handle_event(event) ⇒ Object
-
#initialize(webhook_url) ⇒ SlackEventHandler
constructor
A new instance of SlackEventHandler.
Constructor Details
#initialize(webhook_url) ⇒ SlackEventHandler
Returns a new instance of SlackEventHandler.
21 22 23 24 |
# File 'lib/rails_event_store/event_handlers/slack_event_handler.rb', line 21 def initialize(webhook_url) @webhook_url = webhook_url @http_client = HTTPClient.new end |
Instance Attribute Details
#http_client ⇒ Object (readonly)
Returns the value of attribute http_client.
26 27 28 |
# File 'lib/rails_event_store/event_handlers/slack_event_handler.rb', line 26 def http_client @http_client end |
#webhook_url ⇒ Object (readonly)
Returns the value of attribute webhook_url.
26 27 28 |
# File 'lib/rails_event_store/event_handlers/slack_event_handler.rb', line 26 def webhook_url @webhook_url end |
Instance Method Details
#handle_event(event) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/rails_event_store/event_handlers/slack_event_handler.rb', line 28 def handle_event(event) event_name = event.class.name payload = { text: "Event #{event_name} raised.", username: "Rails EventStore Bot", } @http_client.post(@webhook_url, { payload: payload.to_json }) end |