Class: Anypost::Resources::Webhooks

Inherits:
Base
  • Object
show all
Defined in:
lib/anypost/resources/webhooks.rb

Overview

Operations on the ‘/webhooks` endpoints.

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Anypost::Resources::Base

Instance Method Details

#create(params) ⇒ Object

Create a webhook. The full ‘signing_secret` is on the response to this call only — store it now to verify future deliveries; later reads return only the prefix.



15
16
17
# File 'lib/anypost/resources/webhooks.rb', line 15

def create(params)
  request_object(:post, "/webhooks", body: params)
end

#delete(id) ⇒ Object

Permanently delete a webhook.



31
32
33
34
# File 'lib/anypost/resources/webhooks.rb', line 31

def delete(id)
  @http.request(:delete, "/webhooks/#{encode(id)}")
  nil
end

#get(id) ⇒ Object

Retrieve a webhook. The signing secret is never returned — only its prefix.



20
21
22
# File 'lib/anypost/resources/webhooks.rb', line 20

def get(id)
  request_object(:get, "/webhooks/#{encode(id)}")
end

#list(params = {}) ⇒ Object

List the team’s webhooks, newest-first.



8
9
10
# File 'lib/anypost/resources/webhooks.rb', line 8

def list(params = {})
  paginate("/webhooks", {limit: params[:limit], after: params[:after]})
end

#rotate_secret(id) ⇒ Object

Rotate the signing secret. The new secret is on this response only. The previous secret stays valid for a 24h grace window. Rotating again before the window ends raises webhook_rotation_in_progress (a ConflictError).



46
47
48
# File 'lib/anypost/resources/webhooks.rb', line 46

def rotate_secret(id)
  request_object(:post, "/webhooks/#{encode(id)}/rotate-secret")
end

#test(id) ⇒ Object

Send one synthetic ‘webhook.test` event and report the outcome. One-shot, not retried, and absent from delivery history. Returns the result even when the endpoint fails — read `delivered` and `status_code`.



39
40
41
# File 'lib/anypost/resources/webhooks.rb', line 39

def test(id)
  request_object(:post, "/webhooks/#{encode(id)}/test")
end

#update(id, params) ⇒ Object

Update a webhook’s name, URL, subscribed events, and status. This does not rotate the signing secret — use #rotate_secret.



26
27
28
# File 'lib/anypost/resources/webhooks.rb', line 26

def update(id, params)
  request_object(:patch, "/webhooks/#{encode(id)}", body: params)
end