Class: Mammoth::WebhookSink
- Inherits:
-
Object
- Object
- Mammoth::WebhookSink
- Defined in:
- lib/mammoth/webhook_sink.rb
Overview
Delivers normalized Mammoth events to a webhook endpoint.
Constant Summary collapse
- SUCCESS_RANGE =
HTTP status range treated as successful webhook delivery.
200..299
- SIGNING_ALGORITHM =
Supported webhook signing algorithm.
"hmac_sha256"- SIGNATURE_PREFIX =
Prefix added to generated webhook signatures.
"sha256="
Instance Attribute Summary collapse
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#signing ⇒ Object
readonly
Returns the value of attribute signing.
-
#timeout_seconds ⇒ Object
readonly
Returns the value of attribute timeout_seconds.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Class Method Summary collapse
-
.from_config(config) ⇒ Mammoth::WebhookSink
Build a sink from Mammoth configuration.
-
.from_destination_config(destination, label: "destination") ⇒ Mammoth::WebhookSink
Build a sink from one destination configuration entry.
Instance Method Summary collapse
-
#deliver(event) ⇒ Hash
Deliver an event to the webhook endpoint.
-
#deliver_transaction(envelope) ⇒ Hash
Deliver a transaction envelope to the webhook endpoint.
-
#initialize(name:, url:, timeout_seconds: 5, headers: {}, signing: nil) ⇒ WebhookSink
constructor
A new instance of WebhookSink.
Constructor Details
#initialize(name:, url:, timeout_seconds: 5, headers: {}, signing: nil) ⇒ WebhookSink
Returns a new instance of WebhookSink.
28 29 30 31 32 33 34 |
# File 'lib/mammoth/webhook_sink.rb', line 28 def initialize(name:, url:, timeout_seconds: 5, headers: {}, signing: nil) @name = name @url = URI(url) @timeout_seconds = timeout_seconds @headers = headers.transform_keys(&:to_s) @signing = signing end |
Instance Attribute Details
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
21 22 23 |
# File 'lib/mammoth/webhook_sink.rb', line 21 def headers @headers end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
21 22 23 |
# File 'lib/mammoth/webhook_sink.rb', line 21 def name @name end |
#signing ⇒ Object (readonly)
Returns the value of attribute signing.
21 22 23 |
# File 'lib/mammoth/webhook_sink.rb', line 21 def signing @signing end |
#timeout_seconds ⇒ Object (readonly)
Returns the value of attribute timeout_seconds.
21 22 23 |
# File 'lib/mammoth/webhook_sink.rb', line 21 def timeout_seconds @timeout_seconds end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
21 22 23 |
# File 'lib/mammoth/webhook_sink.rb', line 21 def url @url end |
Class Method Details
.from_config(config) ⇒ Mammoth::WebhookSink
Build a sink from Mammoth configuration.
41 42 43 |
# File 'lib/mammoth/webhook_sink.rb', line 41 def from_config(config) from_destination_config(config.data["webhook"], label: "webhook") end |
.from_destination_config(destination, label: "destination") ⇒ Mammoth::WebhookSink
Build a sink from one destination configuration entry.
50 51 52 53 54 55 56 57 58 |
# File 'lib/mammoth/webhook_sink.rb', line 50 def from_destination_config(destination, label: "destination") new( name: destination.fetch("name"), url: destination.fetch("url"), timeout_seconds: destination.fetch("timeout_seconds"), headers: configured_headers(destination, label: label), signing: configured_signing(destination, label: label) ) end |
Instance Method Details
#deliver(event) ⇒ Hash
Deliver an event to the webhook endpoint.
100 101 102 |
# File 'lib/mammoth/webhook_sink.rb', line 100 def deliver(event) deliver_payload(EventSerializer.call(event)) end |
#deliver_transaction(envelope) ⇒ Hash
Deliver a transaction envelope to the webhook endpoint.
109 110 111 |
# File 'lib/mammoth/webhook_sink.rb', line 109 def deliver_transaction(envelope) deliver_payload(TransactionEnvelopeSerializer.call(envelope)) end |