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"- MINIMUM_SECRET_LENGTH =
Shortest signing secret the API accepts.
32
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, or nil when the API confirms the deletion without echoing the object.
- #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.
18 19 20 |
# File 'lib/abacate_pay/clients/webhook_client.rb', line 18 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.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/abacate_pay/clients/webhook_client.rb', line 48 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? # The API rejects anything shorter with # "Expected string length greater or equal to 32". if secret.to_s.length < MINIMUM_SECRET_LENGTH raise ArgumentError, "secret must be at least #{MINIMUM_SECRET_LENGTH} characters, got #{secret.to_s.length}" end 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, or nil when the API confirms the deletion without echoing the object.
71 72 73 74 75 76 77 78 79 |
# File 'lib/abacate_pay/clients/webhook_client.rb', line 71 def delete(id) # The API reads the id from the query string here, like # transparents/simulate-payment. Sending it in the body fails with # "Expected property 'id' to be string but found: undefined". response = request("POST", "delete", params: { id: id }, json: {}) return nil if response.nil? Resources::WebhookEndpoints.new(response) end |
#get(id) ⇒ Resources::WebhookEndpoints
31 32 33 34 |
# File 'lib/abacate_pay/clients/webhook_client.rb', line 31 def get(id) response = request("GET", "get", params: { id: id }) Resources::WebhookEndpoints.new(response) end |
#list(**params) ⇒ Array<Resources::WebhookEndpoints>
24 25 26 27 |
# File 'lib/abacate_pay/clients/webhook_client.rb', line 24 def list(**params) response = request("GET", "list", params: params.empty? ? nil : params) build_list(response, Resources::WebhookEndpoints) end |