Class: Mailgunner::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/mailgunner/client.rb,
lib/mailgunner/client/ips.rb,
lib/mailgunner/client/tags.rb,
lib/mailgunner/client/stats.rb,
lib/mailgunner/client/events.rb,
lib/mailgunner/client/routes.rb,
lib/mailgunner/client/domains.rb,
lib/mailgunner/client/messages.rb,
lib/mailgunner/client/webhooks.rb,
lib/mailgunner/client/suppressions.rb,
lib/mailgunner/client/mailing_lists.rb,
lib/mailgunner/client/email_validation.rb

Instance Method Summary collapse

Constructor Details

#initialize(domain: nil, api_key: nil, api_host: nil) ⇒ Client

Returns a new instance of Client


7
8
9
10
11
12
13
14
15
16
17
# File 'lib/mailgunner/client.rb', line 7

def initialize(domain: nil, api_key: nil, api_host: nil)
  @domain = domain || Mailgunner.config.domain

  @api_key = api_key || Mailgunner.config.api_key

  @api_host = api_host || Mailgunner.config.api_host

  @http = Net::HTTP.new(@api_host, Net::HTTP.https_default_port)

  @http.use_ssl = true
end

Instance Method Details

#add_bounce(attributes = ATTRIBUTES) ⇒ Object


13
14
15
# File 'lib/mailgunner/client/suppressions.rb', line 13

def add_bounce(attributes = ATTRIBUTES)
  post("/v3/#{escape @domain}/bounces", attributes)
end

#add_complaint(attributes = ATTRIBUTES) ⇒ Object


49
50
51
# File 'lib/mailgunner/client/suppressions.rb', line 49

def add_complaint(attributes = ATTRIBUTES)
  post("/v3/#{escape @domain}/complaints", attributes)
end

#add_credentials(attributes) ⇒ Object


25
26
27
# File 'lib/mailgunner/client/domains.rb', line 25

def add_credentials(attributes)
  post("/v3/domains/#{escape @domain}/credentials", attributes)
end

#add_domain(attributes = ATTRIBUTES) ⇒ Object


13
14
15
# File 'lib/mailgunner/client/domains.rb', line 13

def add_domain(attributes = ATTRIBUTES)
  post('/v3/domains', attributes)
end

#add_ip(address) ⇒ Object


17
18
19
# File 'lib/mailgunner/client/ips.rb', line 17

def add_ip(address)
  post("/v3/domains/#{escape @domain}/ips", ip: address)
end

#add_list(attributes = ATTRIBUTES) ⇒ Object


13
14
15
# File 'lib/mailgunner/client/mailing_lists.rb', line 13

def add_list(attributes = ATTRIBUTES)
  post('/v3/lists', attributes)
end

#add_list_member(list_address, member_attributes) ⇒ Object


33
34
35
# File 'lib/mailgunner/client/mailing_lists.rb', line 33

def add_list_member(list_address, member_attributes)
  post("/v3/lists/#{escape list_address}/members", member_attributes)
end

#add_route(attributes = ATTRIBUTES) ⇒ Object


13
14
15
# File 'lib/mailgunner/client/routes.rb', line 13

def add_route(attributes = ATTRIBUTES)
  post('/v3/routes', attributes)
end

#add_unsubscribe(attributes = ATTRIBUTES) ⇒ Object


37
38
39
# File 'lib/mailgunner/client/suppressions.rb', line 37

def add_unsubscribe(attributes = ATTRIBUTES)
  post("/v3/#{escape @domain}/unsubscribes", attributes)
end

#add_webhook(attributes = ATTRIBUTES) ⇒ Object


13
14
15
# File 'lib/mailgunner/client/webhooks.rb', line 13

def add_webhook(attributes = ATTRIBUTES)
  post("/v3/domains/#{escape @domain}/webhooks", attributes)
end

#add_whitelist(attributes = ATTRIBUTES) ⇒ Object


65
66
67
# File 'lib/mailgunner/client/suppressions.rb', line 65

def add_whitelist(attributes = ATTRIBUTES)
  post("/v3/#{escape @domain}/whitelists", attributes)
end

#cancel_bulk_validation(list_id) ⇒ Object


21
22
23
# File 'lib/mailgunner/client/email_validation.rb', line 21

def cancel_bulk_validation(list_id)
  delete("/v4/address/validate/bulk/#{escape list_id}")
end

#create_bulk_validation(list_id) ⇒ Object


13
14
15
# File 'lib/mailgunner/client/email_validation.rb', line 13

def create_bulk_validation(list_id)
  post("/v4/address/validate/bulk/#{escape list_id}")
end

#delete_bounce(address) ⇒ Object


17
18
19
# File 'lib/mailgunner/client/suppressions.rb', line 17

