messagebus-sdk 4.1.1 → 5.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +5 -69
- data/lib/messagebus-sdk/actionmailer_client.rb +1 -1
- data/lib/messagebus-sdk/api_client.rb +6 -6
- data/lib/messagebus-sdk/messagebus_base.rb +27 -4
- data/lib/messagebus-sdk/messagebus_errors.rb +1 -1
- data/lib/messagebus-sdk/messagebus_version.rb +2 -2
- data/lib/messagebus-sdk/reports_client.rb +110 -0
- data/lib/messagebus-sdk/template_client.rb +6 -6
- data/lib/messagebus-sdk/webhook_client.rb +68 -0
- data/lib/messagebus-sdk.rb +1 -1
- data/spec/messagebus-sdk/actionmailer_client_spec.rb +1 -1
- data/spec/messagebus-sdk/api_client_spec.rb +4 -4
- data/spec/messagebus-sdk/base_spec.rb +3 -3
- data/spec/messagebus-sdk/reports_client_spec.rb +132 -0
- data/spec/messagebus-sdk/template_client_spec.rb +8 -8
- data/spec/messagebus-sdk/webhook_client_spec.rb +72 -0
- data/spec/spec_core_extensions.rb +1 -1
- data/spec/spec_helper.rb +157 -2
- metadata +8 -8
- data/lib/messagebus-sdk/feedback_client.rb +0 -104
- data/lib/messagebus-sdk/stats_client.rb +0 -50
- data/spec/messagebus-sdk/feedback_client_spec.rb +0 -65
- data/spec/messagebus-sdk/stats_client_spec.rb +0 -56
data/README.md
CHANGED
@@ -28,7 +28,7 @@ If you have questions not answered by the samples or the online documentation, p
|
|
28
28
|
require 'messagebus-sdk/api_client'
|
29
29
|
|
30
30
|
api_key="12345678934628542E2599F7ED712345"
|
31
|
-
api_host="https://api
|
31
|
+
api_host="https://api.messagebus.com"
|
32
32
|
|
33
33
|
client = MessagebusApiClient.new(api_key, api_host)
|
34
34
|
|
@@ -39,6 +39,7 @@ If you have questions not answered by the samples or the online documentation, p
|
|
39
39
|
:toName => 'Bobby Flay',
|
40
40
|
:fromEmail => 'alice@example.com',
|
41
41
|
:fromName => 'Alice Waters',
|
42
|
+
:returnPath => 'bounces@bounces.example.com',
|
42
43
|
:subject => 'Sample Message with HTML body.',
|
43
44
|
:customHeaders => {"x-messagebus-sdk"=>"ruby-sdk"},
|
44
45
|
:plaintextBody => 'This is the plain text body.',
|
@@ -48,6 +49,7 @@ If you have questions not answered by the samples or the online documentation, p
|
|
48
49
|
:toName => 'Jamie Lauren',
|
49
50
|
:fromEmail => 'alice@example.com',
|
50
51
|
:fromName => 'Alice Waters',
|
52
|
+
:returnPath => 'bounces@bounces.example.com',
|
51
53
|
:subject => 'Simple Example with no HTML body.',
|
52
54
|
:customHeaders => {"x-messagebus-sdk"=>"ruby-sdk"},
|
53
55
|
:plaintextBody => 'This is the plaintext example.',
|
@@ -76,7 +78,7 @@ If you have questions not answered by the samples or the online documentation, p
|
|
76
78
|
class MessagebusMailer < MessagebusActionMailerClient
|
77
79
|
def initialize(*args)
|
78
80
|
api_key = "12345678934628542E2599F7ED712345"
|
79
|
-
api_endpoint = "https://api
|
81
|
+
api_endpoint = "https://api.messagebus.com"
|
80
82
|
super(api_key, api_endpoint)
|
81
83
|
end
|
82
84
|
end
|
@@ -101,77 +103,11 @@ If you have questions not answered by the samples or the online documentation, p
|
|
101
103
|
message = MessageBusActionMailerTest.test_message(to_email, session_key)
|
102
104
|
message.deliver
|
103
105
|
|
104
|
-
####Checking email statistics
|
105
|
-
|
106
|
-
require 'messagebus-sdk/stats_client'
|
107
|
-
|
108
|
-
api_key = "12345678934628542E2599F7ED712345"
|
109
|
-
api_host = "https://api-v4.messagebus.com"
|
110
|
-
|
111
|
-
client = MessagebusStatsClient.new(api_key, api_host)
|
112
|
-
|
113
|
-
begin
|
114
|
-
response = client.stats
|
115
|
-
if response[:statusCode] == 200
|
116
|
-
stats = response[:stats]
|
117
|
-
puts "Stats"
|
118
|
-
puts "\tMessages Attempted: #{stats[:msgsAttemptedCount]}"
|
119
|
-
puts "\tComplaint Count: #{stats[:complaintCount]}"
|
120
|
-
puts "\tUnsubscribe Count: #{stats[:unsubscribeCount]}"
|
121
|
-
puts "\tOpen Count: #{stats[:openCount]}"
|
122
|
-
puts "\tUnique Open Count: #{stats[:uniqueOpenCount]}"
|
123
|
-
puts "\tClick Count: #{stats[:clickCount]}"
|
124
|
-
|
125
|
-
smtp = response[:smtp]
|
126
|
-
puts "SMTP"
|
127
|
-
puts "\tAccept Count: #{smtp[:acceptCount]}"
|
128
|
-
puts "\tBounce Count: #{smtp[:bounceCount]}"
|
129
|
-
puts "\tReject Count: #{smtp[:rejectCount]}"
|
130
|
-
puts "\tError Count: #{smtp[:errorCount]}"
|
131
|
-
|
132
|
-
filter = response[:filter]
|
133
|
-
puts "Filter"
|
134
|
-
puts "\tBad Mailbox Count: #{filter[:rcptBadMailboxCount]}"
|
135
|
-
puts "\tChannel Block Count: #{filter[:rcptChannelBlockCount]}"
|
136
|
-
|
137
|
-
else
|
138
|
-
puts "#{response[:statusMessage]}"
|
139
|
-
end
|
140
|
-
rescue Exception=>e
|
141
|
-
puts "Exception thrown. Error during stats retrieval: #{e.message}"
|
142
|
-
end
|
143
|
-
|
144
|
-
#### Checking email feedback data
|
145
|
-
|
146
|
-
require 'messagebus-sdk/feedback_client'
|
147
|
-
|
148
|
-
api_key = "12345678934628542E2599F7ED712345"
|
149
|
-
api_host = "https://api-v4.messagebus.com"
|
150
|
-
|
151
|
-
client = MessagebusFeedbackClient.new(api_key, api_host)
|
152
|
-
|
153
|
-
begin
|
154
|
-
response = client.feedback
|
155
|
-
if response[:statusCode] == 200
|
156
|
-
puts "Bounces"
|
157
|
-
response[:bounces].each do |bounce|
|
158
|
-
puts "Email: #{bounce[:email]} Count: #{bounce[:count]} BounceCode: #{bounce[:bounceCode]} LastEventTime: #{bounce[:lastEventTime]}"
|
159
|
-
end
|
160
|
-
puts "Clicks"
|
161
|
-
response[:clicks].each do |click|
|
162
|
-
puts "Email: #{click[:email]} Count: #{click[:count]} LastEventTime: #{click[:lastEventTime]}"
|
163
|
-
end
|
164
|
-
else
|
165
|
-
puts "#{response[:statusMessage]}"
|
166
|
-
end
|
167
|
-
rescue Exception=>e
|
168
|
-
puts "Exception thrown. Error during feedback retrieval: #{e.message}"
|
169
|
-
end
|
170
106
|
|
171
107
|
#### License
|
172
108
|
|
173
109
|
|
174
|
-
Copyright (c)
|
110
|
+
Copyright (c) 2014 Message Bus
|
175
111
|
|
176
112
|
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance
|
177
113
|
with the License. You may obtain a copy of the License at
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright
|
1
|
+
# Copyright 2014 Message Bus
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
4
4
|
# not use this file except in compliance with the License. You may obtain
|
@@ -58,11 +58,11 @@ class MessagebusApiClient < MessagebusSDK::MessagebusBase
|
|
58
58
|
|
59
59
|
def define_rest_endpoints
|
60
60
|
{
|
61
|
-
:message_emails_send => "/
|
62
|
-
:channels => "/
|
63
|
-
:channel_config => "/
|
64
|
-
:channel_sessions => "/
|
65
|
-
:channel_session_rename => "/
|
61
|
+
:message_emails_send => "/v5/messages/send",
|
62
|
+
:channels => "/v5/channels",
|
63
|
+
:channel_config => "/v5/channel/%CHANNEL_KEY%/config",
|
64
|
+
:channel_sessions => "/v5/channel/%CHANNEL_KEY%/sessions",
|
65
|
+
:channel_session_rename => "/v5/channel/%CHANNEL_KEY%/session/%SESSION_KEY%/rename"
|
66
66
|
}
|
67
67
|
end
|
68
68
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright
|
1
|
+
# Copyright 2014 Message Bus
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
4
4
|
# not use this file except in compliance with the License. You may obtain
|
@@ -20,7 +20,7 @@ require 'messagebus_errors'
|
|
20
20
|
module MessagebusSDK
|
21
21
|
|
22
22
|
class MessagebusBase
|
23
|
-
DEFAULT_API_ENDPOINT = 'https://api
|
23
|
+
DEFAULT_API_ENDPOINT = 'https://api.messagebus.com'
|
24
24
|
DEFAULT = 'DEFAULT'
|
25
25
|
HEADER_SESSION_KEY = 'X-MESSAGEBUS-SESSIONKEY'
|
26
26
|
SCOPE_ALL = 'all'
|
@@ -39,6 +39,8 @@ module MessagebusSDK
|
|
39
39
|
|
40
40
|
@results = base_response_params
|
41
41
|
@rest_http_errors = define_rest_http_errors
|
42
|
+
@return_json = true
|
43
|
+
@file_handle = nil
|
42
44
|
end
|
43
45
|
|
44
46
|
def api_version
|
@@ -108,15 +110,27 @@ module MessagebusSDK
|
|
108
110
|
!address.match(/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i).nil?
|
109
111
|
end
|
110
112
|
|
111
|
-
def make_api_request(path, request_type=HTTP_GET, data='')
|
113
|
+
def make_api_request(path, request_type=HTTP_GET, data='', return_json = true, file_name='')
|
112
114
|
if (@last_init_time < Time.now.utc - 60)
|
113
115
|
init_http_connection(@api_endpoint)
|
114
116
|
end
|
115
117
|
|
118
|
+
@return_json = return_json
|
116
119
|
headers = common_http_headers
|
117
120
|
case request_type
|
118
121
|
when HTTP_GET
|
119
|
-
|
122
|
+
if !@return_json && file_name != ''
|
123
|
+
response_file = open(file_name, 'w')
|
124
|
+
@http.request_get(path, headers) do |response|
|
125
|
+
response.read_body do |segment|
|
126
|
+
response_file.write(segment)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
response_file.close
|
130
|
+
return true
|
131
|
+
else
|
132
|
+
response = @http.request_get(path, headers)
|
133
|
+
end
|
120
134
|
when HTTP_PUT
|
121
135
|
headers = common_http_headers.merge(rest_post_headers)
|
122
136
|
response = @http.request_put(path, data, headers)
|
@@ -130,6 +144,7 @@ module MessagebusSDK
|
|
130
144
|
end
|
131
145
|
|
132
146
|
def check_response(response, symbolize_names=true)
|
147
|
+
return response.body if !@return_json
|
133
148
|
case response
|
134
149
|
when Net::HTTPSuccess
|
135
150
|
begin
|
@@ -183,6 +198,14 @@ module MessagebusSDK
|
|
183
198
|
replace_channel_key(replace_token_with_key(path, "%SESSION_KEY%", session_key), channel_key)
|
184
199
|
end
|
185
200
|
|
201
|
+
def replace_webhook_key(path, webhook_key)
|
202
|
+
replace_token_with_key(path, "%WEBHOOK_KEY%", webhook_key)
|
203
|
+
end
|
204
|
+
|
205
|
+
def replace_report_key(path, report_key)
|
206
|
+
replace_token_with_key(path, "%REPORT_KEY%", report_key)
|
207
|
+
end
|
208
|
+
|
186
209
|
def feedback_query_args(start_date, end_date, use_send_time, scope)
|
187
210
|
query_string_parts = ["useSendTime=#{use_send_time}", "scope=#{scope}"]
|
188
211
|
date_range = "#{date_range(start_date, end_date)}"
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright
|
1
|
+
# Copyright 2014 Message Bus
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
4
4
|
# not use this file except in compliance with the License. You may obtain
|
@@ -13,7 +13,7 @@
|
|
13
13
|
# under the License.
|
14
14
|
|
15
15
|
module MessagebusSDK
|
16
|
-
VERSION = "
|
16
|
+
VERSION = "5.0.0"
|
17
17
|
|
18
18
|
class Info
|
19
19
|
@@ClientVersion = MessagebusSDK::VERSION
|
@@ -0,0 +1,110 @@
|
|
1
|
+
# Copyright 2014 Message Bus
|
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
|
+
require 'messagebus_base'
|
16
|
+
|
17
|
+
class MessagebusReportsClient < MessagebusSDK::MessagebusBase
|
18
|
+
FORMAT_JSON = "json"
|
19
|
+
FORMAT_CSV = "csv"
|
20
|
+
|
21
|
+
REPORT_TYPE_STATS = "stats"
|
22
|
+
REPORT_TYPE_FEEDBACK = "feedback"
|
23
|
+
REPORT_TYPE_BLOCKLIST = "blocklist"
|
24
|
+
|
25
|
+
SCOPE_BOUNCES = "bounces"
|
26
|
+
SCOPE_UNSUBSCRIBES = "unsubscribes"
|
27
|
+
SCOPE_COMPLAINTS = "complaints"
|
28
|
+
SCOPE_CLICKS = "clicks"
|
29
|
+
SCOPE_OPENS = "opens"
|
30
|
+
SCOPE_BLOCKS = "blocks"
|
31
|
+
|
32
|
+
STATUS_DONE = "done"
|
33
|
+
STATUS_RUNNING = "running"
|
34
|
+
STATUS_NODATA = "nodata"
|
35
|
+
STATUS_FAILED = "failed"
|
36
|
+
|
37
|
+
def initialize(api_key, api_endpoint = DEFAULT_API_ENDPOINT)
|
38
|
+
super(api_key, api_endpoint)
|
39
|
+
@rest_endpoints = define_rest_endpoints
|
40
|
+
end
|
41
|
+
|
42
|
+
def report_status(report_key)
|
43
|
+
path = replace_report_key("#{@rest_endpoints[:status]}", report_key)
|
44
|
+
make_api_request(path)
|
45
|
+
end
|
46
|
+
|
47
|
+
def report_data(report_key, file_name = '')
|
48
|
+
path = replace_report_key("#{@rest_endpoints[:report]}", report_key)
|
49
|
+
make_api_request(path, HTTP_GET, '', false, file_name)
|
50
|
+
end
|
51
|
+
|
52
|
+
def report(report_key, file_name = '', sleep_interval = 5)
|
53
|
+
report_data = ''
|
54
|
+
check_report_status = true
|
55
|
+
while check_report_status
|
56
|
+
response = report_status(report_key)
|
57
|
+
case response[:reportStatus]
|
58
|
+
when STATUS_DONE
|
59
|
+
report_data = report_data(report_key, file_name)
|
60
|
+
check_report_status = false
|
61
|
+
when STATUS_NODATA, STATUS_FAILED
|
62
|
+
report_data = ''
|
63
|
+
check_report_status = false
|
64
|
+
else
|
65
|
+
sleep(sleep_interval)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
return report_data
|
69
|
+
end
|
70
|
+
|
71
|
+
def create_report(report_type, start_date, end_date, scope = 'bounces', format = 'json', channel_key = '', session_key = '')
|
72
|
+
path = @rest_endpoints[:reports]
|
73
|
+
days = 1
|
74
|
+
end_date = set_date(end_date, 0)
|
75
|
+
start_date = set_date(start_date, days)
|
76
|
+
|
77
|
+
post_data = {:reportType => report_type,
|
78
|
+
:scope => scope,
|
79
|
+
:format => format,
|
80
|
+
:startDate => start_date,
|
81
|
+
:endDate => end_date,
|
82
|
+
:channelKey => channel_key,
|
83
|
+
:sessionKey => session_key
|
84
|
+
}
|
85
|
+
make_api_request(path, HTTP_POST, post_data.to_json)
|
86
|
+
end
|
87
|
+
|
88
|
+
def create_feedback_report(start_date, end_date, scope = 'bounces', format = 'json', channel_key = '', session_key = '')
|
89
|
+
create_report(REPORT_TYPE_FEEDBACK, start_date, end_date, scope, format, channel_key, session_key)
|
90
|
+
end
|
91
|
+
|
92
|
+
def create_stats_report(start_date, end_date, format = 'json', channel_key = '', session_key = '')
|
93
|
+
create_report(REPORT_TYPE_STATS, start_date, end_date, SCOPE_ALL, format, channel_key, session_key)
|
94
|
+
end
|
95
|
+
|
96
|
+
def create_blocklist_report(start_date, end_date, scope = 'blocks', format = 'json', channel_key = '', session_key = '')
|
97
|
+
create_report(REPORT_TYPE_BLOCKLIST, start_date, end_date, scope, format, channel_key, session_key)
|
98
|
+
end
|
99
|
+
|
100
|
+
private
|
101
|
+
|
102
|
+
def define_rest_endpoints
|
103
|
+
{
|
104
|
+
:reports => "/v5/reports",
|
105
|
+
:report => "/v5/report/%REPORT_KEY%",
|
106
|
+
:status => "/v5/report/%REPORT_KEY%/status"
|
107
|
+
}
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright
|
1
|
+
# Copyright 2014 Message Bus
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
4
4
|
# not use this file except in compliance with the License. You may obtain
|
@@ -15,7 +15,7 @@
|
|
15
15
|
require 'messagebus_base'
|
16
16
|
|
17
17
|
class MessagebusTemplateClient < MessagebusSDK::MessagebusBase
|
18
|
-
DEFAULT_TEMPLATE_ENDPOINT = 'https://templates
|
18
|
+
DEFAULT_TEMPLATE_ENDPOINT = 'https://templates.messagebus.com'
|
19
19
|
|
20
20
|
def initialize(api_key, api_endpoint = DEFAULT_TEMPLATE_ENDPOINT)
|
21
21
|
super(api_key, api_endpoint)
|
@@ -55,10 +55,10 @@ class MessagebusTemplateClient < MessagebusSDK::MessagebusBase
|
|
55
55
|
private
|
56
56
|
def define_rest_endpoints
|
57
57
|
{
|
58
|
-
:template_version => "/
|
59
|
-
:template => "/
|
60
|
-
:templates => "/
|
61
|
-
:templates_send => "/
|
58
|
+
:template_version => "/v5/templates/version",
|
59
|
+
:template => "/v5/template/%TEMPLATE_KEY%",
|
60
|
+
:templates => "/v5/templates",
|
61
|
+
:templates_send => "/v5/templates/email/send"
|
62
62
|
}
|
63
63
|
end
|
64
64
|
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# Copyright 2014 Message Bus
|
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
|
+
require 'messagebus_base'
|
16
|
+
|
17
|
+
class MessagebusWebhookClient < MessagebusSDK::MessagebusBase
|
18
|
+
|
19
|
+
EVENT_TYPE_MESSAGE_ATTEMPT = 'message.attempt'
|
20
|
+
EVENT_TYPE_MESSAGE_ACCEPT = 'message.accept'
|
21
|
+
EVENT_TYPE_MESSAGE_BOUNCE = 'message.bounce'
|
22
|
+
EVENT_TYPE_MESSAGE_DEFERRAL = 'message.deferral'
|
23
|
+
EVENT_TYPE_MESSAGE_OPEN = 'message.open'
|
24
|
+
EVENT_TYPE_LINK_CLICK = 'link.click'
|
25
|
+
EVENT_TYPE_RECIPIENT_UNSUBSCRIBE = 'recipient.unsubscribe'
|
26
|
+
EVENT_TYPE_RECIPIENT_COMPLAINT = 'recipient.complaint'
|
27
|
+
EVENT_TYPE_RECIPIENT_BLOCK = 'recipient.block'
|
28
|
+
|
29
|
+
def initialize(api_key, api_endpoint = DEFAULT_API_ENDPOINT)
|
30
|
+
super(api_key, api_endpoint)
|
31
|
+
@rest_endpoints = define_rest_endpoints
|
32
|
+
end
|
33
|
+
|
34
|
+
def webhooks
|
35
|
+
path = "#{@rest_endpoints[:webhooks]}"
|
36
|
+
make_api_request(path, HTTP_GET)
|
37
|
+
end
|
38
|
+
|
39
|
+
def webhook(webhook_key)
|
40
|
+
path = replace_webhook_key("#{@rest_endpoints[:webhook]}", webhook_key)
|
41
|
+
make_api_request(path, HTTP_GET)
|
42
|
+
end
|
43
|
+
|
44
|
+
def create(params)
|
45
|
+
path = "#{@rest_endpoints[:webhooks]}"
|
46
|
+
make_api_request(path, HTTP_POST, params.to_json)
|
47
|
+
end
|
48
|
+
|
49
|
+
def update(webhook_key, params)
|
50
|
+
path = replace_webhook_key("#{@rest_endpoints[:webhook]}", webhook_key)
|
51
|
+
make_api_request(path, HTTP_PUT, params.to_json)
|
52
|
+
end
|
53
|
+
|
54
|
+
def delete(webhook_key)
|
55
|
+
path = replace_webhook_key("#{@rest_endpoints[:webhook]}", webhook_key)
|
56
|
+
make_api_request(path, HTTP_DELETE)
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
def define_rest_endpoints
|
62
|
+
{
|
63
|
+
:webhooks => "/v5/webhooks",
|
64
|
+
:webhook => "/v5/webhook/%WEBHOOK_KEY%"
|
65
|
+
}
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
data/lib/messagebus-sdk.rb
CHANGED
@@ -18,7 +18,7 @@ describe MessagebusActionMailerClient do
|
|
18
18
|
session_key = "DEFAULT"
|
19
19
|
message = MessageBusActionMailerTest.new_message(to_email, session_key)
|
20
20
|
|
21
|
-
FakeWeb.register_uri(:post, "#{API_URL}/
|
21
|
+
FakeWeb.register_uri(:post, "#{API_URL}/messages/send", :body => json_valid_send)
|
22
22
|
message.deliver
|
23
23
|
|
24
24
|
message_body = JSON.parse(FakeWeb.last_request.body)
|
@@ -32,7 +32,7 @@ describe MessagebusApiClient do
|
|
32
32
|
|
33
33
|
describe "#send_messages" do
|
34
34
|
it "should have user-agent and x-messagebus-key set in request headers" do
|
35
|
-
FakeWeb.register_uri(:post, "#{API_URL}/
|
35
|
+
FakeWeb.register_uri(:post, "#{API_URL}/messages/send", :body => json_valid_send)
|
36
36
|
client.send_messages(default_message_params)
|
37
37
|
|
38
38
|
FakeWeb.last_request.get_fields("X-MessageBus-Key").should_not be_nil
|
@@ -41,7 +41,7 @@ describe MessagebusApiClient do
|
|
41
41
|
end
|
42
42
|
|
43
43
|
it "sends messages" do
|
44
|
-
FakeWeb.register_uri(:post, "#{API_URL}/
|
44
|
+
FakeWeb.register_uri(:post, "#{API_URL}/messages/send", :body => json_valid_send)
|
45
45
|
results = client.send_messages(default_message_params)
|
46
46
|
results[:results].size.should == 1
|
47
47
|
end
|
@@ -55,7 +55,7 @@ describe MessagebusApiClient do
|
|
55
55
|
it "doesnt reset connection if under a minute old" do
|
56
56
|
current_init_time=@http_client.last_init_time
|
57
57
|
current_init_time.should be > Time.now.utc-5
|
58
|
-
FakeWeb.register_uri(:post, "#{API_URL}/
|
58
|
+
FakeWeb.register_uri(:post, "#{API_URL}/messages/send", :body => json_valid_send)
|
59
59
|
results = @http_client.send_messages(default_message_params)
|
60
60
|
results[:results].size.should == 1
|
61
61
|
@http_client.last_init_time.should == current_init_time
|
@@ -65,7 +65,7 @@ describe MessagebusApiClient do
|
|
65
65
|
@http_client.last_init_time=Time.now.utc-60
|
66
66
|
current_init_time=@http_client.last_init_time
|
67
67
|
current_init_time.should be < Time.now.utc-59
|
68
|
-
FakeWeb.register_uri(:post, "#{API_URL}/
|
68
|
+
FakeWeb.register_uri(:post, "#{API_URL}/messages/send", :body => json_valid_send)
|
69
69
|
results = @http_client.send_messages(default_message_params)
|
70
70
|
results[:results].size.should == 1
|
71
71
|
@http_client.last_init_time.should be > current_init_time
|
@@ -30,9 +30,9 @@ describe MessagebusSDK::MessagebusBase do
|
|
30
30
|
|
31
31
|
describe "messagebus base object set up correctly" do
|
32
32
|
it "has correct headers and accepts a custom endpoint" do
|
33
|
-
test_endpoint = 'https://testapi
|
33
|
+
test_endpoint = 'https://testapi.messagebus.com/v5'
|
34
34
|
client = MessagebusSDK::MessagebusBase.new(@api_key, test_endpoint)
|
35
|
-
client.instance_eval('@http').address.should == "testapi
|
35
|
+
client.instance_eval('@http').address.should == "testapi.messagebus.com"
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
@@ -140,7 +140,7 @@ describe MessagebusSDK::MessagebusBase do
|
|
140
140
|
|
141
141
|
describe "#version" do
|
142
142
|
it "retrieves the current version of the API" do
|
143
|
-
FakeWeb.register_uri(:get, "https://api
|
143
|
+
FakeWeb.register_uri(:get, "https://api.messagebus.com/api/version", :body => json_api_version_results)
|
144
144
|
client = MessagebusSDK::MessagebusBase.new(@api_key)
|
145
145
|
version = client.api_version
|
146
146
|
|
@@ -0,0 +1,132 @@
|
|
1
|
+
|
2
|
+
dir = File.dirname(__FILE__)
|
3
|
+
require "#{dir}/../spec_helper"
|
4
|
+
require "#{dir}/../../lib/messagebus-sdk/reports_client"
|
5
|
+
|
6
|
+
describe MessagebusReportsClient do
|
7
|
+
attr_reader :client, :api_key
|
8
|
+
|
9
|
+
before do
|
10
|
+
FakeWeb.allow_net_connect = false
|
11
|
+
@api_key = "7215ee9c7d9dc229d2921a40e899ec5f"
|
12
|
+
@client = MessagebusReportsClient.new(@api_key)
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "reports" do
|
16
|
+
it "#report_status" do
|
17
|
+
report_key = '125a58512d8446279e3530c8d803f5e2'
|
18
|
+
expected_request="#{API_URL}/report/#{report_key}/status"
|
19
|
+
FakeWeb.register_uri(:get, expected_request, :body => json_report_status_request_response_done200)
|
20
|
+
|
21
|
+
response = client.report_status(report_key)
|
22
|
+
response.should == json_parse(json_report_status_request_response_done200)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "#report_data" do
|
26
|
+
report_key = '125a58512d8446279e3530c8d803f5e2'
|
27
|
+
expected_request="#{API_URL}/report/#{report_key}/status"
|
28
|
+
FakeWeb.register_uri(:get, expected_request, :body => json_report_status_request_response_done200)
|
29
|
+
|
30
|
+
response = client.report_status(report_key)
|
31
|
+
response.should == json_parse(json_report_status_request_response_done200)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "#report" do
|
35
|
+
report_key = '125a58512d8446279e3530c8d803f5e2'
|
36
|
+
expected_request="#{API_URL}/report/#{report_key}/status"
|
37
|
+
FakeWeb.register_uri(:get, expected_request, :body => json_report_status_request_response_done200)
|
38
|
+
|
39
|
+
expected_request="#{API_URL}/report/#{report_key}"
|
40
|
+
FakeWeb.register_uri(:get, expected_request, :body => json_report_request_data_bounce)
|
41
|
+
|
42
|
+
response = client.report(report_key)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "#create_report" do
|
46
|
+
#def create_report(report_type, start_date, end_date, scope = 'bounces', format = 'json', channel_key = '', session_key = '')
|
47
|
+
report_type = MessagebusReportsClient::REPORT_TYPE_STATS
|
48
|
+
start_date_str="2014-01-01"
|
49
|
+
end_date_str="2014-01-02"
|
50
|
+
scope = MessagebusReportsClient::SCOPE_BOUNCES
|
51
|
+
format = MessagebusReportsClient::FORMAT_CSV
|
52
|
+
|
53
|
+
post_data = {:reportType => report_type,
|
54
|
+
:scope => scope,
|
55
|
+
:format => format,
|
56
|
+
:startDate => start_date_str,
|
57
|
+
:endDate => end_date_str,
|
58
|
+
:channelKey => '',
|
59
|
+
:sessionKey => ''
|
60
|
+
}
|
61
|
+
|
62
|
+
expected_request="#{API_URL}/reports"
|
63
|
+
FakeWeb.register_uri(:post, expected_request, :body => json_report_request_response201)
|
64
|
+
|
65
|
+
response = client.create_report(report_type, start_date_str, end_date_str, scope, format)
|
66
|
+
FakeWeb.last_request.body.should == post_data.to_json
|
67
|
+
end
|
68
|
+
|
69
|
+
it "#create_feedback_report" do
|
70
|
+
start_date_str="2014-01-01"
|
71
|
+
end_date_str="2014-01-02"
|
72
|
+
scope = MessagebusReportsClient::SCOPE_BOUNCES
|
73
|
+
format = MessagebusReportsClient::FORMAT_CSV
|
74
|
+
|
75
|
+
post_data = {:reportType => MessagebusReportsClient::REPORT_TYPE_FEEDBACK,
|
76
|
+
:scope => scope,
|
77
|
+
:format => format,
|
78
|
+
:startDate => start_date_str,
|
79
|
+
:endDate => end_date_str,
|
80
|
+
:channelKey => '',
|
81
|
+
:sessionKey => ''
|
82
|
+
}
|
83
|
+
|
84
|
+
expected_request="#{API_URL}/reports"
|
85
|
+
FakeWeb.register_uri(:post, expected_request, :body => json_report_request_response201)
|
86
|
+
response = client.create_feedback_report(start_date_str, end_date_str, scope, format)
|
87
|
+
FakeWeb.last_request.body.should == post_data.to_json
|
88
|
+
end
|
89
|
+
|
90
|
+
it "#create_stats_report" do
|
91
|
+
start_date_str="2014-01-01"
|
92
|
+
end_date_str="2014-01-02"
|
93
|
+
format = MessagebusReportsClient::FORMAT_CSV
|
94
|
+
|
95
|
+
post_data = {:reportType => MessagebusReportsClient::REPORT_TYPE_STATS,
|
96
|
+
:scope => MessagebusReportsClient::SCOPE_ALL,
|
97
|
+
:format => format,
|
98
|
+
:startDate => start_date_str,
|
99
|
+
:endDate => end_date_str,
|
100
|
+
:channelKey => '',
|
101
|
+
:sessionKey => ''
|
102
|
+
}
|
103
|
+
|
104
|
+
expected_request="#{API_URL}/reports"
|
105
|
+
FakeWeb.register_uri(:post, expected_request, :body => json_report_request_response201)
|
106
|
+
response = client.create_stats_report(start_date_str, end_date_str, format)
|
107
|
+
FakeWeb.last_request.body.should == post_data.to_json
|
108
|
+
|
109
|
+
end
|
110
|
+
|
111
|
+
it "#create_blocklist_report" do
|
112
|
+
start_date_str="2014-01-01"
|
113
|
+
end_date_str="2014-01-02"
|
114
|
+
scope = MessagebusReportsClient::SCOPE_BLOCKS
|
115
|
+
format = MessagebusReportsClient::FORMAT_CSV
|
116
|
+
|
117
|
+
post_data = {:reportType => MessagebusReportsClient::REPORT_TYPE_BLOCKLIST,
|
118
|
+
:scope => scope,
|
119
|
+
:format => format,
|
120
|
+
:startDate => start_date_str,
|
121
|
+
:endDate => end_date_str,
|
122
|
+
:channelKey => '',
|
123
|
+
:sessionKey => ''
|
124
|
+
}
|
125
|
+
|
126
|
+
expected_request="#{API_URL}/reports"
|
127
|
+
FakeWeb.register_uri(:post, expected_request, :body => json_report_request_response201)
|
128
|
+
response = client.create_blocklist_report(start_date_str, end_date_str, scope, format)
|
129
|
+
FakeWeb.last_request.body.should == post_data.to_json
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
@@ -9,7 +9,7 @@ describe MessagebusTemplateClient do
|
|
9
9
|
before do
|
10
10
|
FakeWeb.allow_net_connect = false
|
11
11
|
@api_key = "7215ee9c7d9dc229d2921a40e899ec5f"
|
12
|
-
@api_endpoint = "https://templates
|
12
|
+
@api_endpoint = "https://templates.messagebus.com"
|
13
13
|
@client = MessagebusTemplateClient.new(@api_key)
|
14
14
|
|
15
15
|
@test_template = {
|
@@ -29,7 +29,7 @@ describe MessagebusTemplateClient do
|
|
29
29
|
|
30
30
|
describe "templates" do
|
31
31
|
it "#template_version" do
|
32
|
-
FakeWeb.register_uri(:get, "#{@api_endpoint}/
|
32
|
+
FakeWeb.register_uri(:get, "#{@api_endpoint}/v5/templates/version", :body => json_template_version_results)
|
33
33
|
result = @client.template_version
|
34
34
|
|
35
35
|
result[:statusCode].should == 200
|
@@ -38,7 +38,7 @@ describe MessagebusTemplateClient do
|
|
38
38
|
end
|
39
39
|
|
40
40
|
it "#create_template" do
|
41
|
-
FakeWeb.register_uri(:post, "#{@api_endpoint}/
|
41
|
+
FakeWeb.register_uri(:post, "#{@api_endpoint}/v5/templates", :body => json_template_create)
|
42
42
|
|
43
43
|
|
44
44
|
result = @client.create_template(@test_template)
|
@@ -52,7 +52,7 @@ describe MessagebusTemplateClient do
|
|
52
52
|
it "#get_template" do
|
53
53
|
template_key = "33ffafac-b15e-4146-b046-14ed897c522b"
|
54
54
|
|
55
|
-
FakeWeb.register_uri(:get, "#{@api_endpoint}/
|
55
|
+
FakeWeb.register_uri(:get, "#{@api_endpoint}/v5/template/#{template_key}", :body => json_template_get)
|
56
56
|
|
57
57
|
result = @client.get_template(template_key)
|
58
58
|
|
@@ -66,7 +66,7 @@ describe MessagebusTemplateClient do
|
|
66
66
|
|
67
67
|
it "#templates" do
|
68
68
|
# list templates available
|
69
|
-
FakeWeb.register_uri(:get, "#{@api_endpoint}/
|
69
|
+
FakeWeb.register_uri(:get, "#{@api_endpoint}/v5/templates", :body => json_templates_get)
|
70
70
|
|
71
71
|
result = @client.templates
|
72
72
|
|
@@ -93,7 +93,7 @@ describe MessagebusTemplateClient do
|
|
93
93
|
end
|
94
94
|
|
95
95
|
it "#send_messages with batch size 25" do
|
96
|
-
FakeWeb.register_uri(:post, "#{@api_endpoint}/
|
96
|
+
FakeWeb.register_uri(:post, "#{@api_endpoint}/v5/templates/email/send", :body => json_templates_email_send)
|
97
97
|
|
98
98
|
template_messages = []
|
99
99
|
(1..25).each do |i|
|
@@ -105,7 +105,7 @@ describe MessagebusTemplateClient do
|
|
105
105
|
end
|
106
106
|
|
107
107
|
it "#send_messages with batch size 0" do
|
108
|
-
FakeWeb.register_uri(:post, "#{@api_endpoint}/
|
108
|
+
FakeWeb.register_uri(:post, "#{@api_endpoint}/v5/templates/email/send", :body => json_templates_email_send_empty)
|
109
109
|
|
110
110
|
template_messages = []
|
111
111
|
result = @client.send_messages(@template_key, template_messages)
|
@@ -113,7 +113,7 @@ describe MessagebusTemplateClient do
|
|
113
113
|
end
|
114
114
|
|
115
115
|
it "#send_messages with batch size 26" do
|
116
|
-
FakeWeb.register_uri(:post, "#{@api_endpoint}/
|
116
|
+
FakeWeb.register_uri(:post, "#{@api_endpoint}/v5/templates/email/send", :body => json_templates_email_send)
|
117
117
|
|
118
118
|
template_messages = []
|
119
119
|
(1..26).each do |i|
|
@@ -0,0 +1,72 @@
|
|
1
|
+
|
2
|
+
dir = File.dirname(__FILE__)
|
3
|
+
require "#{dir}/../spec_helper"
|
4
|
+
require "#{dir}/../../lib/messagebus-sdk/webhook_client"
|
5
|
+
|
6
|
+
describe MessagebusWebhookClient do
|
7
|
+
attr_reader :client, :api_key
|
8
|
+
|
9
|
+
before do
|
10
|
+
FakeWeb.allow_net_connect = false
|
11
|
+
@api_key = "7215ee9c7d9dc229d2921a40e899ec5f"
|
12
|
+
@client = MessagebusWebhookClient.new(@api_key)
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "webhooks" do
|
16
|
+
it "#webhooks" do
|
17
|
+
expected_request="#{API_URL}/webhooks"
|
18
|
+
FakeWeb.register_uri(:get, expected_request, :body => json_webhooks)
|
19
|
+
|
20
|
+
response = client.webhooks
|
21
|
+
response.should == json_parse(json_webhooks)
|
22
|
+
|
23
|
+
response[:webhooks].length.should == 2
|
24
|
+
end
|
25
|
+
|
26
|
+
it "#webhook" do
|
27
|
+
webhook_key = "ab487e9d750a3c50876d12e8f381a79f"
|
28
|
+
|
29
|
+
expected_request="#{API_URL}/webhook/#{webhook_key}"
|
30
|
+
FakeWeb.register_uri(:get, expected_request, :body => json_webhook)
|
31
|
+
|
32
|
+
response = client.webhook(webhook_key)
|
33
|
+
response.should == json_parse(json_webhook)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "#create" do
|
37
|
+
params = {:enabled => false,
|
38
|
+
:uri => 'http://domain.com/events/messagebus/message.accept',
|
39
|
+
:eventType => MessagebusWebhookClient::EVENT_TYPE_MESSAGE_ACCEPT
|
40
|
+
}
|
41
|
+
|
42
|
+
expected_request="#{API_URL}/webhooks"
|
43
|
+
FakeWeb.register_uri(:post, expected_request, :body => json_webhook_create)
|
44
|
+
|
45
|
+
response = client.create(params)
|
46
|
+
response.should == json_parse(json_webhook_create)
|
47
|
+
end
|
48
|
+
|
49
|
+
it "#update" do
|
50
|
+
webhook_key = "ab487e9d750a3c50876d12e8f381a79f"
|
51
|
+
params = {:uri => 'http://domain.com/events/messagebus/message.accepted'}
|
52
|
+
|
53
|
+
expected_request="#{API_URL}/webhook/#{webhook_key}"
|
54
|
+
FakeWeb.register_uri(:put, expected_request, :body => json_webhook_update)
|
55
|
+
|
56
|
+
response = client.update(webhook_key, params)
|
57
|
+
response.should == json_parse(json_webhook_update)
|
58
|
+
end
|
59
|
+
|
60
|
+
it "#delete_webhook" do
|
61
|
+
webhook_key = "ab487e9d750a3c50876d12e8f381a79f"
|
62
|
+
|
63
|
+
expected_request="#{API_URL}/webhook/#{webhook_key}"
|
64
|
+
FakeWeb.register_uri(:delete, expected_request, :body => json_webhook_delete)
|
65
|
+
|
66
|
+
response = client.delete(webhook_key)
|
67
|
+
response.should == json_parse(json_webhook_delete)
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright
|
1
|
+
# Copyright 2014 Message Bus
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
4
4
|
# not use this file except in compliance with the License. You may obtain
|
@@ -26,7 +26,7 @@ require 'api_client'
|
|
26
26
|
require 'actionmailer_client'
|
27
27
|
require 'messagebus_errors'
|
28
28
|
|
29
|
-
API_URL = 'https://api
|
29
|
+
API_URL = 'https://api.messagebus.com/v5'
|
30
30
|
|
31
31
|
def json_parse(data)
|
32
32
|
JSON.parse(data, :symbolize_names => true)
|
@@ -229,6 +229,161 @@ JAVASCRIPT
|
|
229
229
|
json
|
230
230
|
end
|
231
231
|
|
232
|
+
def json_webhooks
|
233
|
+
json = <<JAVASCRIPT
|
234
|
+
{
|
235
|
+
"statusCode":200,
|
236
|
+
"statusMessage":"OK",
|
237
|
+
"statusTime":"2014-01-22T23:12:45.768Z",
|
238
|
+
"webhooks":[
|
239
|
+
{"enabled":true,
|
240
|
+
"eventType":"recipient.block",
|
241
|
+
"uri":"http://webhook.messagebus.com/events/block",
|
242
|
+
"webhookKey":"902e4a3d-24a0-470f-bbde-58f81fc04b79",
|
243
|
+
"lastUpdated":"2014-01-22T23:31:42Z",
|
244
|
+
"dateCreated":"2014-01-22T23:31:42Z",
|
245
|
+
"batching":{
|
246
|
+
"batchingEnabled":true,
|
247
|
+
"batchTimeSeconds":30,
|
248
|
+
"maxBatchSize":500}
|
249
|
+
},
|
250
|
+
{"enabled":true,
|
251
|
+
"eventType":"message.attempt",
|
252
|
+
"uri":"http://webhook.messagebus.com/events/attempt",
|
253
|
+
"webhookKey":"9b4309e1-0551-4c7a-ab0b-4b69f977201f",
|
254
|
+
"lastUpdated":"2014-01-22T23:31:35Z",
|
255
|
+
"dateCreated":"2014-01-22T23:31:35Z",
|
256
|
+
"batching":{
|
257
|
+
"batchingEnabled":true,
|
258
|
+
"batchTimeSeconds":30,
|
259
|
+
"maxBatchSize":500
|
260
|
+
},
|
261
|
+
"channelKey":"DDCEFC35298644A998606CAB10F38501"
|
262
|
+
}
|
263
|
+
]
|
264
|
+
}
|
265
|
+
JAVASCRIPT
|
266
|
+
json
|
267
|
+
end
|
268
|
+
|
269
|
+
def json_webhook
|
270
|
+
json = <<JAVASCRIPT
|
271
|
+
{
|
272
|
+
"statusCode":200,
|
273
|
+
"statusMessage":"OK",
|
274
|
+
"statusTime":"2014-01-22T23:12:45.768Z",
|
275
|
+
"webhook":
|
276
|
+
{"enabled":true,
|
277
|
+
"eventType":"recipient.complaint",
|
278
|
+
"uri":"http://webhook.messagebus.com/messagebus/v5/recipient-complaint",
|
279
|
+
"webhookKey":"43980222-6bef-46aa-8644-d6b7e0b8c98a",
|
280
|
+
"lastUpdated":"2014-01-22T22:29:59Z",
|
281
|
+
"dateCreated":"2014-01-22T21:32:17Z",
|
282
|
+
"batching":
|
283
|
+
{"batchingEnabled":true,
|
284
|
+
"batchTimeSeconds":30,
|
285
|
+
"maxBatchSize":500
|
286
|
+
},
|
287
|
+
"channelKey":"DDCEFC35298644A998606CAB10F38501"
|
288
|
+
}
|
289
|
+
}
|
290
|
+
JAVASCRIPT
|
291
|
+
json
|
292
|
+
end
|
293
|
+
|
294
|
+
def json_webhook_no_channel
|
295
|
+
json = <<JAVASCRIPT
|
296
|
+
{
|
297
|
+
"statusCode":200,
|
298
|
+
"statusMessage":"OK",
|
299
|
+
"statusTime":"2014-01-22T23:12:45.768Z",
|
300
|
+
"webhook":
|
301
|
+
{"enabled":true,
|
302
|
+
"eventType":"recipient.complaint",
|
303
|
+
"uri":"http://webhook.messagebus.com/messagebus/v5/recipient-complaint",
|
304
|
+
"webhookKey":"43980222-6bef-46aa-8644-d6b7e0b8c98a",
|
305
|
+
"lastUpdated":"2014-01-22T22:29:59Z",
|
306
|
+
"dateCreated":"2014-01-22T21:32:17Z",
|
307
|
+
"batching":
|
308
|
+
{"batchingEnabled":true,
|
309
|
+
"batchTimeSeconds":30,
|
310
|
+
"maxBatchSize":500
|
311
|
+
}
|
312
|
+
}
|
313
|
+
}
|
314
|
+
JAVASCRIPT
|
315
|
+
json
|
316
|
+
end
|
317
|
+
|
318
|
+
def json_webhook_create
|
319
|
+
json = <<JAVASCRIPT
|
320
|
+
{
|
321
|
+
"statusCode":201,
|
322
|
+
"statusMessage":"Webhook created.",
|
323
|
+
"statusTime":"2014-01-24T23:35:45.083Z",
|
324
|
+
"webhookKey":"8d77789a13144923ba7b38b8ffff0f6c"
|
325
|
+
}
|
326
|
+
JAVASCRIPT
|
327
|
+
json
|
328
|
+
end
|
329
|
+
|
330
|
+
def json_webhook_update
|
331
|
+
json = <<JAVASCRIPT
|
332
|
+
{
|
333
|
+
"statusCode":200,
|
334
|
+
"statusMessage":"OK",
|
335
|
+
"statusTime":"2014-01-24T23:29:03.483Z"
|
336
|
+
}
|
337
|
+
JAVASCRIPT
|
338
|
+
json
|
339
|
+
end
|
340
|
+
|
341
|
+
def json_webhook_delete
|
342
|
+
json = <<JAVASCRIPT
|
343
|
+
{
|
344
|
+
"statusCode":200,
|
345
|
+
"statusMessage":"Webhook deleted.",
|
346
|
+
"statusTime":"2014-01-24T23:31:05.546Z"
|
347
|
+
}
|
348
|
+
JAVASCRIPT
|
349
|
+
json
|
350
|
+
end
|
351
|
+
|
352
|
+
|
353
|
+
def json_report_request_response201
|
354
|
+
json = <<JAVASCRIPT
|
355
|
+
{"statusCode":201,"statusMessage":"Report request received.","statusTime":"1971-01-01T00:00:00.000Z","reportKey":"e98d2f001da5678b39482efbdf5770dc","reportStatus":"created","reportQuota":50,"reportQuotaRemaining":49}
|
356
|
+
JAVASCRIPT
|
357
|
+
json
|
358
|
+
end
|
359
|
+
|
360
|
+
def json_report_status_request_response_done200
|
361
|
+
json = <<JAVASCRIPT
|
362
|
+
{"statusCode":200,"statusMessage":"Report has completed.","statusTime":"1971-01-01T00:00:00.000Z","reportStatus":"done"}
|
363
|
+
JAVASCRIPT
|
364
|
+
json
|
365
|
+
end
|
366
|
+
|
367
|
+
def json_report_status_request_response_running200
|
368
|
+
json = <<JAVASCRIPT
|
369
|
+
{"statusCode":200,"statusMessage":"Report is still running.","statusTime":"1971-01-01T00:00:00.000Z","reportStatus":"running"}
|
370
|
+
JAVASCRIPT
|
371
|
+
json
|
372
|
+
end
|
373
|
+
|
374
|
+
def json_report_status_request_response_no_data200
|
375
|
+
json = <<JAVASCRIPT
|
376
|
+
{"statusCode":200,"statusMessage":"Report contains no data.","statusTime":"1971-01-01T00:00:00.000Z","reportStatus":"nodata"}
|
377
|
+
JAVASCRIPT
|
378
|
+
json
|
379
|
+
end
|
380
|
+
|
381
|
+
def json_report_request_data_bounce
|
382
|
+
json = <<JAVASCRIPT
|
383
|
+
{"type":"bounce","channelKey":"0000000000ABCDEF0123456789ABCDEF","sessionKey":"1111111111ABCDEF0123456789ABCDEF","email":"bob@hotmail.com","bounceCode":1000,"eventTime":"1971-01-01T23:45:00.000Z","sendTime":"1971-01-01T00:00:00.000Z"}
|
384
|
+
JAVASCRIPT
|
385
|
+
json
|
386
|
+
end
|
232
387
|
|
233
388
|
class MessagebusMailer < MessagebusActionMailerClient
|
234
389
|
def initialize(*args)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: messagebus-sdk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 5.0.0
|
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:
|
12
|
+
date: 2014-02-17 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: SDK for Message Bus service
|
15
15
|
email:
|
@@ -20,20 +20,20 @@ extra_rdoc_files: []
|
|
20
20
|
files:
|
21
21
|
- lib/messagebus-sdk/actionmailer_client.rb
|
22
22
|
- lib/messagebus-sdk/api_client.rb
|
23
|
-
- lib/messagebus-sdk/feedback_client.rb
|
24
23
|
- lib/messagebus-sdk/messagebus_base.rb
|
25
24
|
- lib/messagebus-sdk/messagebus_errors.rb
|
26
25
|
- lib/messagebus-sdk/messagebus_version.rb
|
27
|
-
- lib/messagebus-sdk/
|
26
|
+
- lib/messagebus-sdk/reports_client.rb
|
28
27
|
- lib/messagebus-sdk/template_client.rb
|
28
|
+
- lib/messagebus-sdk/webhook_client.rb
|
29
29
|
- lib/messagebus-sdk.rb
|
30
30
|
- spec/messagebus-sdk/actionmailer_client_spec.rb
|
31
31
|
- spec/messagebus-sdk/api_client_spec.rb
|
32
32
|
- spec/messagebus-sdk/base_spec.rb
|
33
33
|
- spec/messagebus-sdk/cacert.pem
|
34
|
-
- spec/messagebus-sdk/
|
35
|
-
- spec/messagebus-sdk/stats_client_spec.rb
|
34
|
+
- spec/messagebus-sdk/reports_client_spec.rb
|
36
35
|
- spec/messagebus-sdk/template_client_spec.rb
|
36
|
+
- spec/messagebus-sdk/webhook_client_spec.rb
|
37
37
|
- spec/spec_core_extensions.rb
|
38
38
|
- spec/spec_helper.rb
|
39
39
|
- README.md
|
@@ -71,8 +71,8 @@ test_files:
|
|
71
71
|
- spec/messagebus-sdk/api_client_spec.rb
|
72
72
|
- spec/messagebus-sdk/base_spec.rb
|
73
73
|
- spec/messagebus-sdk/cacert.pem
|
74
|
-
- spec/messagebus-sdk/
|
75
|
-
- spec/messagebus-sdk/stats_client_spec.rb
|
74
|
+
- spec/messagebus-sdk/reports_client_spec.rb
|
76
75
|
- spec/messagebus-sdk/template_client_spec.rb
|
76
|
+
- spec/messagebus-sdk/webhook_client_spec.rb
|
77
77
|
- spec/spec_core_extensions.rb
|
78
78
|
- spec/spec_helper.rb
|
@@ -1,104 +0,0 @@
|
|
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
|
-
require 'messagebus_base'
|
16
|
-
|
17
|
-
class MessagebusFeedbackClient < MessagebusSDK::MessagebusBase
|
18
|
-
|
19
|
-
def initialize(api_key, api_endpoint = DEFAULT_API_ENDPOINT)
|
20
|
-
super(api_key, api_endpoint)
|
21
|
-
@rest_endpoints = define_rest_endpoints
|
22
|
-
end
|
23
|
-
|
24
|
-
def feedback(start_date = '', end_date = '', scope = SCOPE_ALL, use_send_time = TRUE_VALUE)
|
25
|
-
path = "#{@rest_endpoints[:feedback]}#{feedback_query_args(start_date, end_date, use_send_time, scope)}"
|
26
|
-
make_api_request(path)
|
27
|
-
end
|
28
|
-
|
29
|
-
def feedback_by_channel(channel_key, start_date = '', end_date = '', scope = SCOPE_ALL, use_send_time = TRUE_VALUE)
|
30
|
-
path = "#{replace_channel_key(@rest_endpoints[:feedback_channel], channel_key)}#{feedback_query_args(start_date, end_date, use_send_time, scope)}"
|
31
|
-
make_api_request(path)
|
32
|
-
end
|
33
|
-
|
34
|
-
def feedback_by_session(channel_key, session_key, start_date = '', end_date = '', scope = SCOPE_ALL, use_send_time = TRUE_VALUE)
|
35
|
-
path = "#{replace_channel_and_session_key(@rest_endpoints[:feedback_session], channel_key, session_key)}#{feedback_query_args(start_date, end_date, use_send_time, scope)}"
|
36
|
-
make_api_request(path)
|
37
|
-
end
|
38
|
-
|
39
|
-
def unsubs(start_date = '', end_date = '')
|
40
|
-
path = "#{@rest_endpoints[:unsubs]}?#{date_range(start_date, end_date)}"
|
41
|
-
make_api_request(path)
|
42
|
-
end
|
43
|
-
|
44
|
-
def unsubs_by_channel(channel_key, start_date = '', end_date = '')
|
45
|
-
path = "#{replace_channel_key(@rest_endpoints[:unsubs_channel], channel_key)}?#{date_range(start_date, end_date)}"
|
46
|
-
make_api_request(path)
|
47
|
-
end
|
48
|
-
|
49
|
-
def unsubs_by_session(channel_key, session_key, start_date = '', end_date = '')
|
50
|
-
path = "#{replace_channel_and_session_key(@rest_endpoints[:unsubs_session], channel_key, session_key)}?#{date_range(start_date, end_date)}"
|
51
|
-
make_api_request(path)
|
52
|
-
end
|
53
|
-
|
54
|
-
def complaints(start_date = '', end_date = '')
|
55
|
-
path = "#{@rest_endpoints[:complaints]}?#{date_range(start_date, end_date)}"
|
56
|
-
make_api_request(path)
|
57
|
-
end
|
58
|
-
|
59
|
-
def complaints_by_channel(channel_key, start_date = '', end_date = '')
|
60
|
-
path = "#{replace_channel_key(@rest_endpoints[:complaints_channel], channel_key)}?#{date_range(start_date, end_date)}"
|
61
|
-
make_api_request(path)
|
62
|
-
end
|
63
|
-
|
64
|
-
def complaints_by_session(channel_key, session_key, start_date = '', end_date = '')
|
65
|
-
path = "#{replace_channel_and_session_key(@rest_endpoints[:complaints_session], channel_key, session_key)}?#{date_range(start_date, end_date)}"
|
66
|
-
make_api_request(path)
|
67
|
-
end
|
68
|
-
|
69
|
-
def bounces(start_date = '', end_date = '')
|
70
|
-
path = "#{@rest_endpoints[:bounces]}?#{date_range(start_date, end_date)}"
|
71
|
-
make_api_request(path)
|
72
|
-
end
|
73
|
-
|
74
|
-
def bounces_by_channel(channel_key, start_date = '', end_date = '')
|
75
|
-
path = "#{replace_channel_key(@rest_endpoints[:bounces_channel], channel_key)}?#{date_range(start_date, end_date)}"
|
76
|
-
make_api_request(path)
|
77
|
-
end
|
78
|
-
|
79
|
-
def bounces_by_session(channel_key, session_key, start_date = '', end_date = '')
|
80
|
-
path = "#{replace_channel_and_session_key(@rest_endpoints[:bounces_session], channel_key, session_key)}?#{date_range(start_date, end_date)}"
|
81
|
-
make_api_request(path)
|
82
|
-
end
|
83
|
-
|
84
|
-
private
|
85
|
-
|
86
|
-
def define_rest_endpoints
|
87
|
-
{
|
88
|
-
:feedback => "/api/v4/feedback",
|
89
|
-
:feedback_channel => "/api/v4/feedback/channel/%CHANNEL_KEY%",
|
90
|
-
:feedback_session => "/api/v4/feedback/channel/%CHANNEL_KEY%/session/%SESSION_KEY%",
|
91
|
-
:unsubs => "/api/v4/unsubs",
|
92
|
-
:unsubs_channel => "/api/v4/unsubs/channel/%CHANNEL_KEY%",
|
93
|
-
:unsubs_session => "/api/v4/unsubs/channel/%CHANNEL_KEY%/session/%SESSION_KEY%",
|
94
|
-
:complaints => "/api/v4/complaints",
|
95
|
-
:complaints_channel => "/api/v4/complaints/channel/%CHANNEL_KEY%",
|
96
|
-
:complaints_session => "/api/v4/complaints/channel/%CHANNEL_KEY%/session/%SESSION_KEY%",
|
97
|
-
:bounces => "/api/v4/bounces",
|
98
|
-
:bounces_channel => "/api/v4/bounces/channel/%CHANNEL_KEY%",
|
99
|
-
:bounces_session => "/api/v4/bounces/channel/%CHANNEL_KEY%/session/%SESSION_KEY%"
|
100
|
-
}
|
101
|
-
end
|
102
|
-
|
103
|
-
end
|
104
|
-
|
@@ -1,50 +0,0 @@
|
|
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
|
-
require 'messagebus_base'
|
16
|
-
|
17
|
-
class MessagebusStatsClient < MessagebusSDK::MessagebusBase
|
18
|
-
|
19
|
-
def initialize(api_key, api_endpoint = DEFAULT_API_ENDPOINT)
|
20
|
-
super(api_key, api_endpoint)
|
21
|
-
@rest_endpoints = define_rest_endpoints
|
22
|
-
end
|
23
|
-
|
24
|
-
def stats(start_date = '', end_date = '')
|
25
|
-
path = "#{@rest_endpoints[:stats]}?#{date_range(start_date, end_date)}"
|
26
|
-
make_api_request(path)
|
27
|
-
end
|
28
|
-
|
29
|
-
def stats_by_channel(channel_key, start_date = '', end_date = '')
|
30
|
-
path = "#{replace_channel_key(@rest_endpoints[:stats_channel], channel_key)}?#{date_range(start_date, end_date)}"
|
31
|
-
make_api_request(path)
|
32
|
-
end
|
33
|
-
|
34
|
-
def stats_by_session(channel_key, session_key, start_date = '', end_date = '')
|
35
|
-
path = "#{replace_channel_and_session_key(@rest_endpoints[:stats_session], channel_key, session_key)}?#{date_range(start_date, end_date)}"
|
36
|
-
make_api_request(path)
|
37
|
-
end
|
38
|
-
|
39
|
-
private
|
40
|
-
|
41
|
-
def define_rest_endpoints
|
42
|
-
{
|
43
|
-
:stats => "/api/v4/stats/email",
|
44
|
-
:stats_channel => "/api/v4/stats/email/channel/%CHANNEL_KEY%",
|
45
|
-
:stats_session => "/api/v4/stats/email/channel/%CHANNEL_KEY%/session/%SESSION_KEY%",
|
46
|
-
}
|
47
|
-
end
|
48
|
-
|
49
|
-
end
|
50
|
-
|
@@ -1,65 +0,0 @@
|
|
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
|
@@ -1,56 +0,0 @@
|
|
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
|