Class: Mailgun::Webhook

Inherits:
Object show all
Defined in:
lib/mailgun/webhook.rb

Overview

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mailgun, domain, url) ⇒ Webhook

Used internally, called from Mailgun::Base



8
9
10
11
12
# File 'lib/mailgun/webhook.rb', line 8

def initialize(mailgun, domain, url)
  @mailgun = mailgun
  @domain = domain
  @default_webhook_url = url
end

Instance Attribute Details

#default_webhook_urlObject

Returns the value of attribute default_webhook_url.



5
6
7
# File 'lib/mailgun/webhook.rb', line 5

def default_webhook_url
  @default_webhook_url
end

#domainObject

Returns the value of attribute domain.



5
6
7
# File 'lib/mailgun/webhook.rb', line 5

def domain
  @domain
end

Instance Method Details

#available_idsObject

List of currently available webhooks



15
16
17
# File 'lib/mailgun/webhook.rb', line 15

def available_ids
  %w(bounce deliver drop spam unsubscribe click open).map(&:to_sym)
end

#create(id, url = default_webhook_url) ⇒ Object

Creates a new webhook Note: Creating an Open or Click webhook will enable Open or Click tracking



31
32
33
34
# File 'lib/mailgun/webhook.rb', line 31

def create(id, url=default_webhook_url)
  params = {:id => id, :url => url}
  Mailgun.submit :post, webhook_url, params
end

#delete(id) ⇒ Object

Deletes an existing webhook Note: Deleting an Open or Click webhook will disable Open or Click tracking



44
45
46
# File 'lib/mailgun/webhook.rb', line 44

def delete(id)
  Mailgun.submit :delete, webhook_url(id)
end

#find(id) ⇒ Object

Returns details about the webhook specified



25
26
27
# File 'lib/mailgun/webhook.rb', line 25

def find(id)
  Mailgun.submit :get, webhook_url(id)
end

#listObject

Returns a list of webhooks set for the specified domain



20
21
22
# File 'lib/mailgun/webhook.rb', line 20

def list
  Mailgun.submit(:get, webhook_url)["webhooks"] || []
end

#update(id, url = default_webhook_url) ⇒ Object

Updates an existing webhook



37
38
39
40
# File 'lib/mailgun/webhook.rb', line 37

def update(id, url=default_webhook_url)
  params = {:url => url}
  Mailgun.submit :put, webhook_url(id), params
end