def delete_bounce(address)
  delete("/v3/#{escape @domain}/bounces/#{escape address}")
end

#delete_bouncesObject


21
22
23
# File 'lib/mailgunner/client/suppressions.rb', line 21

def delete_bounces
  delete("/v3/#{escape @domain}/bounces")
end

#delete_complaint(address) ⇒ Object


53
54
55
# File 'lib/mailgunner/client/suppressions.rb', line 53

def delete_complaint(address)
  delete("/v3/#{escape @domain}/complaints/#{escape address}")
end

#delete_credentials(login) ⇒ Object


33
34
35
# File 'lib/mailgunner/client/domains.rb', line 33

def delete_credentials()
  delete("/v3/domains/#{escape @domain}/credentials/#{escape }")
end

#delete_domain(name) ⇒ Object


17
18
19
# File 'lib/mailgunner/client/domains.rb', line 17

def delete_domain(name)
  delete("/v3/domains/#{escape name}")
end

#delete_ip(address) ⇒ Object


21
22
23
# File 'lib/mailgunner/client/ips.rb', line 21

def delete_ip(address)
  delete("/v3/domains/#{escape @domain}/ips/#{escape address}")
end

#delete_list(address) ⇒ Object


21
22
23
# File 'lib/mailgunner/client/mailing_lists.rb', line 21

def delete_list(address)
  delete("/v3/lists/#{escape address}")
end

#delete_list_member(list_address, member_address) ⇒ Object


41
42
43
# File 'lib/mailgunner/client/mailing_lists.rb', line 41

def delete_list_member(list_address, member_address)
  delete("/v3/lists/#{escape list_address}/members/#{escape member_address}")
end

#delete_message(key) ⇒ Object


25
26
27
# File 'lib/mailgunner/client/messages.rb', line 25

def delete_message(key)
  delete("/v3/domains/#{escape @domain}/messages/#{escape key}")
end

#delete_route(id) ⇒ Object


21
22
23
# File 'lib/mailgunner/client/routes.rb', line 21

def delete_route(id)
  delete("/v3/routes/#{escape id}")
end

#delete_tag(id) ⇒ Object


21
22
23
# File 'lib/mailgunner/client/tags.rb', line 21

def delete_tag(id)
  delete("/v3/#{escape @domain}/tags/#{escape id}")
end

#delete_unsubscribe(address_or_id) ⇒ Object


33
34
35
# File 'lib/mailgunner/client/suppressions.rb', line 33

def delete_unsubscribe(address_or_id)
  delete("/v3/#{escape @domain}/unsubscribes/#{escape address_or_id}")
end

#delete_webhook(id) ⇒ Object


21
22
23
# File 'lib/mailgunner/client/webhooks.rb', line 21

def delete_webhook(id)
  delete("/v3/domains/#{escape @domain}/webhooks/#{escape id}")
end

#delete_whitelist(address_or_domain) ⇒ Object


69
70
71
# File 'lib/mailgunner/client/suppressions.rb', line 69

def delete_whitelist(address_or_domain)
  delete("/v3/#{escape @domain}/whitelists/#{escape address_or_domain}")
end

#get_all_ips(params = PARAMS) ⇒ Object


5
6
7
# File 'lib/mailgunner/client/ips.rb', line 5

def get_all_ips(params = PARAMS)
  get('/v3/ips', query: params)
end

#get_bounce(address) ⇒ Object


9
10
11
# File 'lib/mailgunner/client/suppressions.rb', line 9

def get_bounce(address)
  get("/v3/#{escape @domain}/bounces/#{escape address}")
end

#get_bounces(params = PARAMS) ⇒ Object


5
6
7
# File 'lib/mailgunner/client/suppressions.rb', line 5

def get_bounces(params = PARAMS)
  get("/v3/#{escape @domain}/bounces", query: params)
end

#get_bulk_validation(list_id) ⇒ Object


17
18
19
# File 'lib/mailgunner/client/email_validation.rb', line 17

def get_bulk_validation(list_id)
  get("/v4/address/validate/bulk/#{escape list_id}")
end

#get_bulk_validationsObject


9
10
11
# File 'lib/mailgunner/client/email_validation.rb', line 9

def get_bulk_validations
  get('/v4/address/validate/bulk')
end

#get_complaint(address) ⇒ Object


45
46
47
# File 'lib/mailgunner/client/suppressions.rb', line 45

def get_complaint(address)
  get("/v3/#{escape @domain}/complaints/#{escape address}")
end

#get_complaints(params = PARAMS) ⇒ Object


41
42
43
# File 'lib/mailgunner/client/suppressions.rb', line 41

def get_complaints(params = PARAMS)
  get("/v3/#{escape @domain}/complaints", query: params)
end

#get_connection_settingsObject


