Class: Ghostcrawl::WebhooksClient

Inherits:
Object
  • Object
show all
Defined in:
lib/ghostcrawl/client.rb

Overview

Manage webhooks — /v1/webhooks.

Instance Method Summary collapse

Constructor Details

#initialize(v1, adapter = nil) ⇒ WebhooksClient

Returns a new instance of WebhooksClient.



728
729
730
731
# File 'lib/ghostcrawl/client.rb', line 728

def initialize(v1, adapter = nil)
  @v1 = v1
  @adapter = adapter
end

Instance Method Details

#create(url:, event_types: nil, events: nil, **opts) ⇒ Object

Register a new webhook endpoint. Delegates to POST /v1/webhooks via the generated WebhooksRequestBuilder.



747
748
749
750
751
752
753
# File 'lib/ghostcrawl/client.rb', line 747

def create(url:, event_types: nil, events: nil, **opts)
  data = { "url" => url }.merge(opts.transform_keys(&:to_s))
  # API field is "event_types"; "events" kept as a back-compat alias.
  et = event_types.nil? ? events : event_types
  data["event_types"] = et unless et.nil?
  ResponseHelper.to_hash(@v1.webhooks.post(AdditionalDataBody.new(data)))
end

#delete(webhook_id) ⇒ Object

Delete a webhook. Delegates to DELETE /v1/webhooks/id. The generated builder passes a nil response factory (204 void), which the Kiota adapter rejects with a bare StandardError BEFORE sending the request — so we build the request info and run it through ResponseHelper.void_request! instead, which actually fires the DELETE and returns {} on success.



761
762
763
# File 'lib/ghostcrawl/client.rb', line 761

def delete(webhook_id)
  ResponseHelper.void_request!(@adapter, @v1.webhooks.by_webhook_id(webhook_id).to_delete_request_information(nil))
end

#get(webhook_id) ⇒ Object

Get a webhook by ID. Delegates to GET /v1/webhooks/id via the generated builder.



741
742
743
# File 'lib/ghostcrawl/client.rb', line 741

def get(webhook_id)
  ResponseHelper.to_hash(@v1.webhooks.by_webhook_id(webhook_id).get)
end

#listObject

List all webhooks. Delegates to GET /v1/webhooks via the generated WebhooksRequestBuilder.



735
736
737
# File 'lib/ghostcrawl/client.rb', line 735

def list
  ResponseHelper.to_hash(@v1.webhooks.get)
end

#rotate_secret(webhook_id) ⇒ Object

Rotate the signing secret for a webhook. Delegates to POST /v1/webhooks/id/rotate-secret via the generated builder.



767
768
769
# File 'lib/ghostcrawl/client.rb', line 767

def rotate_secret(webhook_id)
  ResponseHelper.to_hash(@v1.webhooks.by_webhook_id(webhook_id).rotate_secret.post)
end