Class: BaseCradle::TimelineWebhookEndpoints

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/basecradle/webhooks.rb

Overview

One timeline's webhook endpoints: create here, or iterate (newest first).

Instance Method Summary collapse

Constructor Details

#initialize(client, timeline_uuid) ⇒ TimelineWebhookEndpoints

Returns a new instance of TimelineWebhookEndpoints.



111
112
113
114
# File 'lib/basecradle/webhooks.rb', line 111

def initialize(client, timeline_uuid)
  @client = client
  @timeline_uuid = timeline_uuid
end

Instance Method Details

#create(description:, idempotency_key: nil) ⇒ Object

Create an inbound webhook endpoint on this timeline (viewer; the timeline unlocked).

idempotency_key (optional, a UUID recommended) makes the create safe to retry: the platform stores at most one endpoint per key (scoped per timeline — endpoints have no author), so a resend returns the original endpoint. See BaseCradle::Client#max_retries.



121
122
123
124
125
126
# File 'lib/basecradle/webhooks.rb', line 121

def create(description:, idempotency_key: nil)
  response = @client.request("POST", "/timelines/#{@timeline_uuid}/webhook_endpoints",
                             json: { "webhook_endpoint" => { "description" => description } },
                             headers: BaseCradle.idempotency_headers(idempotency_key))
  WebhookEndpoint.new(response.fetch("webhook_endpoint"), client: @client)
end

#each(&block) ⇒ Object



128
129
130
# File 'lib/basecradle/webhooks.rb', line 128

def each(&block)
  WebhookEndpointsResource.new(@client).filter(timeline: @timeline_uuid).each(&block)
end