Class: ScalarGalaxy::Resources::Webhooks

Inherits:
Object
  • Object
show all
Defined in:
lib/galaxy-ruby/resources/webhooks.rb,
sig/galaxy-ruby/resources/webhooks.rbs

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:



29
30
31
# File 'lib/galaxy-ruby/resources/webhooks.rb', line 29

def initialize(client:)
  @client = client
end

Instance Method Details

#unwrap(payload, headers:, key: @client.webhook_secret) ⇒ ScalarGalaxy::Models::NewPlanetWebhookEvent

Parameters:

  • payload (String)

    The raw webhook payload as a string

  • headers (Hash{String=>String})

    The raw HTTP headers that came with the payload

  • key (String, nil) (defaults to: @client.webhook_secret)

    The webhook signing key

Returns:



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/galaxy-ruby/resources/webhooks.rb', line 13

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

  ::StandardWebhooks::Webhook.new(key).verify(payload, headers)

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