Class: Imagekitio::Resources::Webhooks

Inherits:
Object
  • Object
show all
Defined in:
lib/imagekitio/resources/webhooks.rb

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Webhooks

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Webhooks.

Parameters:



36
37
38
# File 'lib/imagekitio/resources/webhooks.rb', line 36

def initialize(client:)
  @client = client
end

Instance Method Details

#unwrap(payload, headers:, key: @client.webhook_secret) ⇒ Imagekitio::Models::VideoTransformationAcceptedEvent, ...



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/imagekitio/resources/webhooks.rb', line 21

def unwrap(payload, headers:, key: @client.webhook_secret)
  if key.nil?
    raise ArgumentError.new("Cannot verify a webhook without a key on either the client's webhook_secret or passed in as an argument")
  end

  encoded_key = Base64.strict_encode64(key)
  ::StandardWebhooks::Webhook.new(encoded_key).verify(payload, headers)

  parsed = JSON.parse(payload, symbolize_names: true)
  Imagekitio::Internal::Type::Converter.coerce(Imagekitio::Models::UnwrapWebhookEvent, parsed)
end