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.



687
688
689
690
# File 'lib/ghostcrawl/client.rb', line 687

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.



706
707
708
709
710
711
712
# File 'lib/ghostcrawl/client.rb', line 706

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.



720
721
722
# File 'lib/ghostcrawl/client.rb', line 720

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.



700
701
702
# File 'lib/ghostcrawl/client.rb', line 700

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.



694
695
696
# File 'lib/ghostcrawl/client.rb', line 694

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.



726
727
728
# File 'lib/ghostcrawl/client.rb', line 726

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