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
8 changes: 4 additions & 4 deletions lib/mailgun/helpers/api_version_checker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ def requires_api_version(version, *method_names)
method_names.each do |method_name|
original_method = instance_method(method_name)

define_method(method_name) do |*args, &block|
define_method(method_name) do |*args, **kwargs, &block|
warn_unless_api_version(version)
original_method.bind(self).call(*args, &block)
original_method.bind(self).call(*args, **kwargs, &block)
end
end
end
Expand All @@ -22,9 +22,9 @@ def enforces_api_version(version, *method_names)
method_names.each do |method_name|
original_method = instance_method(method_name)

define_method(method_name) do |*args, &block|
define_method(method_name) do |*args, **kwargs, &block|
require_api_version(version)
original_method.bind(self).call(*args, &block)
original_method.bind(self).call(*args, **kwargs, &block)
end
end
end
Expand Down
34 changes: 17 additions & 17 deletions lib/mailgun/webhooks/account_webhooks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ def list(webhook_ids = '')
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
#
# 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)
def create(description:, event_types:, url:)
res = @client.post('webhooks', { description: description, event_types: event_types, url: url })
res.to_h
end

Expand All @@ -44,7 +44,7 @@ def create(_options = {})
# 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)
def remove(webhook_ids = nil, all: false)
@client.delete('webhooks', { webhook_ids: webhook_ids, all: all }.compact).status == 204
end

Expand All @@ -60,26 +60,26 @@ def get(webhook_id)

# 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
# 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
def update(webhook_id, description:, event_types:, url:)
@client.put("webhooks/#{webhook_id}",
{ description: description, event_types: event_types, url: url }).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)
def remove_by_id(webhook_id)
@client.delete("webhooks/#{webhook_id}").status == 204
end

enforces_api_version 'v1', :list, :create, :remove_all, :get, :update, :remove
enforces_api_version 'v1', :list, :create, :remove, :get, :update, :remove_by_id
end
end
4 changes: 2 additions & 2 deletions lib/mailgun/webhooks/webhooks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ def list(domain, options = {})

# :nocov:

def get_webhooks(domain, _options = {})
def get_webhooks(domain, options = {})
warn('`get_webhooks` method will be deprecated in future versions of Mailgun. Please use `list` instead.')
list(domain, {})
list(domain, options)
end
# :nocov:

Expand Down
57 changes: 57 additions & 0 deletions spec/integration/account_webhooks_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# frozen_string_literal: true

require 'spec_helper'
require 'mailgun'

vcr_opts = { cassette_name: 'account_webhooks' }

describe 'For the webhooks endpoint', order: :defined, vcr: vcr_opts do
let(:api_version) { 'v1' }
let(:mg_client) { Mailgun::Client.new(APIKEY, APIHOST, api_version, SSL) }
let(:mg_obj) { Mailgun::AccountWebhooks.new(mg_client) }

it 'creates a webhook' do
result = mg_obj.create(
description: 'test',
event_types: 'accepted',
url: 'http://example.com/mailgun/events'
)

expect(result).to have_key('webhook_id')
end

it 'gets a webhook' do
result = mg_obj.get('test')

expect(result['url']).to eq('http://example.com/mailgun/events')
end

it 'gets a list of all account webhooks' do
result = mg_obj.list

expect(result[0]['url']).to eq('http://example.com/mailgun/events')
end

it 'updates a webhook' do
result = mg_obj.update(
'test',
description: 'test2',
event_types: 'accepted',
url: 'http://example.com/mailgun/events'
)

expect(result).to be_truthy
end

it 'removes a webhook' do
result = mg_obj.remove_by_id('test')

expect(result).to be_truthy
end

it 'removes all webhooks' do
result = mg_obj.remove(all: true)

expect(result).to be_truthy
end
end
Loading