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:, signature_header: '') ⇒ 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:, signature_header: '') ⇒ Coinbase::Webhook
Creates a new webhook for a specified network.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/coinbase/webhook.rb', line 37 def create(network_id:, notification_uri:, event_type:, event_filters:, signature_header: '') 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, signature_header: signature_header } ) 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…
57 58 59 60 61 |
# File 'lib/coinbase/webhook.rb', line 57 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.
156 157 158 159 160 161 162 163 164 |
# File 'lib/coinbase/webhook.rb', line 156 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.
115 116 117 |
# File 'lib/coinbase/webhook.rb', line 115 def event_filters @model.event_filters end |
#event_type ⇒ String
Returns the event type of the webhook.
108 109 110 |
# File 'lib/coinbase/webhook.rb', line 108 def event_type @model.event_type end |
#id ⇒ String
Returns the ID of the webhook.
87 88 89 |
# File 'lib/coinbase/webhook.rb', line 87 def id @model.id end |
#inspect ⇒ String
Same as to_s.
182 183 184 |
# File 'lib/coinbase/webhook.rb', line 182 def inspect to_s end |
#network_id ⇒ Symbol
Returns the network ID associated with the webhook.
94 95 96 |
# File 'lib/coinbase/webhook.rb', line 94 def network_id Coinbase.to_sym(@model.network_id) end |
#notification_uri ⇒ String
Returns the notification URI of the webhook.
101 102 103 |
# File 'lib/coinbase/webhook.rb', line 101 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’.
123 124 125 |
# File 'lib/coinbase/webhook.rb', line 123 def signature_header @model.signature_header end |
#to_s ⇒ String
Returns a String representation of the Webhook.
168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/coinbase/webhook.rb', line 168 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.
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/coinbase/webhook.rb', line 134 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 |