Class: Yookassa::Resources::Webhook

Inherits:
Base
  • Object
show all
Defined in:
lib/yookassa/resources/webhook.rb

Overview

REST resource for the /v3/webhooks endpoint.

Unlike other resources, webhooks support create, list, and delete but not find (individual lookup is not available in the API).

See Also:

Instance Attribute Summary

Attributes inherited from Base

#client

Instance Method Summary collapse

Methods inherited from Base

entity_class, #find, #initialize, resource_path

Constructor Details

This class inherits a constructor from Yookassa::Resources::Base

Instance Method Details

#create(params, idempotency_key: nil) ⇒ Entities::WebhookObj

Registers a new webhook subscription.

Parameters:

  • webhook parameters (event, url)

  • (defaults to: nil)

    optional idempotency key

Returns:

Raises:

  • on API failure



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

def create(params, idempotency_key: nil)
  data = request(:post, "webhooks", body: params, idempotency_key: idempotency_key)
  Entities::WebhookObj.new(data)
end

#delete(webhook_id) ⇒ true

Deletes a webhook subscription.

Parameters:

  • the webhook identifier

Returns:

  • always returns true on success

Raises:

  • if webhook does not exist



39
40
41
42
# File 'lib/yookassa/resources/webhook.rb', line 39

def delete(webhook_id)
  request(:delete, "webhooks/#{webhook_id}")
  true
end

#listEntities::Collection<Entities::WebhookObj>

Lists all registered webhook subscriptions.

Returns:



26
27
28
29
30
31
32
# File 'lib/yookassa/resources/webhook.rb', line 26

def list
  data = request(:get, "webhooks")
  Entities::Collection.new(
    items: data["items"] || [],
    entity_class: Entities::WebhookObj
  )
end