Class: CDEKApiClient::API::Webhook

Inherits:
Object
  • Object
show all
Defined in:
lib/cdek_api_client/api/webhook.rb

Overview

Handles webhook-related API requests.

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Webhook

Initializes the Webhook object.

Parameters:



10
11
12
# File 'lib/cdek_api_client/api/webhook.rb', line 10

def initialize(client)
  @client = client
end

Instance Method Details

#delete(webhook_uuid) ⇒ Hash

Deletes a webhook by its UUID.

Parameters:

  • webhook_uuid (String)

    the UUID of the webhook to delete.

Returns:

  • (Hash)

    the response from the API.



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

def delete(webhook_uuid)
  response = @client.request('delete', "webhooks/#{webhook_uuid}")
  @client.send(:handle_response, response)
end

#get(webhook_uuid) ⇒ Hash

Retrieves information about a specific webhook by its UUID.

Parameters:

  • webhook_uuid (String)

    the UUID of the webhook.

Returns:

  • (Hash)

    the webhook information.



58
59
60
61
# File 'lib/cdek_api_client/api/webhook.rb', line 58

def get(webhook_uuid)
  response = @client.request('get', "webhooks/#{webhook_uuid}")
  @client.send(:handle_response, response)
end

#listArray<Hash>

Retrieves a list of registered webhooks.

Returns:

  • (Array<Hash>)

    the list of webhooks.



41
42
43
44
# File 'lib/cdek_api_client/api/webhook.rb', line 41

def list
  response = @client.request('get', 'webhooks')
  @client.send(:handle_response, response)
end

#list_allArray<Hash>

Retrieves a list of all registered webhooks.

Returns:

  • (Array<Hash>)

    the list of webhooks.



49
50
51
52
# File 'lib/cdek_api_client/api/webhook.rb', line 49

def list_all
  response = @client.request('get', 'webhooks')
  @client.send(:handle_response, response)
end

#register(webhook_data) ⇒ Hash

Registers a new webhook.

Parameters:

Returns:

  • (Hash)

    the response from the API.



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

def register(webhook_data)
  response = @client.request('post', 'webhooks', body: webhook_data)
  @client.send(:handle_response, response)
end

#register_simple(url, event_types, type: 'WEBHOOK') ⇒ Hash

Registers a new webhook with simple parameters.

Parameters:

  • url (String)

    the URL where the webhook will send data.

  • event_types (Array<String>)

    the list of event types for the webhook.

  • type (String) (defaults to: 'WEBHOOK')

    the type of webhook (default: ‘WEBHOOK’).

Returns:

  • (Hash)

    the response from the API.



29
30
31
32
33
34
35
36
# File 'lib/cdek_api_client/api/webhook.rb', line 29

def register_simple(url, event_types, type: 'WEBHOOK')
  webhook_data = CDEKApiClient::Entities::Webhook.new(
    url: url,
    type: type,
    event_types: event_types
  )
  register(webhook_data)
end