Class: Handinger::Resources::Workers::Webhooks

Inherits:
Object
  • Object
show all
Defined in:
lib/handinger/resources/workers/webhooks.rb

Overview

Configure outbound webhooks delivered when a worker’s tasks complete.

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Webhooks

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Webhooks.

Parameters:



132
133
134
# File 'lib/handinger/resources/workers/webhooks.rb', line 132

def initialize(client:)
  @client = client
end

Instance Method Details

#delete(worker_id, request_options: {}) ⇒ Handinger::Models::Workers::Webhook

Remove the webhook from a worker. Both ‘url` and `token` are cleared and no further deliveries are attempted. Only the worker creator can delete the webhook.

Parameters:

  • worker_id (String)

    Worker id returned by the create worker endpoint.

  • request_options (Handinger::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



73
74
75
76
77
78
79
80
# File 'lib/handinger/resources/workers/webhooks.rb', line 73

def delete(worker_id, params = {})
  @client.request(
    method: :delete,
    path: ["api/workers/%1$s/webhook", worker_id],
    model: Handinger::Workers::Webhook,
    options: params[:request_options]
  )
end

#list_executions(worker_id, page: nil, request_options: {}) ⇒ Handinger::Models::Workers::WebhookExecutionList

List recent webhook delivery attempts for a worker, newest first, paginated 50 per page. Only the worker creator can read execution history.

Parameters:

  • worker_id (String)

    Worker id returned by the create worker endpoint.

  • page (Integer)

    Page number (1-indexed). Defaults to 1.

  • request_options (Handinger::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



96
97
98
99
100
101
102
103
104
105
106
# File 'lib/handinger/resources/workers/webhooks.rb', line 96

def list_executions(worker_id, params = {})
  parsed, options = Handinger::Workers::WebhookListExecutionsParams.dump_request(params)
  query = Handinger::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: ["api/workers/%1$s/webhook/executions", worker_id],
    query: query,
    model: Handinger::Workers::WebhookExecutionList,
    options: options
  )
end

#regenerate_token(worker_id, request_options: {}) ⇒ Handinger::Models::Workers::Webhook

Issue a new shared token for the webhook, invalidating the previous one. The webhook URL is preserved. Only the worker creator can regenerate the token.

Parameters:

  • worker_id (String)

    Worker id returned by the create worker endpoint.

  • request_options (Handinger::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



120
121
122
123
124
125
126
127
# File 'lib/handinger/resources/workers/webhooks.rb', line 120

def regenerate_token(worker_id, params = {})
  @client.request(
    method: :post,
    path: ["api/workers/%1$s/webhook/regenerate-token", worker_id],
    model: Handinger::Workers::Webhook,
    options: params[:request_options]
  )
end

#retrieve(worker_id, request_options: {}) ⇒ Handinger::Models::Workers::Webhook

Retrieve the webhook URL and shared token configured for a worker. Both fields are ‘null` when no webhook is configured. Only the worker creator can read the webhook configuration.

Parameters:

  • worker_id (String)

    Worker id returned by the create worker endpoint.

  • request_options (Handinger::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



21
22
23
24
25
26
27
28
# File 'lib/handinger/resources/workers/webhooks.rb', line 21

def retrieve(worker_id, params = {})
  @client.request(
    method: :get,
    path: ["api/workers/%1$s/webhook", worker_id],
    model: Handinger::Workers::Webhook,
    options: params[:request_options]
  )
end

#update(worker_id, url:, request_options: {}) ⇒ Handinger::Models::Workers::Webhook

Some parameter documentations has been truncated, see Models::Workers::WebhookUpdateParams for more details.

Set or replace the webhook URL for a worker. A fresh token is generated the first time a URL is set; subsequent updates keep the existing token. Pass ‘url: null` to clear the webhook (use the dedicated DELETE for the same effect). Only the worker creator can update the webhook.

Parameters:

  • worker_id (String)

    Worker id returned by the create worker endpoint.

  • url (String, nil)

    HTTPS endpoint Handinger should POST to when a task finishes. Pass ‘null` to rem

  • request_options (Handinger::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



49
50
51
52
53
54
55
56
57
58
# File 'lib/handinger/resources/workers/webhooks.rb', line 49

def update(worker_id, params)
  parsed, options = Handinger::Workers::WebhookUpdateParams.dump_request(params)
  @client.request(
    method: :put,
    path: ["api/workers/%1$s/webhook", worker_id],
    body: parsed,
    model: Handinger::Workers::Webhook,
    options: options
  )
end