twizo 0.1.1
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.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +126 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/examples/backup_codes.rb +31 -0
- data/examples/backup_codes_check.rb +29 -0
- data/examples/backup_codes_delete.rb +31 -0
- data/examples/backup_codes_update.rb +31 -0
- data/examples/backup_codes_verify.rb +34 -0
- data/examples/balance.rb +18 -0
- data/examples/examples_init.rb +43 -0
- data/examples/number_lookup.rb +32 -0
- data/examples/number_lookup_results.rb +28 -0
- data/examples/number_lookup_status.rb +29 -0
- data/examples/sms.rb +32 -0
- data/examples/sms_advanced.rb +33 -0
- data/examples/sms_concat.rb +32 -0
- data/examples/sms_multiple.rb +35 -0
- data/examples/sms_results.rb +28 -0
- data/examples/sms_status.rb +29 -0
- data/examples/sms_validation_errors.rb +28 -0
- data/examples/verification.rb +31 -0
- data/examples/verification_status.rb +29 -0
- data/examples/verification_verify_token.rb +39 -0
- data/examples/widget.rb +31 -0
- data/examples/widget_status.rb +34 -0
- data/lib/twizo.rb +190 -0
- data/lib/twizo/client.rb +45 -0
- data/lib/twizo/client/net_http_client.rb +48 -0
- data/lib/twizo/entity.rb +114 -0
- data/lib/twizo/modules/backup_codes.rb +100 -0
- data/lib/twizo/modules/balance.rb +40 -0
- data/lib/twizo/modules/number_lookup.rb +81 -0
- data/lib/twizo/modules/params/backup_codes_params.rb +19 -0
- data/lib/twizo/modules/params/number_lookup_params.rb +23 -0
- data/lib/twizo/modules/params/params.rb +37 -0
- data/lib/twizo/modules/params/sms_params.rb +34 -0
- data/lib/twizo/modules/params/verification_params.rb +30 -0
- data/lib/twizo/modules/params/widget_params.rb +29 -0
- data/lib/twizo/modules/sms.rb +130 -0
- data/lib/twizo/modules/verification.rb +73 -0
- data/lib/twizo/modules/widget.rb +59 -0
- data/lib/twizo/result.rb +66 -0
- data/lib/twizo/status_codes.rb +32 -0
- data/lib/twizo/twizo_error.rb +26 -0
- data/lib/twizo/version.rb +3 -0
- data/test/test_all.rb +19 -0
- data/test/test_backup_codes.rb +120 -0
- data/test/test_balance.rb +51 -0
- data/test/test_init.rb +41 -0
- data/test/test_number_lookup.rb +215 -0
- data/test/test_sms.rb +270 -0
- data/test/test_verification.rb +106 -0
- data/test/test_widget.rb +107 -0
- data/twizo.gemspec +34 -0
- metadata +154 -0
data/test/test_sms.rb
ADDED
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
require_relative 'test_init'
|
|
2
|
+
|
|
3
|
+
=begin
|
|
4
|
+
|
|
5
|
+
This file is part of the Twizo php api
|
|
6
|
+
|
|
7
|
+
(c) Twizo <info@twizo.com>
|
|
8
|
+
|
|
9
|
+
For the full copyright and license information, please view the LICENSE
|
|
10
|
+
File that was distributed with this source code.
|
|
11
|
+
|
|
12
|
+
=end
|
|
13
|
+
|
|
14
|
+
class TestSms < TestInit
|
|
15
|
+
|
|
16
|
+
#
|
|
17
|
+
# Initialize Twizo
|
|
18
|
+
#
|
|
19
|
+
def setup
|
|
20
|
+
@twizo = Twizo::Twizo.new(API_KEY, API_HOST)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
#
|
|
24
|
+
# Test if an error is thrown when an invalid key is provided
|
|
25
|
+
#
|
|
26
|
+
def test_invalid_key
|
|
27
|
+
api_key = 'invalid_key'
|
|
28
|
+
|
|
29
|
+
assert_raise Twizo::TwizoError do
|
|
30
|
+
@twizo = Twizo::Twizo.new(api_key, API_HOST)
|
|
31
|
+
sms = @twizo.create_sms('test body', NUMBER1, 'test sender')
|
|
32
|
+
sms.send_simple
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
#
|
|
37
|
+
# Test creation of sms with multiple numbers
|
|
38
|
+
#
|
|
39
|
+
def test_create_sms
|
|
40
|
+
sms = @twizo.create_sms(nil, nil, nil)
|
|
41
|
+
|
|
42
|
+
test_recipients = [NUMBER1, NUMBER2]
|
|
43
|
+
test_body = 'test body'
|
|
44
|
+
test_sender = 'test sender'
|
|
45
|
+
test_sender_ton = 5
|
|
46
|
+
test_sender_npi = 0
|
|
47
|
+
test_pid = 0
|
|
48
|
+
test_scheduled_delivery = nil
|
|
49
|
+
test_tag = 'test tag'
|
|
50
|
+
test_validity = 259200
|
|
51
|
+
test_result_type = 0
|
|
52
|
+
test_callback_url = nil
|
|
53
|
+
|
|
54
|
+
sms.params.recipients = test_recipients
|
|
55
|
+
sms.params.body = test_body
|
|
56
|
+
sms.params.sender = test_sender
|
|
57
|
+
sms.params.sender_ton = test_sender_ton
|
|
58
|
+
sms.params.sender_npi = test_sender_npi
|
|
59
|
+
sms.params.pid = test_pid
|
|
60
|
+
sms.params.scheduled_delivery = test_scheduled_delivery
|
|
61
|
+
sms.params.tag = test_tag
|
|
62
|
+
sms.params.validity = test_validity
|
|
63
|
+
sms.params.result_type = test_result_type
|
|
64
|
+
sms.params.callback_url = test_callback_url
|
|
65
|
+
|
|
66
|
+
sms = sms.send_simple
|
|
67
|
+
|
|
68
|
+
assert_equal test_recipients[0], sms.result[0].recipient
|
|
69
|
+
assert_equal test_tag, sms.result[0].tag
|
|
70
|
+
assert_equal 'no status', sms.result[0].status
|
|
71
|
+
|
|
72
|
+
assert_equal test_recipients[1], sms.result[1].recipient
|
|
73
|
+
assert_equal test_tag, sms.result[1].tag
|
|
74
|
+
assert_equal 'no status', sms.result[1].status
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
#
|
|
78
|
+
# Test creation of sms with a single number
|
|
79
|
+
#
|
|
80
|
+
def test_create_sms_single
|
|
81
|
+
sms = @twizo.create_sms('test body', nil, 'test sender')
|
|
82
|
+
|
|
83
|
+
test_recipient = NUMBER1
|
|
84
|
+
sms.params.recipients = test_recipient
|
|
85
|
+
|
|
86
|
+
sms = sms.send_simple
|
|
87
|
+
|
|
88
|
+
test_message_id = sms.result[0].messageId
|
|
89
|
+
|
|
90
|
+
status = @twizo.get_sms_status(test_message_id)
|
|
91
|
+
|
|
92
|
+
assert_equal test_message_id, status.messageId
|
|
93
|
+
assert_equal test_recipient, status.recipient
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
#
|
|
97
|
+
# Test creation of sms advanced with a single number
|
|
98
|
+
#
|
|
99
|
+
def test_create_sms_advanced
|
|
100
|
+
sms = @twizo.create_sms('Body', nil, 'test sender')
|
|
101
|
+
|
|
102
|
+
test_recipient = '60178467034'
|
|
103
|
+
sms.params.recipients = test_recipient
|
|
104
|
+
sms.params.dcs = 4
|
|
105
|
+
|
|
106
|
+
sms = sms.send
|
|
107
|
+
|
|
108
|
+
test_message_id = sms.result[0].messageId
|
|
109
|
+
|
|
110
|
+
status = @twizo.get_sms_status(test_message_id)
|
|
111
|
+
|
|
112
|
+
assert_equal test_message_id, status.messageId
|
|
113
|
+
assert_equal test_recipient, status.recipient
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
#
|
|
117
|
+
# Test creation of simple sms
|
|
118
|
+
#
|
|
119
|
+
def test_create_sms_simple
|
|
120
|
+
sms = @twizo.create_sms('test body', nil, 'test sender')
|
|
121
|
+
|
|
122
|
+
test_recipient = NUMBER1
|
|
123
|
+
sms.params.recipients = test_recipient
|
|
124
|
+
|
|
125
|
+
sms = sms.send_simple
|
|
126
|
+
|
|
127
|
+
test_message_id = sms.result[0].messageId
|
|
128
|
+
|
|
129
|
+
status = @twizo.get_sms_status(test_message_id)
|
|
130
|
+
|
|
131
|
+
assert_equal test_message_id, status.messageId
|
|
132
|
+
assert_equal test_recipient, status.recipient
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
#
|
|
136
|
+
# Test creation of sms and get status
|
|
137
|
+
#
|
|
138
|
+
def test_get_sms_status
|
|
139
|
+
test_recipient = NUMBER1
|
|
140
|
+
|
|
141
|
+
sms = @twizo.create_sms('test body', test_recipient, 'test sender')
|
|
142
|
+
sms = sms.send_simple
|
|
143
|
+
|
|
144
|
+
test_message_id = sms.result[0].messageId
|
|
145
|
+
|
|
146
|
+
status = @twizo.get_sms_status(test_message_id)
|
|
147
|
+
|
|
148
|
+
assert_equal test_message_id, status.messageId
|
|
149
|
+
assert_equal test_recipient, status.recipient
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
#
|
|
153
|
+
# Test creation of sms and get results after completion of status
|
|
154
|
+
#
|
|
155
|
+
def test_get_sms_results
|
|
156
|
+
test_recipient = NUMBER1
|
|
157
|
+
|
|
158
|
+
sms = @twizo.create_sms('test body', test_recipient, 'test sender')
|
|
159
|
+
sms.params.result_type = 2
|
|
160
|
+
sms = sms.send_simple
|
|
161
|
+
|
|
162
|
+
x = false
|
|
163
|
+
until x
|
|
164
|
+
if @twizo.get_sms_status(sms.result[0].messageId).status == 'no status'
|
|
165
|
+
sleep 0.5
|
|
166
|
+
next
|
|
167
|
+
end
|
|
168
|
+
x = true
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
results = @twizo.get_sms_results
|
|
172
|
+
|
|
173
|
+
assert_not_nil results.batchId
|
|
174
|
+
|
|
175
|
+
results.result.each do |item|
|
|
176
|
+
assert_not_nil item.recipient
|
|
177
|
+
assert_not_nil item.messageId
|
|
178
|
+
end
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
#
|
|
182
|
+
# Test number input normal
|
|
183
|
+
#
|
|
184
|
+
def test_different_recipients1
|
|
185
|
+
test_recipients = '1234567890'
|
|
186
|
+
sms = @twizo.create_sms('test body', test_recipients, 'test sender')
|
|
187
|
+
|
|
188
|
+
sms = sms.send_simple
|
|
189
|
+
|
|
190
|
+
assert_equal '1234567890', sms.result[0].recipient
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
#
|
|
194
|
+
# Test number input with +
|
|
195
|
+
#
|
|
196
|
+
def test_different_recipients2
|
|
197
|
+
test_recipients = '+1234567890'
|
|
198
|
+
sms = @twizo.create_sms('test body', test_recipients, 'test sender')
|
|
199
|
+
|
|
200
|
+
sms = sms.send_simple
|
|
201
|
+
|
|
202
|
+
assert_equal '1234567890', sms.result[0].recipient
|
|
203
|
+
end
|
|
204
|
+
|
|
205
|
+
#
|
|
206
|
+
# Test number input with 00
|
|
207
|
+
#
|
|
208
|
+
def test_different_recipients3
|
|
209
|
+
test_recipients = '0000001234567890'
|
|
210
|
+
sms = @twizo.create_sms('test body', test_recipients, 'test sender')
|
|
211
|
+
|
|
212
|
+
sms = sms.send_simple
|
|
213
|
+
|
|
214
|
+
assert_equal '1234567890', sms.result[0].recipient
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
#
|
|
218
|
+
# Test number input with ' '
|
|
219
|
+
#
|
|
220
|
+
def test_different_recipients4
|
|
221
|
+
test_recipients = '1 23 45 67 89 0'
|
|
222
|
+
sms = @twizo.create_sms('test body', test_recipients, 'test sender')
|
|
223
|
+
|
|
224
|
+
sms = sms.send_simple
|
|
225
|
+
|
|
226
|
+
assert_equal '1234567890', sms.result[0].recipient
|
|
227
|
+
end
|
|
228
|
+
|
|
229
|
+
#
|
|
230
|
+
# Test number input with Characters
|
|
231
|
+
#
|
|
232
|
+
def test_different_recipients5
|
|
233
|
+
test_recipients = '1 23 A5 67 89 o'
|
|
234
|
+
|
|
235
|
+
assert_raise Twizo::TwizoError do
|
|
236
|
+
sms = @twizo.create_sms('test body', test_recipients, 'test sender')
|
|
237
|
+
|
|
238
|
+
sms.send_simple
|
|
239
|
+
end
|
|
240
|
+
end
|
|
241
|
+
|
|
242
|
+
#
|
|
243
|
+
# Test number input with ()
|
|
244
|
+
#
|
|
245
|
+
def test_different_recipients6
|
|
246
|
+
test_recipients = '(1)234567890'
|
|
247
|
+
sms = @twizo.create_sms('test body', test_recipients, 'test sender')
|
|
248
|
+
|
|
249
|
+
sms = sms.send_simple
|
|
250
|
+
|
|
251
|
+
assert_equal '1234567890', sms.result[0].recipient
|
|
252
|
+
end
|
|
253
|
+
|
|
254
|
+
#
|
|
255
|
+
# Test number input with + and ()
|
|
256
|
+
#
|
|
257
|
+
def test_different_recipients7
|
|
258
|
+
test_recipients = '+(1)234567890'
|
|
259
|
+
sms = @twizo.create_sms('test body', test_recipients, 'test sender')
|
|
260
|
+
|
|
261
|
+
sms = sms.send_simple
|
|
262
|
+
|
|
263
|
+
assert_equal '1234567890', sms.result[0].recipient
|
|
264
|
+
end
|
|
265
|
+
|
|
266
|
+
def teardown
|
|
267
|
+
print "\n#{method_name}"
|
|
268
|
+
end
|
|
269
|
+
|
|
270
|
+
end
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
require_relative 'test_init'
|
|
2
|
+
|
|
3
|
+
=begin
|
|
4
|
+
|
|
5
|
+
This file is part of the Twizo php api
|
|
6
|
+
|
|
7
|
+
(c) Twizo <info@twizo.com>
|
|
8
|
+
|
|
9
|
+
For the full copyright and license information, please view the LICENSE
|
|
10
|
+
File that was distributed with this source code.
|
|
11
|
+
|
|
12
|
+
=end
|
|
13
|
+
|
|
14
|
+
class TestVerification < TestInit
|
|
15
|
+
|
|
16
|
+
#
|
|
17
|
+
# Initialize Twizo
|
|
18
|
+
#
|
|
19
|
+
def setup
|
|
20
|
+
@twizo = Twizo::Twizo.new(API_KEY, API_HOST)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
#
|
|
24
|
+
# Test if an error is thrown when an invalid key is provided
|
|
25
|
+
#
|
|
26
|
+
def test_invalid_key
|
|
27
|
+
api_key = 'invalid_key'
|
|
28
|
+
|
|
29
|
+
assert_raise Twizo::TwizoError do
|
|
30
|
+
@twizo = Twizo::Twizo.new(api_key, API_HOST)
|
|
31
|
+
verification = @twizo.create_verification(NUMBER1)
|
|
32
|
+
verification.send
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
#
|
|
37
|
+
# Test creation of verification
|
|
38
|
+
#
|
|
39
|
+
def test_create_verification
|
|
40
|
+
verification = @twizo.create_verification(nil)
|
|
41
|
+
|
|
42
|
+
test_recipient = NUMBER1
|
|
43
|
+
|
|
44
|
+
verification.params.recipient = test_recipient
|
|
45
|
+
|
|
46
|
+
verification = verification.send
|
|
47
|
+
|
|
48
|
+
assert_equal test_recipient, verification.recipient
|
|
49
|
+
assert_not_nil verification.messageId
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
#
|
|
53
|
+
# Test token verification
|
|
54
|
+
#
|
|
55
|
+
def test_verify_token
|
|
56
|
+
test_recipient = '5412300000'
|
|
57
|
+
|
|
58
|
+
verification = @twizo.create_verification(nil)
|
|
59
|
+
verification.params.recipient = test_recipient
|
|
60
|
+
|
|
61
|
+
verification = verification.send
|
|
62
|
+
|
|
63
|
+
test_message_id = verification.messageId
|
|
64
|
+
test_token = '012345'
|
|
65
|
+
|
|
66
|
+
verify_token = @twizo.verify_token(test_message_id, test_token)
|
|
67
|
+
|
|
68
|
+
assert_equal test_message_id, verify_token.messageId
|
|
69
|
+
assert_equal test_recipient, verify_token.recipient
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
#
|
|
73
|
+
# Test creation of verification and get status
|
|
74
|
+
#
|
|
75
|
+
def test_get_verification_status
|
|
76
|
+
test_recipient = NUMBER1
|
|
77
|
+
|
|
78
|
+
verification = @twizo.create_verification(test_recipient)
|
|
79
|
+
verification = verification.send
|
|
80
|
+
|
|
81
|
+
test_message_id = verification.messageId
|
|
82
|
+
|
|
83
|
+
status = @twizo.get_verification_status(test_message_id)
|
|
84
|
+
|
|
85
|
+
assert_equal test_message_id, status.messageId
|
|
86
|
+
assert_equal test_recipient, status.recipient
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
#
|
|
90
|
+
# Test creation of an invalid verification
|
|
91
|
+
#
|
|
92
|
+
def test_get_verification_status_invalid
|
|
93
|
+
test_recipient = 'number'
|
|
94
|
+
|
|
95
|
+
verification = @twizo.create_verification(test_recipient)
|
|
96
|
+
|
|
97
|
+
assert_raise Twizo::TwizoError do
|
|
98
|
+
verification = verification.send
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def teardown
|
|
103
|
+
print "\n#{method_name}"
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
end
|
data/test/test_widget.rb
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
require_relative 'test_init'
|
|
2
|
+
|
|
3
|
+
=begin
|
|
4
|
+
|
|
5
|
+
This file is part of the Twizo php api
|
|
6
|
+
|
|
7
|
+
(c) Twizo <info@twizo.com>
|
|
8
|
+
|
|
9
|
+
For the full copyright and license information, please view the LICENSE
|
|
10
|
+
File that was distributed with this source code.
|
|
11
|
+
|
|
12
|
+
=end
|
|
13
|
+
|
|
14
|
+
class TestWidget < TestInit
|
|
15
|
+
|
|
16
|
+
#
|
|
17
|
+
# Initialize Twizo
|
|
18
|
+
#
|
|
19
|
+
def setup
|
|
20
|
+
@twizo = Twizo::Twizo.new(API_KEY, API_HOST)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
#
|
|
24
|
+
# Test if an error is thrown when an invalid key is provided
|
|
25
|
+
#
|
|
26
|
+
def test_invalid_key
|
|
27
|
+
api_key = 'invalid_key'
|
|
28
|
+
|
|
29
|
+
assert_raise Twizo::TwizoError do
|
|
30
|
+
@twizo = Twizo::Twizo.new(api_key, API_HOST)
|
|
31
|
+
widget = @twizo.create_widget(NUMBER1)
|
|
32
|
+
widget.send
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
#
|
|
37
|
+
# Test creation of a widget session
|
|
38
|
+
#
|
|
39
|
+
def test_create_widget
|
|
40
|
+
widget = @twizo.create_widget(nil)
|
|
41
|
+
|
|
42
|
+
test_recipient = NUMBER1
|
|
43
|
+
|
|
44
|
+
widget.params.recipient = test_recipient
|
|
45
|
+
|
|
46
|
+
widget = widget.send
|
|
47
|
+
|
|
48
|
+
assert_equal test_recipient, widget.recipient
|
|
49
|
+
assert_not_nil widget.sessionToken
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
#
|
|
53
|
+
# Test widget session allowed types
|
|
54
|
+
#
|
|
55
|
+
def test_widget_type
|
|
56
|
+
widget = @twizo.create_widget(nil)
|
|
57
|
+
widget.params.allowed_types = ['sms']
|
|
58
|
+
|
|
59
|
+
test_recipient = NUMBER1
|
|
60
|
+
|
|
61
|
+
widget.params.recipient = test_recipient
|
|
62
|
+
|
|
63
|
+
widget = widget.send
|
|
64
|
+
|
|
65
|
+
assert_equal test_recipient, widget.recipient
|
|
66
|
+
assert_equal ['sms'], widget.allowedTypes
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
#
|
|
70
|
+
# Test widget session allowed types invalid
|
|
71
|
+
#
|
|
72
|
+
def test_widget_type_invalid
|
|
73
|
+
widget = @twizo.create_widget(nil)
|
|
74
|
+
widget.params.allowed_types = 'sms'
|
|
75
|
+
|
|
76
|
+
test_recipient = NUMBER1
|
|
77
|
+
|
|
78
|
+
widget.params.recipient = test_recipient
|
|
79
|
+
|
|
80
|
+
assert_raise Twizo::TwizoError do
|
|
81
|
+
widget = widget.send
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
#
|
|
86
|
+
# Test creation of widget and get status
|
|
87
|
+
#
|
|
88
|
+
def test_get_widget_status
|
|
89
|
+
widget = @twizo.create_widget(nil)
|
|
90
|
+
|
|
91
|
+
test_recipient = NUMBER1
|
|
92
|
+
|
|
93
|
+
widget.params.recipient = test_recipient
|
|
94
|
+
|
|
95
|
+
widget = widget.send
|
|
96
|
+
|
|
97
|
+
status = @twizo.get_widget_status(widget.sessionToken, widget.recipient)
|
|
98
|
+
|
|
99
|
+
assert_equal widget.sessionToken, status.sessionToken
|
|
100
|
+
assert_equal test_recipient, status.recipient
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def teardown
|
|
104
|
+
print "\n#{method_name}"
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
end
|