Class: StarkInfra::Webhook
- Inherits:
-
Utils::Resource
- Object
- Utils::SubResource
- Utils::Resource
- StarkInfra::Webhook
- Defined in:
- lib/webhook/webhook.rb
Overview
# Webhook subscription object
A Webhook is used to subscribe to notification events on a user-selected endpoint. Currently available services for subscription are contract, credit-note, signer, issuing-card, issuing-invoice, issuing-purchase, pix-request.in, pix-request.out, pix-reversal.in, pix-reversal.out, pix-claim, pix-key, pix-chargeback, pix-infraction.
## Parameters (required):
-
url [string]: URL that will be notified when an event occurs.
-
subscriptions [list of strings]: list of any non-empty combination of the available services. ex: [‘contract’, ‘credit-note’, ‘signer’, ‘issuing-card’, ‘issuing-invoice’, ‘issuing-purchase’, ‘pix-request.in’, ‘pix-request.out’, ‘pix-reversal.in’, ‘pix-reversal.out’, ‘pix-claim’, ‘pix-key’, ‘pix-chargeback’, ‘pix-infraction’]
## Attributes:
-
id [string]: unique id returned when the webhook is created. ex: ‘5656565656565656’
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#subscriptions ⇒ Object
readonly
Returns the value of attribute subscriptions.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Class Method Summary collapse
-
.create(webhook, user: nil) ⇒ Object
# Create Webhook subscription.
-
.delete(id, user: nil) ⇒ Object
# Delete a Webhook entity.
-
.get(id, user: nil) ⇒ Object
# Retrieve a specific Webhook subscription.
-
.page(cursor: nil, limit: nil, user: nil) ⇒ Object
# Retrieve paged Webhooks.
-
.query(limit: nil, user: nil) ⇒ Object
# Retrieve Webhook subscriptions.
- .resource ⇒ Object
Instance Method Summary collapse
-
#initialize(url:, subscriptions:, id: nil) ⇒ Webhook
constructor
A new instance of Webhook.
Methods inherited from Utils::SubResource
Constructor Details
#initialize(url:, subscriptions:, id: nil) ⇒ Webhook
Returns a new instance of Webhook.
21 22 23 24 25 |
# File 'lib/webhook/webhook.rb', line 21 def initialize(url:, subscriptions:, id: nil) super(id) @url = url @subscriptions = subscriptions end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
20 21 22 |
# File 'lib/webhook/webhook.rb', line 20 def id @id end |
#subscriptions ⇒ Object (readonly)
Returns the value of attribute subscriptions.
20 21 22 |
# File 'lib/webhook/webhook.rb', line 20 def subscriptions @subscriptions end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
20 21 22 |
# File 'lib/webhook/webhook.rb', line 20 def url @url end |
Class Method Details
.create(webhook, user: nil) ⇒ Object
# Create Webhook subscription
Send a single Webhook subscription for creation in the Stark Infra API
## Parameters (required):
-
webhook [Webhook object or hash]: Webhook subscription to be created to receive Events. ex: Webhook.new()
## Parameters (optional):
-
user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
## Return:
-
Webhook object with updated attributes
39 40 41 |
# File 'lib/webhook/webhook.rb', line 39 def self.create(webhook, user: nil) StarkInfra::Utils::Rest.post_single(entity: webhook, user: user, **resource) end |
.delete(id, user: nil) ⇒ Object
# Delete a Webhook entity
Delete a Webhook entity previously created in the Stark Infra API
## Parameters (required):
-
id [string]: Webhook unique id. ex: ‘5656565656565656’
## Parameters (optional):
-
user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
## Return:
-
deleted Webhook object
107 108 109 |
# File 'lib/webhook/webhook.rb', line 107 def self.delete(id, user: nil) StarkInfra::Utils::Rest.delete_id(id: id, user: user, **resource) end |
.get(id, user: nil) ⇒ Object
# Retrieve a specific Webhook subscription
Receive a single Webhook subscription object previously created in the Stark Infra API by passing its id
## Parameters (required):
-
id [string]: object unique id. ex: ‘5656565656565656’
## Parameters (optional):
-
user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
## Return:
-
Webhook object with updated attributes
55 56 57 |
# File 'lib/webhook/webhook.rb', line 55 def self.get(id, user: nil) StarkInfra::Utils::Rest.get_id(id: id, user: user, **resource) end |
.page(cursor: nil, limit: nil, user: nil) ⇒ Object
# Retrieve paged Webhooks
Receive a list of up to 100 Webhook objects previously created in the Stark Infra API and the cursor to the next page. Use this function instead of query if you want to manually page your requests.
## Parameters (optional):
-
cursor [string, default nil]: cursor returned on the previous page function call
-
limit [integer, default 100]: maximum number of objects to be retrieved. Max = 100. ex: 35
-
user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
## Return:
-
list of Webhook objects with updated attributes
-
cursor to retrieve the next page of Webhook objects
86 87 88 89 90 91 92 93 |
# File 'lib/webhook/webhook.rb', line 86 def self.page(cursor: nil, limit: nil, user: nil) return StarkInfra::Utils::Rest.get_page( cursor: cursor, limit: limit, user: user, **resource ) end |
.query(limit: nil, user: nil) ⇒ Object
# Retrieve Webhook subscriptions
Receive a generator of Webhook subscription objects previously created in the Stark Infra API
## Parameters (optional):
-
limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
-
user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
## Return:
-
generator of Webhook objects with updated attributes
69 70 71 |
# File 'lib/webhook/webhook.rb', line 69 def self.query(limit: nil, user: nil) StarkInfra::Utils::Rest.get_stream(user: user, limit: limit, **resource) end |