37
38
39
# File 'lib/mailgunner/client/domains.rb', line 37

def get_connection_settings
  get("/v3/domains/#{escape @domain}/connection")
end

#get_credentialsObject


21
22
23
# File 'lib/mailgunner/client/domains.rb', line 21

def get_credentials
  get("/v3/domains/#{escape @domain}/credentials")
end

#get_domain(name) ⇒ Object


9
10
11
# File 'lib/mailgunner/client/domains.rb', line 9

def get_domain(name)
  get("/v3/domains/#{escape name}")
end

#get_domains(params = PARAMS) ⇒ Object


5
6
7
# File 'lib/mailgunner/client/domains.rb', line 5

def get_domains(params = PARAMS)
  get('/v3/domains', query: params)
end

#get_events(params = PARAMS) ⇒ Object


5
6
7
# File 'lib/mailgunner/client/events.rb', line 5

def get_events(params = PARAMS)
  get("/v3/#{escape @domain}/events", query: params)
end

#get_ip(address) ⇒ Object


9
10
11
# File 'lib/mailgunner/client/ips.rb', line 9

def get_ip(address)
  get("/v3/ips/#{escape address}")
end

#get_ipsObject


13
14
15
# File 'lib/mailgunner/client/ips.rb', line 13

def get_ips
  get("/v3/domains/#{escape @domain}/ips")
end

#get_list(address) ⇒ Object


9
10
11
# File 'lib/mailgunner/client/mailing_lists.rb', line 9

def get_list(address)
  get("/v3/lists/#{escape address}")
end

#get_list_member(list_address, member_address) ⇒ Object


29
30
31
# File 'lib/mailgunner/client/mailing_lists.rb', line 29

def get_list_member(list_address, member_address)
  get("/v3/lists/#{escape list_address}/members/#{escape member_address}")
end

#get_list_members(list_address, params = PARAMS) ⇒ Object


25
26
27
# File 'lib/mailgunner/client/mailing_lists.rb', line 25

def get_list_members(list_address, params = PARAMS)
  get("/v3/lists/#{escape list_address}/members/pages", query: params)
end

#get_lists(params = PARAMS) ⇒ Object


5
6
7
# File 'lib/mailgunner/client/mailing_lists.rb', line 5

def get_lists(params = PARAMS)
  get('/v3/lists/pages', query: params)
end

#get_message(key) ⇒ Object


5
6
7
# File 'lib/mailgunner/client/messages.rb', line 5

def get_message(key)
  get("/v3/domains/#{escape @domain}/messages/#{escape key}")
end

#get_mime_message(key) ⇒ Object


9
10
11
# File 'lib/mailgunner/client/messages.rb', line 9

def get_mime_message(key)
  get("/v3/domains/#{escape @domain}/messages/#{escape key}", headers: {'Accept' => 'message/rfc2822'})
end

#get_route(id) ⇒ Object


9
10
11
# File 'lib/mailgunner/client/routes.rb', line 9

def get_route(id)
  get("/v3/routes/#{escape id}")
end

#get_routes(params = PARAMS) ⇒ Object


5
6
7
# File 'lib/mailgunner/client/routes.rb', line 5

def get_routes(params = PARAMS)
  get('/v3/routes', query: params)
end

#get_tag(id) ⇒ Object


9
10
11
# File 'lib/mailgunner/client/tags.rb', line 9

def get_tag(id)
  get("/v3/#{escape @domain}/tags/#{escape id}")
end

#get_tag_stats(id, params) ⇒ Object


17
18
19
# File 'lib/mailgunner/client/tags.rb', line 17

def get_tag_stats(id, params)
  get("/v3/#{escape @domain}/tags/#{escape id}/stats", query: params)
end

#get_tags(params = PARAMS) ⇒ Object


5
6
7
# File 'lib/mailgunner/client/tags.rb', line 5

def get_tags(params = PARAMS)
  get("/v3/#{escape @domain}/tags", query: params)
end

#get_total_stats(params = PARAMS) ⇒ Object


5
6
7
# File 'lib/mailgunner/client/stats.rb', line 5

def get_total_stats(params = PARAMS)
  get("/v3/#{escape @domain}/stats/total", query: params)
end

#get_tracking_settingsObject


45
46
47
# File 'lib/mailgunner/client/domains.rb', line 45

def get_tracking_settings
  get("/v3/domains/#{escape @domain}/tracking")
end

#get_unsubscribe(address) ⇒ Object


29
30
31
# File 'lib/mailgunner/client/suppressions.rb', line 29

def get_unsubscribe(address)
  get("/v3/#{escape @domain}/unsubscribes/#{escape address}")
end

#get_unsubscribes(params = PARAMS) ⇒ Object


