Class: AbacatePay::Clients::WebhookClient
- Defined in:
- lib/abacate_pay/clients/webhook_client.rb
Overview
Client for managing webhook endpoint registrations in the AbacatePay API.
This manages where AbacatePay delivers events. To verify and parse an inbound delivery, use Webhooks.construct_event.
Constant Summary collapse
- URI =
"webhooks"
Constants inherited from Client
Client::RETRIABLE_EXCEPTIONS, Client::RETRIABLE_METHODS, Client::RETRIABLE_STATUSES
Instance Method Summary collapse
-
#create(name:, endpoint:, secret:, events:) ⇒ Resources::WebhookEndpoints
Registers a new webhook endpoint.
-
#delete(id) ⇒ Resources::WebhookEndpoints
The deleted webhook.
- #get(id) ⇒ Resources::WebhookEndpoints
-
#initialize(client = nil) ⇒ WebhookClient
constructor
A new instance of WebhookClient.
- #list(**params) ⇒ Array<Resources::WebhookEndpoints>
Methods inherited from Client
Constructor Details
#initialize(client = nil) ⇒ WebhookClient
Returns a new instance of WebhookClient.
15 16 17 |
# File 'lib/abacate_pay/clients/webhook_client.rb', line 15 def initialize(client = nil) super(URI, client) end |
Instance Method Details
#create(name:, endpoint:, secret:, events:) ⇒ Resources::WebhookEndpoints
Registers a new webhook endpoint.
The secret is what AbacatePay signs deliveries with — pass the same value to Webhooks.construct_event when handling them.
44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/abacate_pay/clients/webhook_client.rb', line 44 def create(name:, endpoint:, secret:, events:) raise ArgumentError, "endpoint must be an HTTPS URL, got #{endpoint.inspect}" unless https_url?(endpoint) raise ArgumentError, "events must not be empty" if Array(events).empty? response = request("POST", "create", json: { name: name, endpoint: endpoint, secret: secret, events: Array(events) }) Resources::WebhookEndpoints.new(response) end |
#delete(id) ⇒ Resources::WebhookEndpoints
Returns The deleted webhook.
59 60 61 62 |
# File 'lib/abacate_pay/clients/webhook_client.rb', line 59 def delete(id) response = request("POST", "delete", json: { id: id }) Resources::WebhookEndpoints.new(response) end |
#get(id) ⇒ Resources::WebhookEndpoints
28 29 30 31 |
# File 'lib/abacate_pay/clients/webhook_client.rb', line 28 def get(id) response = request("GET", "get", params: { id: id }) Resources::WebhookEndpoints.new(response) end |
#list(**params) ⇒ Array<Resources::WebhookEndpoints>
21 22 23 24 |
# File 'lib/abacate_pay/clients/webhook_client.rb', line 21 def list(**params) response = request("GET", "list", params: params.empty? ? nil : params) build_list(response, Resources::WebhookEndpoints) end |