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.



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

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.



761
762
763
764
765
766
767
# File 'lib/ghostcrawl/client.rb', line 761

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.



775
776
777
# File 'lib/ghostcrawl/client.rb', line 775

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.



755
756
757
# File 'lib/ghostcrawl/client.rb', line 755

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.



749
750
751
# File 'lib/ghostcrawl/client.rb', line 749

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.



781
782
783
# File 'lib/ghostcrawl/client.rb', line 781

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