Class: StarkBank::Webhook
- Inherits:
-
Utils::Resource
- Object
- Utils::SubResource
- Utils::Resource
- StarkBank::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 transfer, invoice, deposit, brcode-payment, boleto, boleto-payment and utility-payment
## 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: [‘transfer’, ‘deposit’]
## Attributes:
-
id [string, default nil]: 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(url:, subscriptions:, id: nil, 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 subcriptions.
- .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.
22 23 24 25 26 |
# File 'lib/webhook/webhook.rb', line 22 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.
21 22 23 |
# File 'lib/webhook/webhook.rb', line 21 def id @id end |
#subscriptions ⇒ Object (readonly)
Returns the value of attribute subscriptions.
21 22 23 |
# File 'lib/webhook/webhook.rb', line 21 def subscriptions @subscriptions end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
21 22 23 |
# File 'lib/webhook/webhook.rb', line 21 def url @url end |
Class Method Details
.create(url:, subscriptions:, id: nil, user: nil) ⇒ Object
# Create Webhook subscription
Send a single Webhook subscription for creation in the Stark Bank API
## Parameters (required):
-
url [string]: url to which notification events will be sent to. ex: ‘webhook.site/60e9c18e-4b5c-4369-bda1-ab5fcd8e1b29’
-
subscriptions [list of strings]: list of any non-empty combination of the available services. ex: [‘transfer’, ‘invoice’]
## Parameters (optional):
-
user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
## Return:
-
Webhook object with updated attributes
41 42 43 |
# File 'lib/webhook/webhook.rb', line 41 def self.create(url:, subscriptions:, id: nil, user: nil) StarkBank::Utils::Rest.post_single(entity: Webhook.new(url: url, subscriptions: subscriptions), user: user, **resource) end |
.delete(id, user: nil) ⇒ Object
# Delete a Webhook entity
Delete a Webhook entity previously created in the Stark Bank API
## Parameters (required):
-
id [string]: Webhook unique id. ex: ‘5656565656565656’
## Parameters (optional):
-
user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
## Return:
-
deleted Webhook object
108 109 110 |
# File 'lib/webhook/webhook.rb', line 108 def self.delete(id, user: nil) StarkBank::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 Bank API by passing its id
## Parameters (required):
-
id [string]: object unique id. ex: ‘5656565656565656’
## Parameters (optional):
-
user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
## Return:
-
Webhook object with updated attributes
57 58 59 |
# File 'lib/webhook/webhook.rb', line 57 def self.get(id, user: nil) StarkBank::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 Bank 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 nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
-
user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
## Return:
-
list of Webhook objects with updated attributes and cursor to retrieve the next page of Webhook objects
87 88 89 90 91 92 93 94 |
# File 'lib/webhook/webhook.rb', line 87 def self.page(cursor: nil, limit: nil, user: nil) return StarkBank::Utils::Rest.get_page( cursor: cursor, limit: limit, user: user, **resource ) end |
.query(limit: nil, user: nil) ⇒ Object
# Retrieve Webhook subcriptions
Receive a generator of Webhook subcription objects previously created in the Stark Bank API
## Parameters (optional):
-
limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
-
user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
## Return:
-
generator of Webhook objects with updated attributes
71 72 73 |
# File 'lib/webhook/webhook.rb', line 71 def self.query(limit: nil, user: nil) StarkBank::Utils::Rest.get_stream(user: user, limit: limit, **resource) end |
.resource ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/webhook/webhook.rb', line 112 def self.resource { resource_name: 'Webhook', resource_maker: proc { |json| Webhook.new( id: json['id'], url: json['url'], subscriptions: json['subscriptions'] ) } } end |