Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/mailgun/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def delete(resource_path, params = nil, body_params = false)
request.body = params.to_json
end
else
@http_client.delete(resource_path, params: params)
@http_client.delete(resource_path, params)
end
else
@http_client.delete(resource_path)
Expand Down
85 changes: 85 additions & 0 deletions lib/mailgun/webhooks/account_webhooks.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# frozen_string_literal: true

module Mailgun
# A Mailgun::AccountWebhooks object is a simple CRUD interface to Account Mailgun Webhooks.
# Uses Mailgun
class AccountWebhooks
include ApiVersionChecker

# Public creates a new Mailgun::Webhooks instance.
# Defaults to Mailgun::Client
def initialize(client = Mailgun::Client.new(Mailgun.api_key, Mailgun.api_host || 'api.mailgun.net', 'v1'))
@client = client
end

# 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.
def list(webhook_ids = '')
res = @client.get('webhooks', webhook_ids: webhook_ids)
res.to_h['webhooks']
end

# Public: Create an account-level webhook
# options - [Hash] of
# 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
def create(_options = {})
res = @client.post('webhooks', description: description, event_types: event_types, url: url)
res.to_h
end

# 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
def remove_all(webhook_ids = nil, all: false)
@client.delete('webhooks', { webhook_ids: webhook_ids, all: all }.compact).status == 204
end

# Public: Get account-level webhook by ID
#
# webhook_id - [String] The webhook ID to retrieve
#
# Returns webhook details including associated event types.
def get(webhook_id)
res = @client.get("webhooks/#{webhook_id}")
res.to_h
end

# Public: Update an account-level webhook
#
# options - [Hash] of
# 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
def update(webhook_id, options = {})
@client.put("webhooks/#{webhook_id}", options).status == 204
end

# Public: Delete account-level webhook by ID
#
# webhook_id - [String] The webhook ID to delete
#
# Returns a Boolean of the success
def remove(webhook_id)
@client.delete("webhooks/#{webhook_id}").status == 204
end

enforces_api_version 'v1', :list, :create, :remove_all, :get, :update, :remove
end
end
2 changes: 1 addition & 1 deletion vcr_cassettes/domains.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.