Class: WebhookManager::Webhook
- Inherits:
-
Object
- Object
- WebhookManager::Webhook
- Defined in:
- lib/webhook_manager.rb
Instance Attribute Summary collapse
-
#conn ⇒ Object
Returns the value of attribute conn.
Instance Method Summary collapse
-
#initialize(api_key) ⇒ Webhook
constructor
A new instance of Webhook.
- #trigger!(event_name:, payload:) ⇒ Object
- #update_status(event_id:, status:) ⇒ Object
Constructor Details
#initialize(api_key) ⇒ Webhook
Returns a new instance of Webhook.
15 16 17 18 19 20 21 22 23 |
# File 'lib/webhook_manager.rb', line 15 def initialize(api_key) @conn = Faraday::Connection.new( url: HOOKY_API, headers: { "Authorization" => "ApiKey #{api_key}", "Content-Type" => "application/json" } ) end |
Instance Attribute Details
#conn ⇒ Object
Returns the value of attribute conn.
13 14 15 |
# File 'lib/webhook_manager.rb', line 13 def conn @conn end |
Instance Method Details
#trigger!(event_name:, payload:) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/webhook_manager.rb', line 25 def trigger!(event_name:, payload:) begin res = @conn.post("webhook_events/trigger", {webhook_event: { event_name: event_name, event_payload: payload }}.to_json) rescue Faraday::ConnectionFailed => e raise Error.new("Could not connect to API") rescue Faraday::TimeoutError => e raise Error.new("Time out error") end handle_reponse(res) end |
#update_status(event_id:, status:) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/webhook_manager.rb', line 37 def update_status(event_id:, status:) begin res = @conn.post("webhook_events/update_status", { event_id: event_id, event_status: status }.to_json) rescue Faraday::ConnectionFailed => e raise Error.new("Could not connect to API") rescue Faraday::TimeoutError => e raise Error.new("Time out error") end handle_reponse(res) end |