Class: StarkBank::Webhook

Inherits:
Utils::Resource show all
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, 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’, ‘boleto-payment’]

## Attributes:

  • id [string, default nil]: unique id returned when the log is created. ex: ‘5656565656565656’

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Utils::Resource

#inspect, #to_s

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

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

#subscriptionsObject (readonly)

Returns the value of attribute subscriptions.



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

def subscriptions
  @subscriptions
end

#urlObject (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’, ‘boleto-payment’]

## Parameters (optional):

  • user [Project object]: 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 [Project object]: Project object. Not necessary if StarkBank.user was set before function call

## Return:

  • deleted Webhook with updated attributes



87
88
89
# File 'lib/webhook/webhook.rb', line 87

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 [Project object]: 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

.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 [Project object, default nil]: 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_list(user: user, limit: limit, **resource)
end

.resourceObject



91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/webhook/webhook.rb', line 91

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