Module: Ckeditor::Webhook

Defined in:
lib/ckeditor/webhook.rb,
lib/ckeditor/webhook/event.rb,
lib/ckeditor/webhook/version.rb

Defined Under Namespace

Classes: Error, Event, InvalidPayload, SignatureVerificationError

Constant Summary collapse

VERSION =
"0.3.0"

Class Method Summary collapse

Class Method Details

.construct_event(secret:, payload:, signature:, timestamp:, url:, method: "POST") ⇒ Event

Returns an Event if the webhook signature is valid.

Parameters:

  • secret (String)

    the CKEditor Cloud Services API secret

  • payload (String)

    the webhook’s string payload

  • signature (String)

    the request’s ‘X-CS-Signature` header

  • timestamp (Integer)

    the request’s ‘X-CS-Timestamp` header

  • method (String) (defaults to: "POST")

    the request’s method (defaults to “POST”)

  • url (String)

    the request’s url

Returns:

Raises:



28
29
30
31
32
33
34
# File 'lib/ckeditor/webhook.rb', line 28

def construct_event(secret:, payload:, signature:, timestamp:, url:, method: "POST")
  event = message(method: method, url: url, timestamp: timestamp, payload: payload)

  raise SignatureVerificationError if signature != message_signature(message: event, secret: secret)

  Event.new(parse_payload(payload))
end