messagebus_ruby_api 1.0.6 → 1.0.10
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.
- data/Gemfile +1 -0
- data/lib/messagebus_ruby_api/messagebus.rb +57 -0
- data/lib/messagebus_ruby_api/version.rb +1 -1
- data/spec/messagebus_ruby_api/messagebus_spec.rb +67 -0
- data/spec/spec_helper.rb +14 -0
- metadata +3 -3
data/Gemfile
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
12
12
|
# License for the specific language governing permissions and limitations
|
|
13
13
|
# under the License.
|
|
14
|
+
require 'net/http/post/multipart'
|
|
14
15
|
|
|
15
16
|
module MessagebusApi
|
|
16
17
|
DEFAULT_API_ENDPOINT_STRING = 'https://api.messagebus.com'
|
|
@@ -95,6 +96,42 @@ module MessagebusApi
|
|
|
95
96
|
make_api_get_call(@rest_endpoints[:mailing_lists])
|
|
96
97
|
end
|
|
97
98
|
|
|
99
|
+
def upload_mailing_list(name, file_path)
|
|
100
|
+
path = @rest_endpoints[:mailing_lists_upload]
|
|
101
|
+
File.open(file_path) do |f|
|
|
102
|
+
headers = common_http_headers.merge(rest_upload_headers)
|
|
103
|
+
req = Net::HTTP::Post::Multipart.new path, {:jsonData => "{\"name\":\"#{name}\"}", "fileData" => UploadIO.new(f, "text/plain", file_path)}, headers
|
|
104
|
+
@results = @http.request(req)
|
|
105
|
+
end
|
|
106
|
+
check_response(@results)
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def mailing_list_delete(mailing_list_key)
|
|
110
|
+
path = @rest_endpoints[:mailing_list_delete].gsub("%KEY%", mailing_list_key)
|
|
111
|
+
@results = make_api_delete_call(path)
|
|
112
|
+
@results
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
def campaigns
|
|
116
|
+
path = @rest_endpoints[:campaigns]
|
|
117
|
+
@results = make_api_get_call(path)
|
|
118
|
+
@results
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
def campaigns_send(params)
|
|
122
|
+
path = @rest_endpoints[:campaigns_send]
|
|
123
|
+
campaign_params = base_campaign_params.merge!(params)
|
|
124
|
+
json = campaign_params.to_json
|
|
125
|
+
@results = make_api_post_call(path, json)
|
|
126
|
+
@results
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
def campaign_status(campaign_key)
|
|
130
|
+
path = @rest_endpoints[:campaign_status].gsub("%KEY%", campaign_key)
|
|
131
|
+
@results = make_api_get_call(path)
|
|
132
|
+
@results
|
|
133
|
+
end
|
|
134
|
+
|
|
98
135
|
def delete_mailing_list_entry(mailing_list_key, email)
|
|
99
136
|
path = @rest_endpoints[:mailing_lists_entry_email].gsub("%KEY%", mailing_list_key).gsub("%EMAIL%", email)
|
|
100
137
|
@results = make_api_delete_call(path)
|
|
@@ -165,6 +202,10 @@ module MessagebusApi
|
|
|
165
202
|
{"Content-Type" => "application/json; charset=utf-8"}
|
|
166
203
|
end
|
|
167
204
|
|
|
205
|
+
def rest_upload_headers
|
|
206
|
+
{"Content-Type" => "multipart/form-data; charset=utf-8"}
|
|
207
|
+
end
|
|
208
|
+
|
|
168
209
|
def add_email_message(params)
|
|
169
210
|
@msg_type = EMAIL if @msg_type == nil
|
|
170
211
|
@msg_buffer << base_message_params.merge!(params)
|
|
@@ -267,8 +308,13 @@ module MessagebusApi
|
|
|
267
308
|
:unsubscribes => "/api/v3/unsubscribes",
|
|
268
309
|
:feedbackloops => "/api/v3/feedbackloops",
|
|
269
310
|
:mailing_lists => "/api/v3/mailing_lists",
|
|
311
|
+
:mailing_lists_upload => "/api/v3/mailing_lists/upload",
|
|
312
|
+
:mailing_list_delete => "/api/v3/mailing_list/%KEY%",
|
|
270
313
|
:mailing_lists_entries => "/api/v3/mailing_list/%KEY%/entries",
|
|
271
314
|
:mailing_lists_entry_email => "/api/v3/mailing_list/%KEY%/entry/%EMAIL%",
|
|
315
|
+
:campaigns_send => "/api/v3/campaigns/send",
|
|
316
|
+
:campaign_status => "/api/v3/campaign/%KEY%/status",
|
|
317
|
+
:campaigns => "/api/v3/campaigns",
|
|
272
318
|
:version => "/api/version"
|
|
273
319
|
}
|
|
274
320
|
end
|
|
@@ -320,5 +366,16 @@ module MessagebusApi
|
|
|
320
366
|
:customHeaders => {}}
|
|
321
367
|
end
|
|
322
368
|
|
|
369
|
+
def base_campaign_params
|
|
370
|
+
{:campaignName => '',
|
|
371
|
+
:fromName => '',
|
|
372
|
+
:fromEmail => '',
|
|
373
|
+
:subject => '',
|
|
374
|
+
:mailingListKey => '',
|
|
375
|
+
:htmlBody => '',
|
|
376
|
+
:plaintextBody => '',
|
|
377
|
+
:tags => [],
|
|
378
|
+
:customHeaders => {}}
|
|
379
|
+
end
|
|
323
380
|
end
|
|
324
381
|
end
|
|
@@ -302,6 +302,18 @@ describe MessagebusApi::Messagebus do
|
|
|
302
302
|
end
|
|
303
303
|
|
|
304
304
|
describe "#mailing_lists" do
|
|
305
|
+
it "uploads a mailing list" do
|
|
306
|
+
name = 'mylist'
|
|
307
|
+
filename = File.dirname(__FILE__) + '/../../examples/example_maillist.txt'
|
|
308
|
+
expected_request="https://api.messagebus.com/api/v3/mailing_lists/upload"
|
|
309
|
+
|
|
310
|
+
FakeWeb.register_uri(:post, expected_request, :body => json_mailing_list_upload)
|
|
311
|
+
expect do
|
|
312
|
+
response = client.upload_mailing_list(name, filename)
|
|
313
|
+
response.should == json_parse(json_mailing_list_upload)
|
|
314
|
+
end.should_not raise_error
|
|
315
|
+
end
|
|
316
|
+
|
|
305
317
|
it "get mailing lists" do
|
|
306
318
|
expected_request="https://api.messagebus.com/api/v3/mailing_lists"
|
|
307
319
|
|
|
@@ -311,6 +323,61 @@ describe MessagebusApi::Messagebus do
|
|
|
311
323
|
response.should == json_parse(json_mailing_lists)
|
|
312
324
|
end.should_not raise_error
|
|
313
325
|
end
|
|
326
|
+
|
|
327
|
+
it "deletes a mailing list" do
|
|
328
|
+
mailing_list_key = "7215ee9c7d9dc229d2921a40e899ec5f"
|
|
329
|
+
expected_request="https://api.messagebus.com/api/v3/mailing_list/7215ee9c7d9dc229d2921a40e899ec5f"
|
|
330
|
+
|
|
331
|
+
FakeWeb.register_uri(:delete, expected_request, :body => json_mailing_lists)
|
|
332
|
+
expect do
|
|
333
|
+
response = client.mailing_list_delete(mailing_list_key)
|
|
334
|
+
response.should == json_parse(json_mailing_lists)
|
|
335
|
+
end.should_not raise_error
|
|
336
|
+
end
|
|
337
|
+
end
|
|
338
|
+
|
|
339
|
+
describe "#campaigns" do
|
|
340
|
+
it "sends a campaign with a mailing list key" do
|
|
341
|
+
campaign_params = {:campaignName => 'MessageBus Test Campaign',
|
|
342
|
+
:fromName => 'Message Bus',
|
|
343
|
+
:fromEmail => 'do.not.reply@messagebus.com',
|
|
344
|
+
:subject => 'This is a test campaign',
|
|
345
|
+
:mailingListKey => '7215ee9c7d9dc229d2921a40e899ec5f',
|
|
346
|
+
:htmlBody => "<html><body>This message is only a test sent by the Ruby Message Bus client library.</body></html>",
|
|
347
|
+
:plaintextBody => 'This message is only a test sent by the Ruby Message Bus client library.',
|
|
348
|
+
:tags => ['RUBY', 'Unit Test Ruby'],
|
|
349
|
+
:customHeaders => {"sender"=>"apitest1@messagebus.com"}}
|
|
350
|
+
|
|
351
|
+
|
|
352
|
+
expected_request="https://api.messagebus.com/api/v3/campaigns/send"
|
|
353
|
+
|
|
354
|
+
FakeWeb.register_uri(:post, expected_request, :body => json_campaign_send)
|
|
355
|
+
expect do
|
|
356
|
+
response = client.campaigns_send(campaign_params)
|
|
357
|
+
response.should == json_parse(json_campaign_send)
|
|
358
|
+
end.should_not raise_error
|
|
359
|
+
end
|
|
360
|
+
|
|
361
|
+
it "retrieves completed status with campaign key" do
|
|
362
|
+
campaign_key="7215ee9c7d9dc229d2921a40e899ec5f"
|
|
363
|
+
|
|
364
|
+
expected_request="https://api.messagebus.com/api/v3/campaign/#{campaign_key}/status"
|
|
365
|
+
|
|
366
|
+
FakeWeb.register_uri(:get, expected_request, :body => json_stats)
|
|
367
|
+
expect do
|
|
368
|
+
response = client.campaign_status(campaign_key)
|
|
369
|
+
response.should == json_parse(json_stats)
|
|
370
|
+
end.should_not raise_error
|
|
371
|
+
end
|
|
372
|
+
|
|
373
|
+
it "retrieves a list of campaigns" do
|
|
374
|
+
expected_request="https://api.messagebus.com/api/v3/campaigns"
|
|
375
|
+
FakeWeb.register_uri(:get, expected_request, :body => json_stats)
|
|
376
|
+
expect do
|
|
377
|
+
response = client.campaigns
|
|
378
|
+
response.should == json_parse(json_stats)
|
|
379
|
+
end.should_not raise_error
|
|
380
|
+
end
|
|
314
381
|
end
|
|
315
382
|
|
|
316
383
|
describe "#stats" do
|
data/spec/spec_helper.rb
CHANGED
|
@@ -51,6 +51,13 @@ JAVASCRIPT
|
|
|
51
51
|
json
|
|
52
52
|
end
|
|
53
53
|
|
|
54
|
+
def json_mailing_list_upload
|
|
55
|
+
json = <<JAVASCRIPT
|
|
56
|
+
{"invalidCount":1,"invalidLines":[3],"key":"392d08c0694811e1a7dd4040f34d0a26","statusCode":201,"statusMessage":"","statusTime":"2012-03-08T17:57:51.596Z","validCount":2}
|
|
57
|
+
JAVASCRIPT
|
|
58
|
+
json
|
|
59
|
+
end
|
|
60
|
+
|
|
54
61
|
def json_mailing_list_create
|
|
55
62
|
json = <<JAVASCRIPT
|
|
56
63
|
{"statusCode":201,"statusMessage":"","statusTime":"2011-10-10T21:32:14.195Z","key":"51efcf00f38711e0a93640405cc99fee"}
|
|
@@ -58,6 +65,13 @@ JAVASCRIPT
|
|
|
58
65
|
json
|
|
59
66
|
end
|
|
60
67
|
|
|
68
|
+
def json_campaign_send
|
|
69
|
+
json = <<JAVASCRIPT
|
|
70
|
+
{"statusCode":202,"statusMessage":"","statusTime":"2011-10-10T21:32:14.195Z","campaignKey":"51efcf00f38711e0a93640405cc99fee"}
|
|
71
|
+
JAVASCRIPT
|
|
72
|
+
json
|
|
73
|
+
end
|
|
74
|
+
|
|
61
75
|
def json_unsubscribes
|
|
62
76
|
json = <<JAVASCRIPT
|
|
63
77
|
{"statusCode":200,"statusMessage":"","statusTime":"2011-10-10T21:32:14.195Z","results":[{"toEmail":"joe@example.com","time":"2011-10-10T21:32:14.195Z"}]}
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: messagebus_ruby_api
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0.
|
|
4
|
+
version: 1.0.10
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2012-
|
|
12
|
+
date: 2012-03-23 00:00:00.000000000Z
|
|
13
13
|
dependencies: []
|
|
14
14
|
description: ! 'Allows you to use the Message Bus API '
|
|
15
15
|
email:
|
|
@@ -51,7 +51,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
51
51
|
version: '0'
|
|
52
52
|
requirements: []
|
|
53
53
|
rubyforge_project: messagebus_ruby_api
|
|
54
|
-
rubygems_version: 1.8.
|
|
54
|
+
rubygems_version: 1.8.19
|
|
55
55
|
signing_key:
|
|
56
56
|
specification_version: 3
|
|
57
57
|
summary: Send email through the Message Bus service
|