mailgun-ruby 1.0.3 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/.rubocop.yml +8 -0
- data/.rubocop_todo.yml +22 -0
- data/.ruby-env.yml.example +12 -0
- data/.travis.yml +6 -12
- data/Domains.md +36 -0
- data/MessageBuilder.md +14 -14
- data/Messages.md +44 -30
- data/OptInHandler.md +34 -34
- data/README.md +74 -24
- data/Rakefile +22 -20
- data/Snippets.md +26 -26
- data/Webhooks.md +40 -0
- data/lib/mailgun.rb +26 -228
- data/lib/mailgun/chains.rb +16 -0
- data/lib/mailgun/client.rb +143 -0
- data/lib/mailgun/domains/domains.rb +84 -0
- data/lib/mailgun/events/events.rb +53 -35
- data/lib/mailgun/exceptions/exceptions.rb +43 -10
- data/lib/mailgun/lists/opt_in_handler.rb +18 -19
- data/lib/mailgun/messages/batch_message.rb +31 -48
- data/lib/mailgun/messages/message_builder.rb +160 -144
- data/lib/mailgun/response.rb +55 -0
- data/lib/mailgun/version.rb +2 -3
- data/lib/mailgun/webhooks/webhooks.rb +101 -0
- data/mailgun.gemspec +16 -10
- data/spec/integration/bounces_spec.rb +44 -0
- data/spec/integration/campaign_spec.rb +60 -0
- data/spec/integration/complaints_spec.rb +38 -0
- data/spec/integration/domains_spec.rb +39 -0
- data/spec/integration/email_validation_spec.rb +29 -0
- data/spec/integration/events_spec.rb +20 -0
- data/spec/integration/list_members_spec.rb +63 -0
- data/spec/integration/list_spec.rb +58 -0
- data/spec/integration/mailgun_spec.rb +26 -550
- data/spec/integration/routes_spec.rb +74 -0
- data/spec/integration/stats_spec.rb +15 -0
- data/spec/integration/unsubscribes_spec.rb +42 -0
- data/spec/integration/webhook_spec.rb +54 -0
- data/spec/spec_helper.rb +37 -7
- data/spec/unit/connection/test_client.rb +15 -95
- data/spec/unit/events/events_spec.rb +9 -6
- data/spec/unit/lists/opt_in_handler_spec.rb +6 -4
- data/spec/unit/mailgun_spec.rb +25 -19
- data/spec/unit/messages/batch_message_spec.rb +47 -38
- data/spec/unit/messages/message_builder_spec.rb +282 -111
- data/vcr_cassettes/bounces.yml +175 -0
- data/vcr_cassettes/complaints.yml +175 -0
- data/vcr_cassettes/domains.todo.yml +42 -0
- data/vcr_cassettes/domains.yml +360 -0
- data/vcr_cassettes/email_validation.yml +104 -0
- data/vcr_cassettes/events.yml +61 -0
- data/vcr_cassettes/list_members.yml +320 -0
- data/vcr_cassettes/mailing_list.todo.yml +43 -0
- data/vcr_cassettes/mailing_list.yml +390 -0
- data/vcr_cassettes/routes.yml +359 -0
- data/vcr_cassettes/send_message.yml +107 -0
- data/vcr_cassettes/stats.yml +44 -0
- data/vcr_cassettes/unsubscribes.yml +191 -0
- data/vcr_cassettes/webhooks.yml +276 -0
- metadata +114 -10
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'mailgun'
|
3
|
+
|
4
|
+
vcr_opts = { :cassette_name => "routes" }
|
5
|
+
|
6
|
+
describe 'For the Routes endpoint', order: :defined, vcr: vcr_opts do
|
7
|
+
before(:all) do
|
8
|
+
@mg_obj = Mailgun::Client.new(APIKEY, APIHOST, APIVERSION, SSL)
|
9
|
+
@domain = TESTDOMAIN
|
10
|
+
@forward_to = "alice@#{@domain}"
|
11
|
+
@recipient = ".*@#{@domain}"
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'creates a route' do
|
15
|
+
result = @mg_obj.post("routes", { priority: 10,
|
16
|
+
description: 'Integration Test Route',
|
17
|
+
expression: "match_recipient(\"#{@forward_to}\")",
|
18
|
+
action: "forward(\"#{@recipient}\")" })
|
19
|
+
|
20
|
+
result.to_h!
|
21
|
+
expect(result.body["message"]).to eq("Route has been created")
|
22
|
+
expect(result.body["route"]["description"]).to eq("Integration Test Route")
|
23
|
+
expect(result.body["route"]["actions"]).to include("forward(\"#{@recipient}\")")
|
24
|
+
expect(result.body["route"]["expression"]).to include("match_recipient(\"#{@forward_to}\")")
|
25
|
+
expect(result.body["route"]["priority"]).to eq(10)
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'gets a list of all routes.' do
|
29
|
+
result = @mg_obj.get("routes", {:limit => 50})
|
30
|
+
|
31
|
+
result.to_h!
|
32
|
+
expect(result.body["total_count"]).to be > 0
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'gets the route.' do
|
36
|
+
result = @mg_obj.get("routes", {:limit => 1})
|
37
|
+
route_id = result.to_h['items'].first['id']
|
38
|
+
|
39
|
+
result = @mg_obj.get("routes/#{route_id}")
|
40
|
+
|
41
|
+
result.to_h!
|
42
|
+
expect(result.body["route"]["description"]).to eq("Integration Test Route")
|
43
|
+
expect(result.body["route"]["actions"]).to include("forward(\"#{@recipient}\")")
|
44
|
+
expect(result.body["route"]["expression"]).to include("match_recipient(\"#{@forward_to}\")")
|
45
|
+
expect(result.body["route"]["priority"]).to eq(10)
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'updates the route.' do
|
49
|
+
result = @mg_obj.get("routes", {:limit => 1})
|
50
|
+
route_id = result.to_h['items'].first['id']
|
51
|
+
|
52
|
+
result = @mg_obj.put("routes/#{route_id}", {:priority => 10,
|
53
|
+
:description => 'Integration Test Route Update',
|
54
|
+
:expression => "match_recipient(\"#{@forward_to}\")",
|
55
|
+
:action => "forward(\"#{@recipient}\")"})
|
56
|
+
|
57
|
+
result.to_h!
|
58
|
+
expect(result.body["message"]).to eq("Route has been updated")
|
59
|
+
expect(result.body["description"]).to eq("Integration Test Route Update")
|
60
|
+
expect(result.body["actions"]).to include("forward(\"#{@recipient}\")")
|
61
|
+
expect(result.body["expression"]).to include("match_recipient(\"#{@forward_to}\")")
|
62
|
+
expect(result.body["priority"]).to eq(10)
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'removes a route' do
|
66
|
+
result = @mg_obj.get("routes", {:limit => 1})
|
67
|
+
route_id = result.to_h['items'].first['id']
|
68
|
+
|
69
|
+
@mg_obj.delete("routes/#{route_id}")
|
70
|
+
|
71
|
+
result.to_h!
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'mailgun'
|
3
|
+
|
4
|
+
vcr_opts = { :cassette_name => "stats" }
|
5
|
+
|
6
|
+
describe 'For the Stats endpoint', vcr: vcr_opts do
|
7
|
+
before(:all) do
|
8
|
+
@mg_obj = Mailgun::Client.new(APIKEY, APIHOST, APIVERSION, SSL)
|
9
|
+
@domain = TESTDOMAIN
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'get some stats.' do
|
13
|
+
@mg_obj.get("#{@domain}/stats", {:limit => 50, :skip => 10, :event => 'sent'})
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'mailgun'
|
3
|
+
|
4
|
+
vcr_opts = { :cassette_name => "unsubscribes" }
|
5
|
+
|
6
|
+
describe 'For the Unsubscribes endpoint', order: :defined, vcr: vcr_opts do
|
7
|
+
before(:all) do
|
8
|
+
@mg_obj = Mailgun::Client.new(APIKEY, APIHOST, APIVERSION, SSL)
|
9
|
+
@domain = TESTDOMAIN
|
10
|
+
@email = "integration-test-email@#{TESTDOMAIN}"
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'adds an unsubscriber' do
|
14
|
+
result = @mg_obj.post "#{@domain}/unsubscribes", address: @email, tag: '*'
|
15
|
+
|
16
|
+
result.to_h!
|
17
|
+
expect(result.body["message"]).to eq("Address has been added to the unsubscribes table")
|
18
|
+
expect(result.body["address"]).to eq(@email)
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'get an unsubscribee.' do
|
22
|
+
result = @mg_obj.get "#{@domain}/unsubscribes/#{@email}"
|
23
|
+
|
24
|
+
result.to_h!
|
25
|
+
expect(result.body["address"]).to eq(@email)
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'gets a list of unsubscribes.' do
|
29
|
+
result = @mg_obj.get "#{@domain}/unsubscribes"
|
30
|
+
|
31
|
+
result.to_h!
|
32
|
+
expect(result.body["items"].length).to be > 0
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'removes an unsubscribee' do
|
36
|
+
result = @mg_obj.delete "#{@domain}/unsubscribes/#{@email}"
|
37
|
+
|
38
|
+
result.to_h!
|
39
|
+
expect(result.body['address']).to eq(@email)
|
40
|
+
expect(result.body["message"]).to eq("Unsubscribe event has been removed")
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'mailgun'
|
3
|
+
|
4
|
+
vcr_opts = { :cassette_name => "webhooks" }
|
5
|
+
|
6
|
+
describe 'For the webhooks endpoint', order: :defined, vcr: vcr_opts do
|
7
|
+
before(:all) do
|
8
|
+
@mg_obj = Mailgun::Client.new(APIKEY, APIHOST, APIVERSION, SSL)
|
9
|
+
@domain = TESTDOMAIN
|
10
|
+
@testhook = 'bounce'
|
11
|
+
@testhookup = 'bounceup'
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'creates a webhook' do
|
15
|
+
result = @mg_obj.post("domains/#{@domain}/webhooks", { id: 'bounce',
|
16
|
+
url: "http://example.com/mailgun/events/#{@testhook}" } )
|
17
|
+
|
18
|
+
result.to_h!
|
19
|
+
expect(result.body["message"]).to eq("Webhook has been created")
|
20
|
+
expect(result.body["webhook"]["url"]).to eq("http://example.com/mailgun/events/#{@testhook}")
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'gets a webhook.' do
|
24
|
+
result = @mg_obj.get("domains/#{@domain}/webhooks/#{@testhook}")
|
25
|
+
|
26
|
+
result.to_h!
|
27
|
+
expect(result.body["webhook"]["url"]).to eq("http://example.com/mailgun/events/#{@testhook}")
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'gets a list of all webhooks.' do
|
31
|
+
result = @mg_obj.get("domains/#{@domain}/webhooks")
|
32
|
+
|
33
|
+
result.to_h!
|
34
|
+
expect(result.body["webhooks"]["bounce"]["url"]).to eq("http://example.com/mailgun/events/#{@testhook}")
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'updates a webhook.' do
|
38
|
+
result = @mg_obj.put("domains/#{@domain}/webhooks/bounce", {:id => 'bounce',
|
39
|
+
:url => "http://example.com/mailgun/events/#{@testhookup}"})
|
40
|
+
|
41
|
+
result.to_h!
|
42
|
+
expect(result.body["message"]).to eq("Webhook has been updated")
|
43
|
+
expect(result.body["webhook"]["url"]).to eq("http://example.com/mailgun/events/#{@testhookup}")
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'removes a webhook' do
|
47
|
+
result = @mg_obj.delete("domains/#{@domain}/webhooks/bounce")
|
48
|
+
|
49
|
+
result.to_h!
|
50
|
+
expect(result.body['message']).to eq("Webhook has been deleted")
|
51
|
+
expect(result.body['webhook']['url']).to eq("http://example.com/mailgun/events/#{@testhookup}")
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,15 +1,45 @@
|
|
1
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
1
|
require 'rubygems'
|
4
2
|
require 'bundler'
|
5
3
|
require 'bundler/setup'
|
6
4
|
Bundler.setup(:development)
|
5
|
+
|
6
|
+
require 'simplecov'
|
7
|
+
SimpleCov.start do
|
8
|
+
add_filter "/spec/"
|
9
|
+
end
|
10
|
+
|
7
11
|
require 'mailgun'
|
12
|
+
|
13
|
+
require 'vcr'
|
14
|
+
require 'webmock/rspec'
|
15
|
+
|
16
|
+
#WebMock.disable_net_connect!(allow_localhost: true)
|
8
17
|
require_relative 'unit/connection/test_client'
|
9
18
|
|
10
|
-
|
11
|
-
|
12
|
-
|
19
|
+
RSpec.configure do |c|
|
20
|
+
c.raise_errors_for_deprecations!
|
21
|
+
end
|
22
|
+
|
13
23
|
APIHOST = "api.mailgun.net"
|
14
|
-
APIVERSION = "
|
15
|
-
SSL= true
|
24
|
+
APIVERSION = "v3"
|
25
|
+
SSL = true
|
26
|
+
|
27
|
+
# For integration tests modify .ruby-env.yml
|
28
|
+
# use .ruby-env.yml.example for an example
|
29
|
+
# alternatively
|
30
|
+
# set environment variables as named in .ruby-env.yml.example
|
31
|
+
envfile = File.join(File.dirname(__FILE__), '..','.ruby-env.yml')
|
32
|
+
envs = File.exist?(envfile) ? YAML.load_file(envfile) : ENV
|
33
|
+
APIKEY = envs['MAILGUN_APIKEY']
|
34
|
+
PUB_APIKEY = envs['MAILGUN_PUB_APIKEY']
|
35
|
+
TESTDOMAIN = envs['MAILGUN_TESTDOMAIN']
|
36
|
+
|
37
|
+
VCR.configure do |c|
|
38
|
+
c.cassette_library_dir = 'vcr_cassettes'
|
39
|
+
c.hook_into :webmock
|
40
|
+
c.configure_rspec_metadata!
|
41
|
+
c.default_cassette_options = { record: :new_episodes }
|
42
|
+
c.filter_sensitive_data('<APIKEY>') { APIKEY }
|
43
|
+
c.filter_sensitive_data('DOMAIN.TEST') { TESTDOMAIN }
|
44
|
+
c.filter_sensitive_data('<PUBKEY>') { PUB_APIKEY }
|
45
|
+
end
|
@@ -1,9 +1,8 @@
|
|
1
|
-
require 'spec_helper'
|
2
1
|
require 'time'
|
3
2
|
require 'json'
|
4
3
|
|
5
4
|
module Mailgun
|
6
|
-
class UnitClient
|
5
|
+
class UnitClient < Mailgun::Client
|
7
6
|
|
8
7
|
attr_reader :options, :block, :body, :code, :response
|
9
8
|
|
@@ -43,32 +42,33 @@ module Mailgun
|
|
43
42
|
|
44
43
|
def post(path, data)
|
45
44
|
begin
|
46
|
-
Response.new(response_generator(@endpoint))
|
47
|
-
rescue
|
45
|
+
Mailgun::Response.new(response_generator(@endpoint))
|
46
|
+
rescue => e
|
47
|
+
p e
|
48
48
|
raise CommunicationError.new(e), e.response
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
52
|
def get(path, query_string = nil)
|
53
53
|
begin
|
54
|
-
Response.new(response_generator(@endpoint))
|
55
|
-
rescue
|
54
|
+
Mailgun::Response.new(response_generator(@endpoint))
|
55
|
+
rescue => e
|
56
56
|
raise CommunicationError.new(e), e.response
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
60
60
|
def put(path, data)
|
61
61
|
begin
|
62
|
-
Response.new(response_generator(@endpoint))
|
63
|
-
rescue
|
62
|
+
Mailgun::Response.new(response_generator(@endpoint))
|
63
|
+
rescue => e
|
64
64
|
raise CommunicationError.new(e), e.response
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
68
68
|
def delete(path)
|
69
69
|
begin
|
70
|
-
Response.new(response_generator(@endpoint))
|
71
|
-
rescue
|
70
|
+
Mailgun::Response.new(response_generator(@endpoint))
|
71
|
+
rescue => e
|
72
72
|
raise CommunicationError.new(e), e.response
|
73
73
|
end
|
74
74
|
end
|
@@ -79,101 +79,21 @@ module Mailgun
|
|
79
79
|
if resource_endpoint == "messages"
|
80
80
|
t = Time.now
|
81
81
|
id = "<#{t.to_i}.#{rand(99999999)}.5817@example.com>"
|
82
|
-
return JSON.generate({"message" => "Queued. Thank you.", "id" => id})
|
82
|
+
return OpenStruct.new({ "body" => JSON.generate({"message" => "Queued. Thank you.", "id" => id}) })
|
83
83
|
end
|
84
84
|
if resource_endpoint == "bounces"
|
85
|
-
return JSON.generate({"total_count" => 1, "items" => {"created_at" => "Fri, 21 Oct 2011 11:02:55 GMT", "code" => 550, "address" => "baz@example.com", "error" => "Message was not accepted -- invalid mailbox. Local mailbox baz@example.com is unavailable: user not found"}})
|
85
|
+
return OpenStruct.new({ "body" => JSON.generate({"total_count" => 1, "items" => {"created_at" => "Fri, 21 Oct 2011 11:02:55 GMT", "code" => 550, "address" => "baz@example.com", "error" => "Message was not accepted -- invalid mailbox. Local mailbox baz@example.com is unavailable: user not found"}}) })
|
86
86
|
end
|
87
87
|
if resource_endpoint == "lists"
|
88
|
-
return JSON.generate({"member" => {"vars" => {"age" => 26}, "name" => "Foo Bar", "subscribed" => false, "address" => "bar@example.com"}, "message" => "Mailing list member has been updated"})
|
88
|
+
return OpenStruct.new({ "body" => JSON.generate({"member" => {"vars" => {"age" => 26}, "name" => "Foo Bar", "subscribed" => false, "address" => "bar@example.com"}, "message" => "Mailing list member has been updated"}) })
|
89
89
|
end
|
90
90
|
if resource_endpoint == "campaigns"
|
91
|
-
return JSON.generate({"message" => "Campaign has been deleted", "id" => "ABC123"})
|
91
|
+
return OpenStruct.new({ "body" => JSON.generate({"message" => "Campaign has been deleted", "id" => "ABC123"}) })
|
92
92
|
end
|
93
93
|
if resource_endpoint == "events"
|
94
|
-
return JSON.generate({"items" => [], "paging" => {"next"=> "https://api.mailgun.net/
|
94
|
+
return OpenStruct.new({ "body" => JSON.generate({"items" => [], "paging" => {"next"=> "https://api.mailgun.net/v3/thisisatestdomainformailgun.com/events/W3siYiI6ICIyMDE0LTA1LTA3VDAwOjQ1OjUxLjc0MDg5MiswMDowMCIsICJlIjogIjIwMTQtMDUtMDVUMDA6NDU6NTEuNzQwOTgzKzAwOjAwIn0sIHsiYiI6ICIyMDE0LTA1LTA3VDAwOjQ1OjUxLjc0MDg5MiswMDowMCIsICJlIjogIjIwMTQtMDUtMDVUMDA6NDU6NTEuNzQwOTgzKzAwOjAwIn0sIFsiZiJdLCBudWxsLCB7ImFjY291bnQuaWQiOiAiNGU4MjMwZjYxNDc2ZDg2NzEzMDBjNDc2IiwgImRvbWFpbi5uYW1lIjogInRoaXNpc2F0ZXN0ZG9tYWluZm9ybWFpbGd1bi5jb20iLCAic2V2ZXJpdHkiOiAiTk9UIGludGVybmFsIn0sIDEwMCwgbnVsbF0=", "previous"=> "https://api.mailgun.net/v2/thisisatestdomainformailgun.com/events/W3siYiI6ICIyMDE0LTA1LTA3VDAwOjQ1OjUxLjc0MDg5MiswMDowMCIsICJlIjogIjIwMTQtMDUtMDVUMDA6NDU6NTEuNzQwOTgzKzAwOjAwIn0sIHsiYiI6ICIyMDE0LTA1LTA3VDAwOjQ1OjUxLjc0MDg5MiswMDowMCIsICJlIjogIjIwMTQtMDUtMDdUMDA6NDU6NTEuNzQxODkyKzAwOjAwIn0sIFsicCIsICJmIl0sIG51bGwsIHsiYWNjb3VudC5pZCI6ICI0ZTgyMzBmNjE0NzZkODY3MTMwMGM0NzYiLCAiZG9tYWluLm5hbWUiOiAidGhpc2lzYXRlc3Rkb21haW5mb3JtYWlsZ3VuLmNvbSIsICJzZXZlcml0eSI6ICJOT1QgaW50ZXJuYWwifSwgMTAwLCBudWxsXQ=="}}) })
|
95
95
|
end
|
96
96
|
end
|
97
97
|
end
|
98
98
|
|
99
|
-
class Response
|
100
|
-
|
101
|
-
attr_accessor :body
|
102
|
-
|
103
|
-
def initialize(response)
|
104
|
-
@body = response
|
105
|
-
end
|
106
|
-
|
107
|
-
# Return response as Ruby Hash
|
108
|
-
#
|
109
|
-
# @return [Hash] A standard Ruby Hash containing the HTTP result.
|
110
|
-
|
111
|
-
def to_h
|
112
|
-
begin
|
113
|
-
JSON.parse(@body)
|
114
|
-
rescue Exception => e
|
115
|
-
raise ParseError.new(e), e
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
# Replace @body with Ruby Hash
|
120
|
-
#
|
121
|
-
# @return [Hash] A standard Ruby Hash containing the HTTP result.
|
122
|
-
|
123
|
-
def to_h!
|
124
|
-
begin
|
125
|
-
@body = JSON.parse(@body)
|
126
|
-
rescue Exception => e
|
127
|
-
raise ParseError.new(e), e
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
# Return response as Yaml
|
132
|
-
#
|
133
|
-
# @return [String] A string containing response as YAML
|
134
|
-
|
135
|
-
def to_yaml
|
136
|
-
begin
|
137
|
-
YAML::dump(JSON.parse(@body))
|
138
|
-
rescue Exception => e
|
139
|
-
raise ParseError.new(e), e
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|
143
|
-
# Replace @body with YAML
|
144
|
-
#
|
145
|
-
# @return [String] A string containing response as YAML
|
146
|
-
|
147
|
-
def to_yaml!
|
148
|
-
begin
|
149
|
-
@body = YAML::dump(JSON.parse(@body))
|
150
|
-
rescue Exception => e
|
151
|
-
raise ParseError.new(e), e
|
152
|
-
end
|
153
|
-
end
|
154
|
-
|
155
|
-
# Return response as Yaml
|
156
|
-
#
|
157
|
-
# @return [String] A string containing response as YAML
|
158
|
-
|
159
|
-
def to_y
|
160
|
-
begin
|
161
|
-
YAML::dump(JSON.parse(@body))
|
162
|
-
rescue Exception => e
|
163
|
-
raise ParseError.new(e), e
|
164
|
-
end
|
165
|
-
end
|
166
|
-
|
167
|
-
# Replace @body with YAML
|
168
|
-
#
|
169
|
-
# @return [String] A string containing response as YAML
|
170
|
-
|
171
|
-
def to_y!
|
172
|
-
begin
|
173
|
-
@body = YAML::dump(JSON.parse(@body))
|
174
|
-
rescue Exception => e
|
175
|
-
raise ParseError.new(e), e
|
176
|
-
end
|
177
|
-
end
|
178
|
-
end
|
179
99
|
end
|
@@ -5,8 +5,9 @@ describe 'The method get' do
|
|
5
5
|
@mg_obj = Mailgun::UnitClient.new('events')
|
6
6
|
events = Mailgun::Events.new(@mg_obj, "samples.mailgun.org")
|
7
7
|
result = events.get()
|
8
|
-
|
9
|
-
result.body.
|
8
|
+
|
9
|
+
expect(result.body).to include("items")
|
10
|
+
expect(result.body).to include("paging")
|
10
11
|
end
|
11
12
|
end
|
12
13
|
|
@@ -16,8 +17,9 @@ describe 'The method next' do
|
|
16
17
|
@mg_obj = Mailgun::UnitClient.new('events')
|
17
18
|
events = Mailgun::Events.new(@mg_obj, "samples.mailgun.org")
|
18
19
|
result = events.next()
|
19
|
-
|
20
|
-
result.body.
|
20
|
+
|
21
|
+
expect(result.body).to include("items")
|
22
|
+
expect(result.body).to include("paging")
|
21
23
|
end
|
22
24
|
end
|
23
25
|
|
@@ -26,7 +28,8 @@ describe 'The method previous' do
|
|
26
28
|
@mg_obj = Mailgun::UnitClient.new('events')
|
27
29
|
events = Mailgun::Events.new(@mg_obj, "samples.mailgun.org")
|
28
30
|
result = events.previous()
|
29
|
-
|
30
|
-
result.body.
|
31
|
+
|
32
|
+
expect(result.body).to include("items")
|
33
|
+
expect(result.body).to include("paging")
|
31
34
|
end
|
32
35
|
end
|
@@ -10,13 +10,15 @@ describe 'The method generate_hash' do
|
|
10
10
|
|
11
11
|
it 'generates a web safe hash for the recipient wishing to subscribe' do
|
12
12
|
my_hash = Mailgun::OptInHandler.generate_hash(@mailing_list, @secret_app_id, @recipient_address)
|
13
|
-
|
13
|
+
|
14
|
+
expect(my_hash).to eq(@precalculated_hash)
|
14
15
|
end
|
15
16
|
|
16
17
|
it 'generates a web safe hash for the recipient wishing to subscribe' do
|
17
18
|
validate_result = Mailgun::OptInHandler.validate_hash(@secret_app_id, @precalculated_hash)
|
18
|
-
|
19
|
-
validate_result
|
20
|
-
validate_result['
|
19
|
+
|
20
|
+
expect(validate_result.length).to eq(2)
|
21
|
+
expect(validate_result['recipient_address']).to eq(@recipient_address)
|
22
|
+
expect(validate_result['mailing_list']).to eq(@mailing_list)
|
21
23
|
end
|
22
24
|
end
|