Module: Ibanity::Webhook

Defined in:
lib/ibanity/webhook.rb

Defined Under Namespace

Modules: Signature

Constant Summary collapse

DEFAULT_TOLERANCE =
30
SIGNING_ALGORITHM =
"RS512"

Class Method Summary collapse

Class Method Details

.construct_event!(payload, signature_header, tolerance: DEFAULT_TOLERANCE) ⇒ Object

Initializes an Ibanity Webhooks event object from a JSON payload.

This may raise JSON::ParserError if the payload is not valid JSON, or Ibanity::Error if the signature verification fails.



10
11
12
13
14
15
16
# File 'lib/ibanity/webhook.rb', line 10

def self.construct_event!(payload, signature_header, tolerance: DEFAULT_TOLERANCE)
  Signature.verify!(payload, signature_header, tolerance)

  raw_item = JSON.parse(payload)
  klass = raw_item["data"]["type"].split(".").map{|klass| klass.sub(/\S/, &:upcase)}.join("::")
  Ibanity::Webhooks.const_get(klass).new(raw_item["data"])
end