Class: Mailtrap::WebhooksAPI

Inherits:
Object
  • Object
show all
Includes:
BaseAPI
Defined in:
lib/mailtrap/webhooks_api.rb

Instance Attribute Summary

Attributes included from BaseAPI

#account_id, #client

Instance Method Summary collapse

Methods included from BaseAPI

included, #initialize

Instance Method Details

#create(options) ⇒ Webhook

Creates a new webhook

Parameters:

  • options (Hash)

    The parameters to create

Options Hash (options):

  • :url (String)

    The URL that will receive webhook payloads

  • :webhook_type (String)

    The type of webhook (‘email_sending` or `audit_log`)

  • :active (Boolean)

    Whether the webhook is active. Defaults to true.

  • :payload_format (String)

    Payload format (‘json` or `jsonlines`). Defaults to `json`.

  • :sending_stream (String)

    Sending stream (‘transactional` or `bulk`). Required for `email_sending` webhook type.

  • :event_types (Array<String>)

    Event types to subscribe to. Required for ‘email_sending` webhook type.

  • :domain_id (Integer)

    Sending domain ID to scope the webhook to. Applicable only for ‘email_sending` webhooks.

Returns:

  • (Webhook)

    Created webhook (includes ‘signing_secret`)

Raises:



45
46
47
# File 'lib/mailtrap/webhooks_api.rb', line 45

def create(options)
  base_create(options)
end

#delete(webhook_id) ⇒ Webhook

Deletes a webhook

Parameters:

  • webhook_id (Integer)

    The webhook ID

Returns:

Raises:



68
69
70
71
# File 'lib/mailtrap/webhooks_api.rb', line 68

def delete(webhook_id)
  response = client.delete("#{base_path}/#{webhook_id}")
  handle_response(response) if response
end

#get(webhook_id) ⇒ Webhook

Retrieves a specific webhook

Parameters:

  • webhook_id (Integer)

    The webhook ID

Returns:

Raises:



26
27
28
# File 'lib/mailtrap/webhooks_api.rb', line 26

def get(webhook_id)
  base_get(webhook_id)
end

#listArray<Webhook>

Lists all webhooks for the account

Returns:

  • (Array<Webhook>)

    Array of webhooks

Raises:



17
18
19
20
# File 'lib/mailtrap/webhooks_api.rb', line 17

def list
  response = client.get(base_path)
  response[:data].map { |item| build_entity(item, response_class) }
end

#update(webhook_id, options) ⇒ Webhook

Updates an existing webhook

Parameters:

  • webhook_id (Integer)

    The webhook ID

  • options (Hash)

    The parameters to update

Options Hash (options):

  • :url (String)

    The URL that will receive webhook payloads

  • :active (Boolean)

    Whether the webhook is active

  • :payload_format (String)

    Payload format (‘json` or `jsonlines`)

  • :event_types (Array<String>)

    Event types to subscribe to. Applicable only for ‘email_sending` webhooks.

Returns:

Raises:



60
61
62
# File 'lib/mailtrap/webhooks_api.rb', line 60

def update(webhook_id, options)
  base_update(webhook_id, options, %i[url active payload_format event_types])
end