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.



585
586
587
588
# File 'lib/ghostcrawl/client.rb', line 585

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.



604
605
606
607
608
609
610
# File 'lib/ghostcrawl/client.rb', line 604

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.



618
619
620
# File 'lib/ghostcrawl/client.rb', line 618

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.



598
599
600
# File 'lib/ghostcrawl/client.rb', line 598

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.



592
593
594
# File 'lib/ghostcrawl/client.rb', line 592

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.



624
625
626
# File 'lib/ghostcrawl/client.rb', line 624

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