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 Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/mailgunner/client.rb', line 10

def initialize(options = {})
  @domain = options.fetch(:domain) { default_domain }

  @api_key = options.fetch(:api_key) { ENV.fetch('MAILGUN_API_KEY') }

  @api_host = options.fetch(:api_host) { 'api.mailgun.net' }

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

  @http.use_ssl = true
end

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



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

def api_key
  @api_key
end

#domainObject

Returns the value of attribute domain.



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

def domain
  @domain
end

#httpObject

Returns the value of attribute http.



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

def http
  @http
end

Instance Method Details

#add_bounce(attributes = {}) ⇒ Object



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

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

#add_complaint(attributes = {}) ⇒ Object



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

def add_complaint(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 = {}) ⇒ Object



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

def add_domain(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 = {}) ⇒ Object



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

def add_list(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 = {}) ⇒ Object



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

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

#add_unsubscribe(attributes = {}) ⇒ Object



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

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

#add_webhook(attributes = {}) ⇒ Object



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

def add_webhook(attributes = {})
  post("/v3/domains/#{escape @domain}/webhooks", attributes)
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

#get_all_ips(params = {}) ⇒ Object



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

def get_all_ips(params = {})
  get('/v3/ips', 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 = {}) ⇒ Object



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

def get_bounces(params = {})
  get("/v3/#{escape @domain}/bounces", params)
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 = {}) ⇒ Object



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

def get_complaints(params = {})
  get("/v3/#{escape @domain}/complaints", 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 = {}) ⇒ Object



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

def get_domains(params = {})
  get('/v3/domains', params)
end

#get_events(params = {}) ⇒ Object



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

def get_events(params = {})
  get("/v3/#{escape @domain}/events", 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 = {}) ⇒ Object



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

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

#get_lists(params = {}) ⇒ Object



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

def get_lists(params = {})
  get('/v3/lists', 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}", {}, {'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 = {}) ⇒ Object



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

def get_routes(params = {})
  get('/v3/routes', params)
end

#get_stats(params = {}) ⇒ Object



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

def get_stats(params = {})
  Kernel.warn 'Mailgunner::Client#get_stats is deprecated'

  get("/v3/#{escape @domain}/stats", 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", params)
end

#get_tags(params = {}) ⇒ Object



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

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

#get_total_stats(params = {}) ⇒ Object



11
12
13
# File 'lib/mailgunner/client/stats.rb', line 11

def get_total_stats(params = {})
  get("/v3/#{escape @domain}/stats/total", params)
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 = {}) ⇒ Object



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

def get_unsubscribes(params = {})
  get("/v3/#{escape @domain}/unsubscribes", 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

#parse_addresses(values) ⇒ Object



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

def parse_addresses(values)
  get('/v3/address/parse', addresses: Array(values).join(','))
end

#send_message(attributes = {}) ⇒ Object



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

def send_message(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_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 = {}) ⇒ Object



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

def update_list(address, 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_route(id, attributes = {}) ⇒ Object



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

def update_route(id, 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_webhook(id, attributes = {}) ⇒ Object



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

def update_webhook(id, 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('/v3/address/validate', address: value)
end