Class: Anthropic::Resources::Beta::Webhooks
- Inherits:
-
Object
- Object
- Anthropic::Resources::Beta::Webhooks
- Defined in:
- lib/anthropic/resources/beta/webhooks.rb,
sig/anthropic/resources/beta/webhooks.rbs
Instance Method Summary collapse
-
#initialize(client:) ⇒ Webhooks
constructor
private
A new instance of Webhooks.
-
#parse_unverified(payload) ⇒ Anthropic::Models::Beta::BetaWebhookEvent
Parses a webhook payload into an event without verifying its signature.
-
#unwrap(payload, headers:, key: @client.webhook_key) ⇒ Anthropic::Models::Beta::BetaWebhookEvent
Verifies the webhook signature from the
webhook-id,webhook-timestampandwebhook-signatureheaders using your webhook signing key, then parses the payload into an event.
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.
43 44 45 |
# File 'lib/anthropic/resources/beta/webhooks.rb', line 43 def initialize(client:) @client = client end |
Instance Method Details
#parse_unverified(payload) ⇒ Anthropic::Models::Beta::BetaWebhookEvent
Parses a webhook payload into an event without verifying its signature. Prefer
unwrap() unless you have already verified the signature yourself.
13 14 15 16 |
# File 'lib/anthropic/resources/beta/webhooks.rb', line 13 def parse_unverified(payload) parsed = JSON.parse(payload, symbolize_names: true) Anthropic::Internal::Type::Converter.coerce(Anthropic::Models::Beta::BetaWebhookEvent, parsed) end |
#unwrap(payload, headers:, key: @client.webhook_key) ⇒ Anthropic::Models::Beta::BetaWebhookEvent
Verifies the webhook signature from the webhook-id, webhook-timestamp and
webhook-signature headers using your webhook signing key, then parses the
payload into an event. Fails if the signature is missing or invalid.
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/anthropic/resources/beta/webhooks.rb', line 29 def unwrap(payload, headers:, key: @client.webhook_key) if key.nil? raise ArgumentError.new("Cannot verify a webhook without a key on either the client's webhook_key or passed in as an argument") end ::StandardWebhooks::Webhook.new(key).verify(payload, headers) parsed = JSON.parse(payload, symbolize_names: true) Anthropic::Internal::Type::Converter.coerce(Anthropic::Models::Beta::BetaWebhookEvent, parsed) end |