Class: StarkInfra::Webhook

Inherits:
StarkCore::Utils::Resource
  • Object
show all
Defined in:
lib/webhook/webhook.rb

Overview

# Webhook 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 (return-only):

  • id [string]: unique id returned when the webhook is created. ex: ‘5656565656565656’

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url:, subscriptions:, id: nil) ⇒ Webhook



20
21
22
23
24
# File 'lib/webhook/webhook.rb', line 20

def initialize(url:, subscriptions:, id: nil)
  super(id)
  @url = url
  @subscriptions = subscriptions
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



19
20
21
# File 'lib/webhook/webhook.rb', line 19

def id
  @id
end

#subscriptionsObject (readonly)

Returns the value of attribute subscriptions.



19
20
21
# File 'lib/webhook/webhook.rb', line 19

def subscriptions
  @subscriptions
end

#urlObject (readonly)

Returns the value of attribute url.



19
20
21
# File 'lib/webhook/webhook.rb', line 19

def url
  @url
end

Class Method Details

.create(webhook, user: nil) ⇒ Object

# Create Webhook

Send a single Webhook for creation in the Stark Infra API

## Parameters (required):

  • webhook [Webhook object]: Webhook 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



38
39
40
# File 'lib/webhook/webhook.rb', line 38

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



106
107
108
# File 'lib/webhook/webhook.rb', line 106

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

Receive a single Webhook 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



54
55
56
# File 'lib/webhook/webhook.rb', line 54

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



85
86
87
88
89
90
91
92
# File 'lib/webhook/webhook.rb', line 85

def self.page(cursor: nil, limit: nil, user: nil)
  StarkInfra::Utils::Rest.get_page(
    cursor: cursor,
    limit: limit,
    user: user,
    **resource
  )
end

.query(limit: nil, user: nil) ⇒ Object

# Retrieve Webhooks

Receive a generator of Webhook 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



68
69
70
# File 'lib/webhook/webhook.rb', line 68

def self.query(limit: nil, user: nil)
  StarkInfra::Utils::Rest.get_stream(user: user, limit: limit, **resource)
end

.resourceObject



110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/webhook/webhook.rb', line 110

def self.resource
  {
    resource_name: 'Webhook',
    resource_maker: proc { |json|
      Webhook.new(
        id: json['id'],
        url: json['url'],
        subscriptions: json['subscriptions']
      )
    }
  }
end