Class: Coinbase::Webhook
- Inherits:
-
Object
- Object
- Coinbase::Webhook
- Defined in:
- lib/coinbase/webhook.rb
Overview
A representation of a Webhook. This class provides methods to create, list, update, and delete webhooks that are used to receive notifications of specific events.
Constant Summary collapse
- ERC20_TRANSFER_EVENT =
Event type for ERC20 transfer
'erc20_transfer'
- ERC721_TRANSFER_EVENT =
Event type for ERC721 transfer
'erc721_transfer'
Class Method Summary collapse
-
.create(network_id:, notification_uri:, event_type:, event_filters:) ⇒ Coinbase::Webhook
Creates a new webhook for a specified network.
-
.list ⇒ Enumerable<Coinbase::Webhook>
Enumerates the webhooks.
Instance Method Summary collapse
-
#delete ⇒ self
Deletes the webhook.
-
#event_filters ⇒ Array<Coinbase::Client::WebhookEventFilter>
Returns the event filters applied to the webhook.
-
#event_type ⇒ String
Returns the event type of the webhook.
-
#id ⇒ String
Returns the ID of the webhook.
-
#initialize(model) ⇒ Webhook
constructor
Initializes a new Webhook object.
-
#inspect ⇒ String
Same as to_s.
-
#network_id ⇒ Symbol
Returns the network ID associated with the webhook.
-
#notification_uri ⇒ String
Returns the notification URI of the webhook.
-
#signature_header ⇒ String
Returns the signature header for the webhook.
-
#to_s ⇒ String
Returns a String representation of the Webhook.
-
#update(notification_uri:) ⇒ self
Updates the webhook with a new notification URI.
Constructor Details
Class Method Details
.create(network_id:, notification_uri:, event_type:, event_filters:) ⇒ Coinbase::Webhook
Creates a new webhook for a specified network.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/coinbase/webhook.rb', line 34 def create(network_id:, notification_uri:, event_type:, event_filters:) model = Coinbase.call_api do webhooks_api.create_webhook( create_webhook_request: { network_id: Coinbase.normalize_network(network_id), notification_uri: notification_uri, event_type: event_type, event_filters: event_filters } ) end new(model) end |
.list ⇒ Enumerable<Coinbase::Webhook>
Enumerates the webhooks. The result is an enumerator that lazily fetches from the server, and can be iterated over, converted to an array, etc…
53 54 55 56 57 |
# File 'lib/coinbase/webhook.rb', line 53 def list Coinbase::Pagination.enumerate(method(:fetch_webhooks_page).to_proc) do |webhook| Coinbase::Webhook.new(webhook) end end |
Instance Method Details
#delete ⇒ self
Deletes the webhook.
152 153 154 155 156 157 158 159 160 |
# File 'lib/coinbase/webhook.rb', line 152 def delete Coinbase.call_api do webhooks_api.delete_webhook(id) end @model = nil self end |
#event_filters ⇒ Array<Coinbase::Client::WebhookEventFilter>
Returns the event filters applied to the webhook.
111 112 113 |
# File 'lib/coinbase/webhook.rb', line 111 def event_filters @model.event_filters end |
#event_type ⇒ String
Returns the event type of the webhook.
104 105 106 |
# File 'lib/coinbase/webhook.rb', line 104 def event_type @model.event_type end |
#id ⇒ String
Returns the ID of the webhook.
83 84 85 |
# File 'lib/coinbase/webhook.rb', line 83 def id @model.id end |
#inspect ⇒ String
Same as to_s.
178 179 180 |
# File 'lib/coinbase/webhook.rb', line 178 def inspect to_s end |
#network_id ⇒ Symbol
Returns the network ID associated with the webhook.
90 91 92 |
# File 'lib/coinbase/webhook.rb', line 90 def network_id Coinbase.to_sym(@model.network_id) end |
#notification_uri ⇒ String
Returns the notification URI of the webhook.
97 98 99 |
# File 'lib/coinbase/webhook.rb', line 97 def notification_uri @model.notification_uri end |
#signature_header ⇒ String
Returns the signature header for the webhook. It is used as the value of callback header with key 'x-webhook-signature'.
119 120 121 |
# File 'lib/coinbase/webhook.rb', line 119 def signature_header @model.signature_header end |
#to_s ⇒ String
Returns a String representation of the Webhook.
164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/coinbase/webhook.rb', line 164 def to_s Coinbase.pretty_print_object( self.class, id: @model.id, network_id: @model.network_id, event_type: @model.event_type, notification_uri: @model.notification_uri, event_filters: @model.event_filters.map(&:to_hash).to_json, signature_header: @model.signature_header ) end |
#update(notification_uri:) ⇒ self
Updates the webhook with a new notification URI.
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/coinbase/webhook.rb', line 130 def update(notification_uri:) model = Coinbase.call_api do webhooks_api.update_webhook( id, update_webhook_request: { notification_uri: notification_uri, event_filters: event_filters.map(&:to_hash) } ) end @model = model self end |