messagebus-sdk 4.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,151 @@
1
+
2
+ dir = File.dirname(__FILE__)
3
+ require "#{dir}/../spec_helper"
4
+ require "#{dir}/../../lib/messagebus-sdk/messagebus_base"
5
+
6
+ class MessagebusTest < MessagebusSDK::MessagebusBase
7
+ def get_test(path)
8
+ make_api_request(path, HTTP_GET)
9
+ end
10
+
11
+ def post_test(path, data)
12
+ make_api_request(path, HTTP_POST, data)
13
+ end
14
+
15
+ def put_test(path, data)
16
+ make_api_request(path, HTTP_PUT, data)
17
+ end
18
+
19
+ def delete_test(path)
20
+ make_api_request(path, HTTP_DELETE)
21
+ end
22
+ end
23
+
24
+ describe MessagebusSDK::MessagebusBase do
25
+
26
+ before do
27
+ FakeWeb.allow_net_connect = false
28
+ @api_key = "7215ee9c7d9dc229d2921a40e899ec5f"
29
+ end
30
+
31
+ describe "messagebus base object set up correctly" do
32
+ it "has correct headers and accepts a custom endpoint" do
33
+ test_endpoint = 'https://testapi-v4.messagebus.com/api/v4'
34
+ client = MessagebusSDK::MessagebusBase.new(@api_key, test_endpoint)
35
+ client.instance_eval('@http').address.should == "testapi-v4.messagebus.com"
36
+ end
37
+ end
38
+
39
+ describe "add cacert file to http communitcations" do
40
+ it "raises error if cert file does not exist" do
41
+ client = MessagebusSDK::MessagebusBase.new(@api_key)
42
+ cert_file_path = File.join(File.dirname(__FILE__), "nofile.pem")
43
+ expect do
44
+ client.cacert_info(cert_file_path)
45
+ end.should raise_error
46
+ end
47
+
48
+ it "accepts a cert file that exists" do
49
+ client = MessagebusSDK::MessagebusBase.new(@api_key)
50
+ cert_file_path = File.join(File.dirname(__FILE__), "cacert.pem")
51
+ expect do
52
+ client.cacert_info(cert_file_path)
53
+ end.should_not raise_error
54
+ end
55
+ end
56
+
57
+ # TODO http testing for correct VERB
58
+ describe "#make_api_request" do
59
+ before do
60
+ @client = MessagebusTest.new(@api_key)
61
+ end
62
+ it "GET" do
63
+ path = "#{API_URL}/get_test"
64
+ FakeWeb.register_uri(:get, path, :body => json_simple_response)
65
+ @client.get_test(path)
66
+
67
+ request = FakeWeb.last_request
68
+ request.method.should == "GET"
69
+ request.body.should be_nil
70
+ request.each_header do |key, value|
71
+ case key
72
+ when "user-agent"
73
+ value.should =~ /^MessagebusAPI*/
74
+ when "x-messagebus-key"
75
+ value.should == @api_key
76
+ end
77
+ end
78
+ end
79
+
80
+ it "POST" do
81
+ path = "#{API_URL}/post_test"
82
+ data = "{\"json\":\"data\"}"
83
+ FakeWeb.register_uri(:post, path, :body => json_simple_response)
84
+ @client.post_test(path, data)
85
+
86
+ request = FakeWeb.last_request
87
+ request.method.should == "POST"
88
+ request.body.should == data
89
+ request.each_header do |key, value|
90
+ case key
91
+ when "user-agent"
92
+ value.should =~ /^MessagebusAPI*/
93
+ when "x-messagebus-key"
94
+ value.should == @api_key
95
+ when "content-type"
96
+ value.should == "application/json; charset=utf-8"
97
+ end
98
+ end
99
+ end
100
+
101
+ it "PUT" do
102
+ path = "#{API_URL}/put_test"
103
+ data = "{\"json\":\"data\"}"
104
+ FakeWeb.register_uri(:put, path, :body => json_simple_response)
105
+ @client.put_test(path, data)
106
+
107
+ request = FakeWeb.last_request
108
+ request.method.should == "PUT"
109
+ request.body.should == data
110
+ request.each_header do |key, value|
111
+ case key
112
+ when "user-agent"
113
+ value.should =~ /^MessagebusAPI*/
114
+ when "x-messagebus-key"
115
+ value.should == @api_key
116
+ when "content-type"
117
+ value.should == "application/json; charset=utf-8"
118
+ end
119
+ end
120
+ end
121
+
122
+ it "DELETE" do
123
+ path = "#{API_URL}/delete_test"
124
+ FakeWeb.register_uri(:delete, path, :body => json_simple_response)
125
+ @client.delete_test(path)
126
+
127
+ request = FakeWeb.last_request
128
+ request.method.should == "DELETE"
129
+ request.body.should be_nil
130
+ request.each_header do |key, value|
131
+ case key
132
+ when "user-agent"
133
+ value.should =~ /^MessagebusAPI*/
134
+ when "x-messagebus-key"
135
+ value.should == @api_key
136
+ end
137
+ end
138
+ end
139
+ end
140
+
141
+ describe "#version" do
142
+ it "retrieves the current version of the API" do
143
+ FakeWeb.register_uri(:get, "https://api-v4.messagebus.com/api/version", :body => json_api_version_results)
144
+ client = MessagebusSDK::MessagebusBase.new(@api_key)
145
+ version = client.api_version
146
+
147
+ version[:statusCode].should == 200
148
+ version[:APIVersion].length.should > 0
149
+ end
150
+ end
151
+ end
@@ -0,0 +1 @@
1
+ # THIS IS ONLY FOR TESTING
@@ -0,0 +1,65 @@
1
+
2
+ dir = File.dirname(__FILE__)
3
+ require "#{dir}/../spec_helper"
4
+ require "#{dir}/../../lib/messagebus-sdk/feedback_client"
5
+
6
+
7
+ describe MessagebusFeedbackClient do
8
+ attr_reader :client, :api_key
9
+
10
+
11
+ before do
12
+ FakeWeb.allow_net_connect = false
13
+ @api_key = "7215ee9c7d9dc229d2921a40e899ec5f"
14
+ @client = MessagebusFeedbackClient.new(@api_key)
15
+ end
16
+
17
+ describe "feedback" do
18
+ it "call #feedback without dates" do
19
+ scope = "all"
20
+ expected_request="#{API_URL}/feedback?useSendTime=true&scope=#{scope}"
21
+
22
+ FakeWeb.register_uri(:get, expected_request, :body => json_feedback(scope))
23
+ response = client.feedback
24
+ FakeWeb.last_request.body.should be_nil
25
+ response.should == json_parse(json_feedback(scope))
26
+ end
27
+
28
+ it "call #feedback with dates" do
29
+ scope = "bounces"
30
+ start_date_str="2011-01-01T04:30:00+00:00"
31
+ end_date_str="2011-01-02T04:30:00+00:00"
32
+ expected_request="#{API_URL}/feedback?useSendTime=true&scope=#{scope}&startDate=#{URI.escape(start_date_str)}&endDate=#{URI.escape(end_date_str)}"
33
+
34
+ FakeWeb.register_uri(:get, expected_request, :body => json_feedback(scope))
35
+ response = client.feedback(start_date_str, end_date_str, scope)
36
+ FakeWeb.last_request.body.should be_nil
37
+ response.should == json_parse(json_feedback(scope))
38
+ end
39
+
40
+ it "call #feedback_by_channel without dates" do
41
+ scope = "all"
42
+ channel_key = "ab487e9d750a3c50876d12e8f381a79f"
43
+ expected_request="#{API_URL}/feedback/channel/#{channel_key}?useSendTime=true&scope=#{scope}"
44
+
45
+ FakeWeb.register_uri(:get, expected_request, :body => json_feedback(scope))
46
+ response = client.feedback_by_channel(channel_key)
47
+ FakeWeb.last_request.body.should be_nil
48
+ response.should == json_parse(json_feedback(scope))
49
+ end
50
+
51
+ it "call #feedback_by_session without dates" do
52
+ scope = "all"
53
+ channel_key = "ab487e9d750a3c50876d12e8f381a79f"
54
+ session_key = "dab775c6e6aa203324598fefbd1e8baf"
55
+
56
+ expected_request="#{API_URL}/feedback/channel/#{channel_key}/session/#{session_key}?useSendTime=true&scope=#{scope}"
57
+
58
+ FakeWeb.register_uri(:get, expected_request, :body => json_feedback(scope))
59
+ response = client.feedback_by_session(channel_key, session_key)
60
+ FakeWeb.last_request.body.should be_nil
61
+ response.should == json_parse(json_feedback(scope))
62
+ end
63
+ end
64
+
65
+ end
@@ -0,0 +1,56 @@
1
+
2
+ dir = File.dirname(__FILE__)
3
+ require "#{dir}/../spec_helper"
4
+ require "#{dir}/../../lib/messagebus-sdk/stats_client"
5
+
6
+ describe MessagebusStatsClient do
7
+ attr_reader :client, :api_key
8
+
9
+ before do
10
+ FakeWeb.allow_net_connect = false
11
+ @api_key = "7215ee9c7d9dc229d2921a40e899ec5f"
12
+ @client = MessagebusStatsClient.new(@api_key)
13
+ end
14
+
15
+ describe "stats" do
16
+ it "#stats with dates" do
17
+ start_date_str="2011-01-01"
18
+ end_date_str="2011-01-02"
19
+
20
+ expected_request="#{API_URL}/stats/email?startDate=#{start_date_str}&endDate=#{end_date_str}"
21
+ FakeWeb.register_uri(:get, expected_request, :body => json_stats)
22
+
23
+ response = client.stats(start_date_str, end_date_str)
24
+ response.should == json_parse(json_stats)
25
+
26
+ response[:stats].length.should == 4
27
+ response[:smtp].length.should == 5
28
+ response[:filter].length.should == 2
29
+ end
30
+
31
+ it "#stats_by_channel with dates" do
32
+ start_date_str="2011-01-01"
33
+ end_date_str="2011-01-02"
34
+ channel_key = "ab487e9d750a3c50876d12e8f381a79f"
35
+
36
+ expected_request="#{API_URL}/stats/email/channel/#{channel_key}?startDate=#{start_date_str}&endDate=#{end_date_str}"
37
+ FakeWeb.register_uri(:get, expected_request, :body => json_stats)
38
+
39
+ response = client.stats_by_channel(channel_key, start_date_str, end_date_str)
40
+ response.should == json_parse(json_stats)
41
+ end
42
+
43
+ it "#stats_by_session with dates" do
44
+ start_date_str="2011-01-01"
45
+ end_date_str="2011-01-02"
46
+ channel_key = "ab487e9d750a3c50876d12e8f381a79f"
47
+ session_key = "dab775c6e6aa203324598fefbd1e8baf"
48
+
49
+ expected_request="#{API_URL}/stats/email/channel/#{channel_key}/session/#{session_key}?startDate=#{start_date_str}&endDate=#{end_date_str}"
50
+ FakeWeb.register_uri(:get, expected_request, :body => json_stats)
51
+
52
+ response = client.stats_by_session(channel_key, session_key, start_date_str, end_date_str)
53
+ response.should == json_parse(json_stats)
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,129 @@
1
+
2
+ dir = File.dirname(__FILE__)
3
+ require "#{dir}/../spec_helper"
4
+ require "#{dir}/../../lib/messagebus-sdk/template_client"
5
+ require "#{dir}/../../lib/messagebus-sdk/messagebus_errors"
6
+
7
+ describe MessagebusTemplateClient do
8
+
9
+ before do
10
+ FakeWeb.allow_net_connect = false
11
+ @api_key = "7215ee9c7d9dc229d2921a40e899ec5f"
12
+ @api_endpoint = "https://templates-v4-jy01-prod.messagebus.com"
13
+ @client = MessagebusTemplateClient.new(@api_key)
14
+
15
+ @test_template = {
16
+ :toName => "{{rcpt_name}}",
17
+ :toEmail => "{{rcpt_email}}",
18
+ :fromName => "{{sender_name}}",
19
+ :fromEmail => "{{sender_email}}",
20
+ :returnPath => "{{return_path}}",
21
+ :subject => "BOB {{{rcpt_name}}}",
22
+ :plaintextBody => "Plain Text Body {{text_value}}",
23
+ :htmlBody => "<p>The test is working</p>",
24
+ :sessionKey => "{{session_key}}",
25
+ :customHeaders => {"X-MessageBus-Test" => "rBob"}
26
+ }
27
+
28
+ end
29
+
30
+ describe "templates" do
31
+ it "#template_version" do
32
+ FakeWeb.register_uri(:get, "#{@api_endpoint}/api/v4/templates/version", :body => json_template_version_results)
33
+ result = @client.template_version
34
+
35
+ result[:statusCode].should == 200
36
+ result[:statusMessage].length.should == 40
37
+ result[:version].length.should > 0
38
+ end
39
+
40
+ it "#create_template" do
41
+ FakeWeb.register_uri(:post, "#{@api_endpoint}/api/v4/templates", :body => json_template_create)
42
+
43
+
44
+ result = @client.create_template(@test_template)
45
+
46
+ result[:statusCode].should == 201
47
+ result[:statusMessage].should == "Template saved"
48
+ result[:templateKey].should =~ /^[0-9a-z]{8}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{12}$/
49
+
50
+ end
51
+
52
+ it "#get_template" do
53
+ template_key = "33ffafac-b15e-4146-b046-14ed897c522b"
54
+
55
+ FakeWeb.register_uri(:get, "#{@api_endpoint}/api/v4/template/#{template_key}", :body => json_template_get)
56
+
57
+ result = @client.get_template(template_key)
58
+
59
+ result[:statusCode].should == 200
60
+ result[:template][:apiKey].should == @api_key
61
+
62
+ @test_template.each do |key, value|
63
+ result[:template].has_key?(key).should be_true
64
+ end
65
+ end
66
+
67
+ it "#templates" do
68
+ # list templates available
69
+ FakeWeb.register_uri(:get, "#{@api_endpoint}/api/v4/templates", :body => json_templates_get)
70
+
71
+ result = @client.templates
72
+
73
+ result[:statusCode].should == 200
74
+ result[:statusMessage].length.should == 0
75
+ result[:count].should == 3
76
+
77
+ result[:templates].each do |template|
78
+ template[:templateKey].should =~ /^[0-9a-z]{8}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{12}$/
79
+ template[:size].should > 0
80
+ end
81
+ end
82
+
83
+ describe "send messages for templates" do
84
+ before do
85
+ @template_params =
86
+ {"rcpt_name" => "Bob",
87
+ "rcpt_email" => "bob@example.com",
88
+ "sender_name" => "Messagebus Ruby SDK",
89
+ "return_path" => "bounce@bounces.messagebus.com",
90
+ "text_value" => "Hello",
91
+ "session_key" => "DEFAULT"
92
+ }
93
+ end
94
+
95
+ it "#send_messages with batch size 25" do
96
+ FakeWeb.register_uri(:post, "#{@api_endpoint}/api/v4/templates/email/send", :body => json_templates_email_send)
97
+
98
+ template_messages = []
99
+ (1..25).each do |i|
100
+ template_messages << @template_params
101
+ end
102
+
103
+ result = @client.send_messages(@template_key, template_messages)
104
+ result[:statusCode].should == 202
105
+ end
106
+
107
+ it "#send_messages with batch size 0" do
108
+ FakeWeb.register_uri(:post, "#{@api_endpoint}/api/v4/templates/email/send", :body => json_templates_email_send_empty)
109
+
110
+ template_messages = []
111
+ result = @client.send_messages(@template_key, template_messages)
112
+ result[:statusCode].should == 202
113
+ end
114
+
115
+ it "#send_messages with batch size 26" do
116
+ FakeWeb.register_uri(:post, "#{@api_endpoint}/api/v4/templates/email/send", :body => json_templates_email_send)
117
+
118
+ template_messages = []
119
+ (1..26).each do |i|
120
+ template_messages << @template_params
121
+ end
122
+
123
+ expect do
124
+ result = @client.send_messages(@template_key, template_messages)
125
+ end.should raise_error(MessagebusSDK::TemplateError, "Max number of template messages per send exceeded 25")
126
+ end
127
+ end
128
+ end
129
+ end
@@ -0,0 +1,19 @@
1
+ # Copyright 2013 Message Bus, Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License"); you may
4
+ # not use this file except in compliance with the License. You may obtain
5
+ # a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12
+ # License for the specific language governing permissions and limitations
13
+ # under the License.
14
+
15
+ class Hash
16
+ def without(key)
17
+ self.dup.tap{|hash| hash.delete(key)}
18
+ end
19
+ end
@@ -0,0 +1,259 @@
1
+ # Copyright 2013 Message Bus, Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License"); you may
4
+ # not use this file except in compliance with the License. You may obtain
5
+ # a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12
+ # License for the specific language governing permissions and limitations
13
+ # under the License.
14
+
15
+ dir = File.dirname(__FILE__)
16
+
17
+ require 'rubygems'
18
+ require 'fakeweb'
19
+ require 'rr'
20
+ require 'json'
21
+ require 'action_mailer'
22
+ require "#{dir}/spec_core_extensions"
23
+ $LOAD_PATH << "#{dir}/../lib/messagebus-sdk"
24
+ require 'messagebus_base'
25
+ require 'api_client'
26
+ require 'actionmailer_client'
27
+ require 'messagebus_errors'
28
+
29
+ API_URL = 'https://api-v4.messagebus.com/api/v4'
30
+
31
+ def json_parse(data)
32
+ JSON.parse(data, :symbolize_names => true)
33
+ end
34
+
35
+ def json_api_version_results
36
+ json = <<JAVASCRIPT
37
+ {"statusCode":200,"statusMessage":"API Version Lookup","statusTime":"2013-03-11T06:16:06.401Z","APIName":"api","APIVersion":"1.1.13.6-final-201302262055"}
38
+ JAVASCRIPT
39
+ json
40
+ end
41
+
42
+ def json_template_version_results
43
+ json = <<JAVASCRIPT
44
+ {"statusCode":200,"statusMessage":"9bdefe3cdcbc97a226c68e2784871f3f5b103c2e","version":"1.2.1","statusTime":"2013-05-02T18:20:32.782Z"}
45
+ JAVASCRIPT
46
+ json
47
+ end
48
+
49
+ def json_simple_response
50
+ json = <<JAVASCRIPT
51
+ {"statusCode":202,"statusMessage":"OK","statusTime":"2011-10-10T21:32:14.195Z"}
52
+ JAVASCRIPT
53
+ json
54
+ end
55
+
56
+ def json_valid_send
57
+ json = <<JAVASCRIPT
58
+ {"statusCode":202,"statusMessage":"OK","statusTime":"2011-10-10T21:32:14.195Z","successCount":1,"failureCount":0,"results":[{"toEmail":"apitest1@messagebus.com","messageId":"51efcf00f38711e0a93640405cc99fee","messageStatus":0}]}
59
+ JAVASCRIPT
60
+ json
61
+ end
62
+
63
+ def json_incomplete_results
64
+ json = <<JAVASCRIPT
65
+ {"statusCode":202}
66
+ JAVASCRIPT
67
+ json
68
+ end
69
+
70
+ def json_invalid_results
71
+ json = <<JAVASCRIPT
72
+ GARBAGE_JSON
73
+ JAVASCRIPT
74
+ json
75
+ end
76
+
77
+ def json_channels
78
+ json = <<JAVASCRIPT
79
+ {"statusCode":200,"statusMessage":"","statusTime":"2011-10-10T21:32:14.195Z",
80
+ "results":[
81
+ {"channelName":"channel1","channelKey":"ab487e9d750a3c50876d12e8f381a79f","defaultSessionKey":"43fd828731048cda3a0a050b22bed4f3","isDefault":true},
82
+ {"channelName":"channel2","channelKey":"9ebd88e34d0e74178cab184e781bafb5","defaultSessionKey":"98432f23b96c8138c2606ef8bebc0a82","isDefault":false}
83
+ ]}
84
+ JAVASCRIPT
85
+ json
86
+ end
87
+
88
+ def json_channel_config
89
+ json = <<JAVASCRIPT
90
+ {"statusCode":200,"statusMessage":"","statusTime":"2011-10-10T21:32:14.195Z",
91
+ "configuration":{
92
+ "addOpenRate":true,
93
+ "openRateCustomDomain":"or.sample.com",
94
+ "addUnsubscribe":true,
95
+ "openRateCustomDomain":"unsub.sample.com",
96
+ "addClickDetection":true,
97
+ "openRateCustomDomain":"cd.sample.com"
98
+ }}
99
+ JAVASCRIPT
100
+ json
101
+ end
102
+
103
+ def json_channel_sessions
104
+ json = <<JAVASCRIPT
105
+ {"statusCode":200,"statusMessage":"","statusTime":"2011-10-10T21:32:14.195Z","count":2
106
+ "results":[
107
+ {"sessionKey":"43fd828731048cda3a0a050b22bed4f3","sessionName":"session1","isDefault":true},
108
+ {"sessionKey":"98432f23b96c8138c2606ef8bebc0a82","sessionName":"session2","isDefault":true}
109
+ ]}
110
+ JAVASCRIPT
111
+ json
112
+ end
113
+
114
+ def json_channel_create_session
115
+ json = <<JAVASCRIPT
116
+ {"statusCode":200,"statusMessage":"","statusTime":"2011-10-10T21:32:14.195Z",
117
+ "sessionName":"new_session",
118
+ "sessionKey":"d2028fa69e46d53d76a84ef13d8d1bb7"
119
+ }
120
+ JAVASCRIPT
121
+ json
122
+ end
123
+
124
+ def json_channel_rename_session
125
+ json = <<JAVASCRIPT
126
+ {"statusCode":200,"statusMessage":"","statusTime":"2011-10-10T21:32:14.195Z",
127
+ "sessionName":"rename_session",
128
+ "sessionKey":"b9c8c04f56e580af6d766419bf1f0716"
129
+ }
130
+ JAVASCRIPT
131
+ json
132
+ end
133
+
134
+ def json_unsubs
135
+ json = <<JAVASCRIPT
136
+ {"statusCode":200,"statusMessage":"","statusTime":"2011-10-10T21:32:14.195Z",
137
+ "unsubs":[
138
+ {"email":"joe@example.com","count":2},
139
+ {"email":"jane@example.com","count":1}
140
+ ]}
141
+ JAVASCRIPT
142
+ json
143
+ end
144
+
145
+ def json_complaints
146
+ json = <<JAVASCRIPT
147
+ {"statusCode":200,"statusMessage":"","statusTime":"2011-10-10T21:32:14.195Z",
148
+ "complaints":[
149
+ {"email":"joe@example.com","count":2},
150
+ {"email":"jane@example.com","count":1}
151
+ ]}
152
+ JAVASCRIPT
153
+ json
154
+ end
155
+
156
+ def json_feedback(scope)
157
+ json = <<JAVASCRIPT
158
+ {"accountId":"2", "channelId":"", "sessionId":"", "startDate":1361908365183, "endDate":1361994765183, "scope":"#{scope}", "useSendTime":"true", "bounces":[], "complaints":[], "unsubscribes":[], "opens":[], "clicks":[], "statusCode":200, "statusMessage":"", "statusTime":"2013-02-27T19:52:45.696Z"}
159
+ JAVASCRIPT
160
+ end
161
+
162
+ def json_stats
163
+ json = <<JAVASCRIPT
164
+ {"statusCode":200,"statusMessage":"","statusTime":"2011-10-10T21:32:14.195Z",
165
+ "stats":
166
+ {"msgAttemptedCount":0, "complaintCount":0,"unsubscribeCount":0,"openCount":0},
167
+ "smtp":
168
+ {"acceptCount":0, "bounceCount":0,"deferralCount":0,"rejectCount":0, "errorCount":0},
169
+ "filter":
170
+ {"rcptBadMailboxCount":0,"rcptChannelBlockCount":0}
171
+ }
172
+ JAVASCRIPT
173
+ json
174
+ end
175
+
176
+ def json_response_201
177
+ json = <<JAVASCRIPT
178
+ {"statusCode":201,"statusMessage":"","statusTime":"2011-10-10T21:32:14.195Z"}
179
+ JAVASCRIPT
180
+ json
181
+ end
182
+
183
+ def json_response_200
184
+ json = <<JAVASCRIPT
185
+ {"statusCode":200,"statusMessage":"","statusTime":"2011-10-10T21:32:14.195Z"}
186
+ JAVASCRIPT
187
+ json
188
+ end
189
+
190
+ def json_response_404
191
+ json = <<JAVASCRIPT
192
+ {"statusCode":404,"statusMessage":"Invalid URL - Mailing list key not found.","statusTime":"2011-10-10T21:32:14.195Z"}
193
+ JAVASCRIPT
194
+ json
195
+ end
196
+
197
+ def json_template_create
198
+ json = <<JAVASCRIPT
199
+ {"templateKey":"33ffafac-b15e-4146-b046-14ed897c522b", "statusCode":201, "statusMessage":"Template saved", "statusTime":"2013-05-02T18:26:27.512Z"}
200
+ JAVASCRIPT
201
+ json
202
+ end
203
+
204
+ def json_template_get
205
+ json = <<JAVASCRIPT
206
+ {"template":{"toEmail":"{{rcpt_email}}","fromEmail":"{{sender_email}}","subject":"BOB {{{rcpt_name}}}","toName":"{{rcpt_name}}","fromName":"{{sender_name}}","returnPath":"{{return_path}}","plaintextBody":"Plain Text Body {{text_value}}","htmlBody":"<p>The test is working</p>","templateKey":"43ffafac-b15e-4146-b046-14ed897c522b","apiKey":"7215ee9c7d9dc229d2921a40e899ec5f","customHeaders":{"X-MessageBus-Test":"rBob","envelope-sender":"{{return_path}}"},"sessionKey":"{{session_key}}","creationTime":"2013-05-02T18:26:27.512Z"},"statusCode":200,"statusMessage":"","statusTime":"2013-05-02T18:34:20.590Z"}
207
+ JAVASCRIPT
208
+ json
209
+ end
210
+
211
+ def json_templates_get
212
+ json = <<JAVASCRIPT
213
+ {"templates":[{"templateKey":"14a47f55-8fe5-49e3-ba41-fa26cb3ca1db","modificationTime":"2013-04-12T06:53:49.000Z","size":639},{"templateKey":"43ffafac-b15e-4146-b046-14ed897c522b","modificationTime":"2013-05-02T18:26:28.000Z","size":584},{"templateKey":"99fb84a3-b4e8-4aeb-8b89-364510becd07","modificationTime":"2013-05-01T04:17:45.000Z","size":584}],"count":3,"statusCode":200,"statusMessage":"","statusTime":"2013-05-02T18:55:11.991Z"}
214
+ JAVASCRIPT
215
+ json
216
+ end
217
+
218
+ def json_templates_email_send
219
+ json = <<JAVASCRIPT
220
+ {"failureCount":0, "results":[{"messageId":"71690500b35b11e28c8290b8d0a751ab", "messageStatus":0, "toEmail":"bob@example.com"}], "statusCode":202, "statusMessage":"", "successCount":1, "statusTime":"2013-05-02T19:06:50.397Z"}
221
+ JAVASCRIPT
222
+ json
223
+ end
224
+
225
+ def json_templates_email_send_empty
226
+ json = <<JAVASCRIPT
227
+ {"failureCount":0, "results":[], "statusCode":202, "statusMessage":"", "successCount":0, "statusTime":"2013-05-02T19:06:50.397Z"}
228
+ JAVASCRIPT
229
+ json
230
+ end
231
+
232
+
233
+ class MessagebusMailer < MessagebusActionMailerClient
234
+ def initialize(*args)
235
+ api_key = "098f6bcd4621d373cade4e832627b4f6"
236
+ super(api_key)
237
+ end
238
+ end
239
+
240
+ ActionMailer::Base.add_delivery_method :messagebus, MessagebusMailer
241
+ ActionMailer::Base.delivery_method = :messagebus
242
+
243
+ class MessageBusActionMailerTest < ActionMailer::Base
244
+ default :from => "Mail Test <no-reply@messagebus.com>",
245
+ :body => "This is a test",
246
+ :subject => "Unit Test",
247
+ :return_path => "bounce@bounce.example.com"
248
+
249
+ def new_message(to_email, session_key, bcc = "", x_headers = {})
250
+ headers[MessagebusSDK::MessagebusBase::HEADER_SESSION_KEY] = session_key
251
+
252
+ x_headers.each do |key, value|
253
+ headers[key] = value
254
+ end
255
+
256
+ mail(:bcc => bcc) if bcc != ""
257
+ mail(:to => to_email)
258
+ end
259
+ end