Class: Mailgun::AccountWebhooks

Inherits:
Object
  • Object
show all
Includes:
ApiVersionChecker
Defined in:
lib/mailgun/webhooks/account_webhooks.rb

Overview

A Mailgun::AccountWebhooks object is a simple CRUD interface to Account Mailgun Webhooks. Uses Mailgun

Instance Method Summary collapse

Methods included from ApiVersionChecker

included

Constructor Details

#initialize(client = Mailgun::Client.new(Mailgun.api_key, Mailgun.api_host || 'api.mailgun.net', 'v1')) ⇒ AccountWebhooks

Public creates a new Mailgun::Webhooks instance.

Defaults to Mailgun::Client


11
12
13
# File 'lib/mailgun/webhooks/account_webhooks.rb', line 11

def initialize(client = Mailgun::Client.new(Mailgun.api_key, Mailgun.api_host || 'api.mailgun.net', 'v1'))
  @client = client
end

Instance Method Details

#create(description:, event_types:, url:) ⇒ Object

Public: Create an account-level webhook

description - [String] Description for the webhook event_types - [String] Event types to subscribe to. Use multiple times to specify multiple event types.

Maximum of 3 unique URLs per event type.

url - [String] URL for webhook to be sent to

Returns the Unique identifier for the webhook



35
36
37
38
# File 'lib/mailgun/webhooks/account_webhooks.rb', line 35

def create(description:, event_types:, url:)
  res = @client.post('webhooks', { description: description, event_types: event_types, url: url })
  res.to_h
end

#get(webhook_id) ⇒ Object

Public: Get account-level webhook by ID

webhook_id - [String] The webhook ID to retrieve

Returns webhook details including associated event types.



56
57
58
59
# File 'lib/mailgun/webhooks/account_webhooks.rb', line 56

def get(webhook_id)
  res = @client.get("webhooks/#{webhook_id}")
  res.to_h
end

#list(webhook_ids = '') ⇒ Object

Public: List account-level webhooks

webhook_ids - [String] Comma-separated list of webhook IDs to filter results. If specified,

only webhooks with matching IDs will be returned.

Retrieve all account-level webhooks or filter by specific webhook IDs. Returns webhook details including associated event types.



22
23
24
25
# File 'lib/mailgun/webhooks/account_webhooks.rb', line 22

def list(webhook_ids = '')
  res = @client.get('webhooks', webhook_ids: webhook_ids)
  res.to_h['webhooks']
end

#remove(webhook_ids = nil, all: false) ⇒ Object

Public: Delete account-level webhooks

webhook_ids - [String] Comma-separated list of webhook IDs to delete.

If provided, only these specific webhooks will be deleted.

all - [Boolean] The required String of the webhook action to delete

Returns a Boolean of the success



47
48
49
# File 'lib/mailgun/webhooks/account_webhooks.rb', line 47

def remove(webhook_ids = nil, all: false)
  @client.delete('webhooks', { webhook_ids: webhook_ids, all: all }.compact).status == 204
end

#remove_by_id(webhook_id) ⇒ Object

Public: Delete account-level webhook by ID

webhook_id - [String] The webhook ID to delete

Returns a Boolean of the success



79
80
81
# File 'lib/mailgun/webhooks/account_webhooks.rb', line 79

def remove_by_id(webhook_id)
  @client.delete("webhooks/#{webhook_id}").status == 204
end

#update(webhook_id, description:, event_types:, url:) ⇒ Object

Public: Update an account-level webhook

description - [String] Description for the webhook event_types - [String] Event types to subscribe to. Use multiple times to specify multiple event types.

Maximum of 3 unique URLs per event type.

url - [String] URL for webhook to be sent to

Returns a Boolean of the success



69
70
71
72
# File 'lib/mailgun/webhooks/account_webhooks.rb', line 69

def update(webhook_id, description:, event_types:, url:)
  @client.put("webhooks/#{webhook_id}",
              { description: description, event_types: event_types, url: url }).status == 204
end