25
26
27
# File 'lib/mailgunner/client/suppressions.rb', line 25

def get_unsubscribes(params = PARAMS)
  get("/v3/#{escape @domain}/unsubscribes", query: params)
end

#get_webhook(id) ⇒ Object


9
10
11
# File 'lib/mailgunner/client/webhooks.rb', line 9

def get_webhook(id)
  get("/v3/domains/#{escape @domain}/webhooks/#{escape id}")
end

#get_webhooksObject


5
6
7
# File 'lib/mailgunner/client/webhooks.rb', line 5

def get_webhooks
  get("/v3/domains/#{escape @domain}/webhooks")
end

#get_whitelist(address_or_domain) ⇒ Object


61
62
63
# File 'lib/mailgunner/client/suppressions.rb', line 61

def get_whitelist(address_or_domain)
  get("/v3/#{escape @domain}/whitelists/#{escape address_or_domain}")
end

#get_whitelists(params = PARAMS) ⇒ Object


57
58
59
# File 'lib/mailgunner/client/suppressions.rb', line 57

def get_whitelists(params = PARAMS)
  get("/v3/#{escape @domain}/whitelists", params)
end

#send_message(attributes = ATTRIBUTES) ⇒ Object


13
14
15
# File 'lib/mailgunner/client/messages.rb', line 13

def send_message(attributes = ATTRIBUTES)
  post("/v3/#{escape @domain}/messages", attributes)
end

#send_mime(mail) ⇒ Object


17
18
19
20
21
22
23
# File 'lib/mailgunner/client/messages.rb', line 17

def send_mime(mail)
  to = ['to', Array(mail.destinations).join(',')]

  message = ['message', mail.encoded, {filename: 'message.mime'}]

  multipart_post("/v3/#{escape @domain}/messages.mime", [to, message])
end

#update_click_tracking_settings(params = PARAMS) ⇒ Object


53
54
55
# File 'lib/mailgunner/client/domains.rb', line 53

def update_click_tracking_settings(params = PARAMS)
  put("/v3/domains/#{escape @domain}/tracking/click", params)
end

#update_connection_settings(attributes) ⇒ Object


41
42
43
# File 'lib/mailgunner/client/domains.rb', line 41

def update_connection_settings(attributes)
  put("/v3/domains/#{escape @domain}/connection", attributes)
end

#update_credentials(login, attributes) ⇒ Object


29
30
31
# File 'lib/mailgunner/client/domains.rb', line 29

def update_credentials(, attributes)
  put("/v3/domains/#{escape @domain}/credentials/#{escape }", attributes)
end

#update_list(address, attributes = ATTRIBUTES) ⇒ Object


17
18
19
# File 'lib/mailgunner/client/mailing_lists.rb', line 17

def update_list(address, attributes = ATTRIBUTES)
  put("/v3/lists/#{escape address}", attributes)
end

#update_list_member(list_address, member_address, member_attributes) ⇒ Object


37
38
39
# File 'lib/mailgunner/client/mailing_lists.rb', line 37

def update_list_member(list_address, member_address, member_attributes)
  put("/v3/lists/#{escape list_address}/members/#{escape member_address}", member_attributes)
end

#update_open_tracking_settings(params = PARAMS) ⇒ Object


49
50
51
# File 'lib/mailgunner/client/domains.rb', line 49

def update_open_tracking_settings(params = PARAMS)
  put("/v3/domains/#{escape @domain}/tracking/open", params)
end

#update_route(id, attributes = ATTRIBUTES) ⇒ Object


17
18
19
# File 'lib/mailgunner/client/routes.rb', line 17

def update_route(id, attributes = ATTRIBUTES)
  put("/v3/routes/#{escape id}", attributes)
end

#update_tag(id, attributes) ⇒ Object


13
14
15
# File 'lib/mailgunner/client/tags.rb', line 13

def update_tag(id, attributes)
  put("/v3/#{escape @domain}/tags/#{escape id}", attributes)
end

#update_unsubscribe_tracking_settings(params = PARAMS) ⇒ Object


57
58
59
# File 'lib/mailgunner/client/domains.rb', line 57

def update_unsubscribe_tracking_settings(params = PARAMS)
  put("/v3/domains/#{escape @domain}/tracking/unsubscribe", params)
end

#update_webhook(id, attributes = ATTRIBUTES) ⇒ Object


17
18
19
# File 'lib/mailgunner/client/webhooks.rb', line 17

def update_webhook(id, attributes = ATTRIBUTES)
  put("/v3/domains/#{escape @domain}/webhooks/#{escape id}", attributes)
end

#validate_address(value) ⇒ Object


5
6
7
# File 'lib/mailgunner/client/email_validation.rb', line 5

def validate_address(value)
  get('/v4/address/validate', query: {address: value})
end