inteltech_sms 0.1.4 → 1.0.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.
- data/.travis.yml +8 -0
- data/README.rdoc +43 -0
- data/VERSION +1 -1
- data/inteltech_sms.gemspec +4 -2
- data/lib/dummy_inteltech_sms.rb +61 -0
- data/lib/inteltech_sms.rb +58 -19
- data/test/helper.rb +1 -0
- data/test/test_dummy_inteltech_sms.rb +250 -0
- data/test/test_inteltech_sms.rb +1 -1
- metadata +5 -3
data/.travis.yml
CHANGED
@@ -66,3 +66,11 @@ matrix:
|
|
66
66
|
- RUBYGEMS_VERSION=1.8.25
|
67
67
|
- TEST_GEM=true
|
68
68
|
- secure: "D6Sd+bPmNb3P+98W1arc+SbaFV8oC+0NhnZX9fcoIqCHfnVpt6Vd54idUxJv\nhhFUFmySl17zCX/HRaVoscpCYPcJWRWIeXSD4qrHlObaTx+BDKlMAlWl/Y7d\nQy9c4g+QbDhz94l3DeNW7VbCYz/YYyRPBCcZK+K3H1KPmMtngRU="
|
69
|
+
allow_failures:
|
70
|
+
- rvm: rbx-19mode
|
71
|
+
- rvm: rbx-19mode
|
72
|
+
env:
|
73
|
+
- RUBYGEMS_VERSION=1.8.25
|
74
|
+
- TEST_GEM=true
|
75
|
+
- secure: "D6Sd+bPmNb3P+98W1arc+SbaFV8oC+0NhnZX9fcoIqCHfnVpt6Vd54idUxJv\nhhFUFmySl17zCX/HRaVoscpCYPcJWRWIeXSD4qrHlObaTx+BDKlMAlWl/Y7d\nQy9c4g+QbDhz94l3DeNW7VbCYz/YYyRPBCcZK+K3H1KPmMtngRU="
|
76
|
+
|
data/README.rdoc
CHANGED
@@ -50,6 +50,49 @@ Example ruby code:
|
|
50
50
|
puts "send_multiple_sms (sending to mobiles should work, sending to a landline should fail):"
|
51
51
|
puts res2.collect {|r| "sms to #{r.sms} #{r.success? ? 'was successfull' : "failed (#{r.class} with code #{r.response_code})"}."}.join("\n")
|
52
52
|
|
53
|
+
=== Dummy for testing
|
54
|
+
|
55
|
+
A Dummy class is also provided for use with tests. The dummy class will return a response based on the response code given.
|
56
|
+
|
57
|
+
You can instantiate an instance of the DummyInteltechSms, passing the initial credit, and optionally the response code
|
58
|
+
|
59
|
+
Example ruby code:
|
60
|
+
|
61
|
+
require 'rubygems'
|
62
|
+
|
63
|
+
require 'dummy_inteltech_sms'
|
64
|
+
|
65
|
+
test_sms = '123'
|
66
|
+
|
67
|
+
gateway = DummyInteltechSms.new(1)
|
68
|
+
|
69
|
+
credit = gateway.get_credit.inspect
|
70
|
+
|
71
|
+
puts "You have #{credit} Credit/s left"
|
72
|
+
|
73
|
+
res = gateway.send_sms(test_sms,'Test from Ruby')
|
74
|
+
puts "send_sms to #{res.sms} was successfull."
|
75
|
+
|
76
|
+
credit = gateway.get_credit.inspect
|
77
|
+
puts "You have #{credit} Credit/s left"
|
78
|
+
|
79
|
+
begin
|
80
|
+
# This will return no credit
|
81
|
+
res = gateway.send_sms(test_sms,'Test from Ruby')
|
82
|
+
puts "send_sms to #{res.sms} was successfull."
|
83
|
+
rescue ex => InteltechSms::Error
|
84
|
+
puts "send_sms to #{res.sms} failed. Gateway response #{ex.response.class} with code #{ex.response.response_code}."
|
85
|
+
end
|
86
|
+
|
87
|
+
res2 = gateway.send_multiple_sms([test_sms, test_sms2, landline_sms],'Test from Ruby to multiple numbers')
|
88
|
+
|
89
|
+
gateway.response_code = InteltechSms::UNAUTHORIZED_RESPONSE_CODE
|
90
|
+
# OR
|
91
|
+
gateway = DummyInteltechSms.new(1,InteltechSms::UNAUTHORIZED_RESPONSE_CODE)
|
92
|
+
|
93
|
+
puts "send_multiple_sms (sending to mobiles should work, sending to a landline should fail):"
|
94
|
+
puts res2.collect {|r| "sms to #{r.sms} #{r.success? ? 'was successfull' : "failed (#{r.class} with code #{r.response_code})"}."}.join("\n")
|
95
|
+
|
53
96
|
=== Optional arguments
|
54
97
|
|
55
98
|
There are a few optional parameters that the gateway will accept.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
1.0.0
|
data/inteltech_sms.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "inteltech_sms"
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "1.0.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Ian Heggie"]
|
12
|
-
s.date = "2013-
|
12
|
+
s.date = "2013-12-01"
|
13
13
|
s.description = "Ruby gem that provides an InteltechSms class to check credit and send SMS text messages to single or multiple recipients"
|
14
14
|
s.email = "ian@heggie.biz"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -27,8 +27,10 @@ Gem::Specification.new do |s|
|
|
27
27
|
"Rakefile",
|
28
28
|
"VERSION",
|
29
29
|
"inteltech_sms.gemspec",
|
30
|
+
"lib/dummy_inteltech_sms.rb",
|
30
31
|
"lib/inteltech_sms.rb",
|
31
32
|
"test/helper.rb",
|
33
|
+
"test/test_dummy_inteltech_sms.rb",
|
32
34
|
"test/test_inteltech_sms.rb"
|
33
35
|
]
|
34
36
|
s.homepage = "http://github.com/ianheggie/inteltech_sms"
|
@@ -0,0 +1,61 @@
|
|
1
|
+
|
2
|
+
require 'net/http'
|
3
|
+
|
4
|
+
require 'inteltech_sms'
|
5
|
+
|
6
|
+
# Dummy Class for testing
|
7
|
+
|
8
|
+
class DummyInteltechSms < InteltechSms
|
9
|
+
|
10
|
+
|
11
|
+
attr_accessor :credit, :response_code
|
12
|
+
|
13
|
+
def initialize(credit, response_code = InteltechSms::SUCCESS_RESPONSE_CODE)
|
14
|
+
super('dummy_user', 'a_secret')
|
15
|
+
@credit = credit.to_i
|
16
|
+
@response_code = response_code
|
17
|
+
@last_sms = ''
|
18
|
+
end
|
19
|
+
|
20
|
+
def get_credit
|
21
|
+
res = InteltechSms::FakeHTTPSuccess.new(@response_code == InteltechSms::SUCCESS_RESPONSE_CODE ? "credit,#{@credit}" : @response_code)
|
22
|
+
process_get_credit_response(res)
|
23
|
+
end
|
24
|
+
|
25
|
+
def send_sms(sms, message, options = { })
|
26
|
+
this_response_code = response_code_for_sms(sms)
|
27
|
+
@credit -= 1 if this_response_code == InteltechSms::SUCCESS_RESPONSE_CODE
|
28
|
+
res = InteltechSms::FakeHTTPSuccess.new(this_response_code)
|
29
|
+
process_send_sms_response(res, sms)
|
30
|
+
end
|
31
|
+
|
32
|
+
def send_multiple_sms(sms, message, options = { })
|
33
|
+
this_response_code = response_code_for_sms(sms)
|
34
|
+
sms_array = (sms.respond_to?(:each) ? sms : sms.split(','))
|
35
|
+
@credit -= sms_array.size if this_response_code == InteltechSms::SUCCESS_RESPONSE_CODE
|
36
|
+
|
37
|
+
ret = [ ]
|
38
|
+
sms_array.each do |this_sms|
|
39
|
+
ret << Response.factory(this_sms.strip, this_response_code)
|
40
|
+
end
|
41
|
+
ret
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def response_code_for_sms(sms)
|
47
|
+
ret = @response_code
|
48
|
+
if ret == InteltechSms::SUCCESS_RESPONSE_CODE
|
49
|
+
if @credit <= 0
|
50
|
+
ret = InteltechSms::NO_CREDIT_RESPONSE_CODE
|
51
|
+
else
|
52
|
+
ret = @last_sms == sms ? InteltechSms::DUPLICATE_RESPONSE_CODE : @response_code
|
53
|
+
@last_sms = sms
|
54
|
+
end
|
55
|
+
end
|
56
|
+
ret
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
# vi:ai sw=2:
|
data/lib/inteltech_sms.rb
CHANGED
@@ -3,6 +3,28 @@ require "rexml/document"
|
|
3
3
|
|
4
4
|
class InteltechSms
|
5
5
|
|
6
|
+
SUCCESS_RESPONSE_CODE = '0000'
|
7
|
+
UNAUTHORIZED_RESPONSE_CODE = '2006'
|
8
|
+
ACCOUNT_NOT_ACTIVATED_RESPONSE_CODE = '2007'
|
9
|
+
INVALID_NUMBER_RESPONSE_CODE = '2015'
|
10
|
+
DUPLICATE_RESPONSE_CODE = '2016'
|
11
|
+
NO_CREDIT_RESPONSE_CODE = '2018'
|
12
|
+
UNAUTHORIZED_KEY_RESPONSE_CODE = '2022'
|
13
|
+
EMPTY_MESSAGE_RESPONSE_CODE = '2051'
|
14
|
+
TOO_MANY_RECIPIENTS_RESPONSE_CODE = '2052'
|
15
|
+
|
16
|
+
# General failures
|
17
|
+
INVALID_SENDER_RESPONSE_CODE = '2017'
|
18
|
+
|
19
|
+
class FakeHTTPSuccess
|
20
|
+
attr_accessor :body
|
21
|
+
|
22
|
+
def initialize(body)
|
23
|
+
@body = body
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
|
6
28
|
class Error < StandardError
|
7
29
|
attr_reader :response
|
8
30
|
def initialize(response)
|
@@ -22,20 +44,24 @@ class InteltechSms
|
|
22
44
|
|
23
45
|
def self.factory(sms, response_code)
|
24
46
|
case response_code.strip
|
25
|
-
when
|
47
|
+
when SUCCESS_RESPONSE_CODE
|
26
48
|
Success.new(sms, response_code)
|
27
|
-
when
|
49
|
+
when UNAUTHORIZED_RESPONSE_CODE
|
28
50
|
Unauthorized.new(sms, response_code)
|
29
|
-
when
|
51
|
+
when INVALID_NUMBER_RESPONSE_CODE
|
30
52
|
BadRequest.new(sms, response_code)
|
31
|
-
when
|
53
|
+
when DUPLICATE_RESPONSE_CODE
|
32
54
|
Duplicate.new(sms, response_code)
|
33
|
-
when
|
55
|
+
when NO_CREDIT_RESPONSE_CODE
|
34
56
|
NoCredit.new(sms, response_code)
|
35
|
-
when
|
57
|
+
when UNAUTHORIZED_KEY_RESPONSE_CODE
|
36
58
|
Unauthorized.new(sms, response_code)
|
37
|
-
when
|
59
|
+
when EMPTY_MESSAGE_RESPONSE_CODE
|
60
|
+
BadRequest.new(sms, response_code)
|
61
|
+
when TOO_MANY_RECIPIENTS_RESPONSE_CODE
|
38
62
|
BadRequest.new(sms, response_code)
|
63
|
+
when ACCOUNT_NOT_ACTIVATED_RESPONSE_CODE
|
64
|
+
Unauthorized.new(sms, response_code)
|
39
65
|
else
|
40
66
|
Failure.new(sms, response_code)
|
41
67
|
end
|
@@ -86,8 +112,29 @@ class InteltechSms
|
|
86
112
|
def get_credit
|
87
113
|
uri = URI('http://inteltech.com.au/secure-api/credit.php')
|
88
114
|
res = Net::HTTP.post_form(uri, 'username' => @username, 'key' => @secret_key, 'method' => 'ruby')
|
115
|
+
process_get_credit_response(res)
|
116
|
+
end
|
117
|
+
|
118
|
+
def send_sms(sms, message, options = { })
|
119
|
+
uri = URI('http://inteltech.com.au/secure-api/send.single.php')
|
120
|
+
args = { :username => @username, :key => @secret_key, :sms => sms, :message => message, :method => 'ruby' }.merge(options)
|
121
|
+
res = Net::HTTP.post_form(uri, args)
|
122
|
+
process_send_sms_response(res, sms)
|
123
|
+
end
|
124
|
+
|
125
|
+
def send_multiple_sms(sms, message, options = { })
|
126
|
+
uri = URI('http://inteltech.com.au/secure-api/send.php')
|
127
|
+
sms_string = sms.respond_to?(:join) ? sms.join(',') : sms.to_s
|
128
|
+
args = { :username => @username, :key => @secret_key, :sms => sms_string, :message => message, :method => 'ruby' }.merge(options)
|
129
|
+
res = Net::HTTP.post_form(uri, args)
|
130
|
+
process_send_multiple_sms_response(res)
|
131
|
+
end
|
132
|
+
|
133
|
+
protected
|
134
|
+
|
135
|
+
def process_get_credit_response(res)
|
89
136
|
case res
|
90
|
-
when Net::HTTPSuccess, Net::HTTPRedirection
|
137
|
+
when Net::HTTPSuccess, Net::HTTPRedirection, InteltechSms::FakeHTTPSuccess
|
91
138
|
if res.body =~ /credit,(\d*)/
|
92
139
|
$1.to_i
|
93
140
|
elsif res.body =~ /\d\d\d\d/
|
@@ -100,13 +147,9 @@ class InteltechSms
|
|
100
147
|
end
|
101
148
|
end
|
102
149
|
|
103
|
-
def
|
104
|
-
uri = URI('http://inteltech.com.au/secure-api/send.single.php')
|
105
|
-
|
106
|
-
args = { :username => @username, :key => @secret_key, :sms => sms, :message => message, :method => 'ruby' }.merge(options)
|
107
|
-
res = Net::HTTP.post_form(uri, args)
|
150
|
+
def process_send_sms_response(res, sms)
|
108
151
|
case res
|
109
|
-
when Net::HTTPSuccess, Net::HTTPRedirection
|
152
|
+
when Net::HTTPSuccess, Net::HTTPRedirection, InteltechSms::FakeHTTPSuccess
|
110
153
|
r= Response.factory(sms, res.body)
|
111
154
|
raise InteltechSms::Error.new(r) unless r.success?
|
112
155
|
r
|
@@ -115,11 +158,7 @@ class InteltechSms
|
|
115
158
|
end
|
116
159
|
end
|
117
160
|
|
118
|
-
def
|
119
|
-
uri = URI('http://inteltech.com.au/secure-api/send.php')
|
120
|
-
sms_string = sms.respond_to?(:join) ? sms.join(',') : sms.to_s
|
121
|
-
args = { :username => @username, :key => @secret_key, :sms => sms_string, :message => message, :method => 'ruby' }.merge(options)
|
122
|
-
res = Net::HTTP.post_form(uri, args)
|
161
|
+
def process_send_multiple_sms_response(res)
|
123
162
|
case res
|
124
163
|
when Net::HTTPSuccess, Net::HTTPRedirection
|
125
164
|
doc = REXML::Document.new res.body
|
data/test/helper.rb
CHANGED
@@ -0,0 +1,250 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'net/http'
|
3
|
+
|
4
|
+
class TestDummyInteltechSms < Test::Unit::TestCase
|
5
|
+
|
6
|
+
# ==================================================
|
7
|
+
# Useful constants
|
8
|
+
|
9
|
+
TEST_SMS = '04111'
|
10
|
+
TEST_SMS2 = '04222'
|
11
|
+
LANDLINE_SMS = '03123'
|
12
|
+
|
13
|
+
# ==================================================
|
14
|
+
# Tests
|
15
|
+
|
16
|
+
# Code 0000 Message added to queue OK.
|
17
|
+
|
18
|
+
context "with credit" do
|
19
|
+
|
20
|
+
setup do
|
21
|
+
@good_gateway = DummyInteltechSms.new(123)
|
22
|
+
end
|
23
|
+
|
24
|
+
should "get_credit should return non zero credit" do
|
25
|
+
assert_operator @good_gateway.get_credit, :>, 0
|
26
|
+
end
|
27
|
+
|
28
|
+
should "send a single test sms via send_sms" do
|
29
|
+
expected = InteltechSms::Success.new(TEST_SMS, InteltechSms::SUCCESS_RESPONSE_CODE)
|
30
|
+
assert_equal expected, @good_gateway.send_sms(TEST_SMS,'Test from Ruby - send a single test sms via send_sms')
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context "#send_multiple_sms" do
|
35
|
+
should "return an array with a response for each sms sent" do
|
36
|
+
@good_gateway = DummyInteltechSms.new(123)
|
37
|
+
@res = @good_gateway.send_multiple_sms [TEST_SMS, TEST_SMS2],'Test from Ruby - return an array with a response for each sms sent'
|
38
|
+
assert_kind_of Array, @res
|
39
|
+
assert_equal 2, @res.length
|
40
|
+
assert_equal InteltechSms::Success.new(TEST_SMS, InteltechSms::SUCCESS_RESPONSE_CODE), @res[0], "send_multiple_sms returns success for 1st element"
|
41
|
+
assert_equal InteltechSms::Success.new(TEST_SMS2, InteltechSms::SUCCESS_RESPONSE_CODE), @res[1], "send_multiple_sms returns success for 2nd element"
|
42
|
+
end
|
43
|
+
|
44
|
+
should "return an array with a response for each sms sent where a comma seperated string is provided" do
|
45
|
+
@good_gateway = DummyInteltechSms.new(123)
|
46
|
+
@res = @good_gateway.send_multiple_sms [TEST_SMS2, TEST_SMS].join(','),'Test from Ruby - return an array with a response for each sms sent where a comma seperated string is provided'
|
47
|
+
assert_kind_of Array, @res
|
48
|
+
assert_equal 2, @res.length
|
49
|
+
assert_equal InteltechSms::Success.new(TEST_SMS2, InteltechSms::SUCCESS_RESPONSE_CODE), @res[0], "send_multiple_sms returns success for 1st element"
|
50
|
+
assert_equal InteltechSms::Success.new(TEST_SMS, InteltechSms::SUCCESS_RESPONSE_CODE), @res[1], "send_multiple_sms returns success for 2nd element"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
# --------------------------------------------------
|
55
|
+
# Code 2006 Not enough information has been supplied for authentication. Please ensure that your Username and Unique Key are supplied in your request.
|
56
|
+
|
57
|
+
context "with blank username" do
|
58
|
+
setup do
|
59
|
+
@bad_gateway = DummyInteltechSms.new(0, InteltechSms::UNAUTHORIZED_RESPONSE_CODE)
|
60
|
+
end
|
61
|
+
|
62
|
+
should "raise an Unauthorized Error exception when get_credit is called" do
|
63
|
+
ex = assert_raises InteltechSms::Error do
|
64
|
+
@bad_gateway.get_credit
|
65
|
+
end
|
66
|
+
assert_equal InteltechSms::Unauthorized.new('', InteltechSms::UNAUTHORIZED_RESPONSE_CODE), ex.response
|
67
|
+
end
|
68
|
+
|
69
|
+
should "raise an Unauthorized Error exception when send_sms is called" do
|
70
|
+
ex = assert_raises InteltechSms::Error do
|
71
|
+
@bad_gateway.send_sms TEST_SMS, 'Tests from ruby - with blank username raise an Unauthorized Error exception when send_sms is called'
|
72
|
+
end
|
73
|
+
assert_equal InteltechSms::Unauthorized.new(TEST_SMS, InteltechSms::UNAUTHORIZED_RESPONSE_CODE), ex.response
|
74
|
+
end
|
75
|
+
|
76
|
+
should "return an array Unauthorized responses when send_multiple_sms is called" do
|
77
|
+
@res = @bad_gateway.send_multiple_sms [TEST_SMS, TEST_SMS2], 'Test from Ruby - with blank username return an array Unauthorized responses when send_multiple_sms is called'
|
78
|
+
assert_kind_of Array, @res
|
79
|
+
assert_equal 2, @res.length, "send_multiple_sms returns results for each sms sent"
|
80
|
+
assert_kind_of InteltechSms::Unauthorized, @res[0], "send_multiple_sms returns Unauthorized for 1st element"
|
81
|
+
assert_equal InteltechSms::Unauthorized.new(TEST_SMS, InteltechSms::UNAUTHORIZED_RESPONSE_CODE), @res[0]
|
82
|
+
assert_kind_of InteltechSms::Unauthorized, @res[1], "send_multiple_sms returns Unauthorized for 2nd element"
|
83
|
+
assert_equal InteltechSms::Unauthorized.new(TEST_SMS2, InteltechSms::UNAUTHORIZED_RESPONSE_CODE), @res[1]
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
|
88
|
+
# --------------------------------------------------
|
89
|
+
# Code 2015 The destination mobile number is invalid.
|
90
|
+
|
91
|
+
# --------------------------------------------------
|
92
|
+
# Code 2016 Identical message sent to this recipient. Please try again in a few seconds.
|
93
|
+
|
94
|
+
context "with a good username and secure_key" do
|
95
|
+
|
96
|
+
setup do
|
97
|
+
@good_gateway = DummyInteltechSms.new(123)
|
98
|
+
end
|
99
|
+
|
100
|
+
should "reject the second of a pair of indentical messages" do
|
101
|
+
expected = InteltechSms::BadRequest.new(TEST_SMS, InteltechSms::DUPLICATE_RESPONSE_CODE)
|
102
|
+
@good_gateway.send_sms(TEST_SMS,'Test from Ruby - send two copies of single test sms via send_sms')
|
103
|
+
|
104
|
+
@good_gateway.response_code = InteltechSms::DUPLICATE_RESPONSE_CODE
|
105
|
+
|
106
|
+
ex = assert_raises InteltechSms::Error do
|
107
|
+
@good_gateway.send_sms(TEST_SMS,'Test from Ruby - send two copies of single test sms via send_sms')
|
108
|
+
end
|
109
|
+
assert_equal InteltechSms::Duplicate.new(TEST_SMS, InteltechSms::DUPLICATE_RESPONSE_CODE), ex.response
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
113
|
+
|
114
|
+
# --------------------------------------------------
|
115
|
+
# Code 2018 You have reached the end of your message credits. You will need to purchase more messages.
|
116
|
+
|
117
|
+
context "With an account without credit" do
|
118
|
+
setup do
|
119
|
+
@nocredit_gateway = DummyInteltechSms.new(0)
|
120
|
+
end
|
121
|
+
|
122
|
+
should "have get_credit return zero credit" do
|
123
|
+
assert_equal 0, @nocredit_gateway.get_credit
|
124
|
+
end
|
125
|
+
|
126
|
+
should "raise an NoCredit Error exception when send_sms is called" do
|
127
|
+
@nocredit_gateway.response_code = InteltechSms::NO_CREDIT_RESPONSE_CODE
|
128
|
+
ex = assert_raises InteltechSms::Error do
|
129
|
+
@nocredit_gateway.send_sms TEST_SMS, 'Test from ruby - no credit on send_sms'
|
130
|
+
end
|
131
|
+
assert_equal InteltechSms::NoCredit.new(TEST_SMS, InteltechSms::NO_CREDIT_RESPONSE_CODE), ex.response
|
132
|
+
end
|
133
|
+
|
134
|
+
should "return an array NoCredit responses when send_multiple_sms is called" do
|
135
|
+
@res = @nocredit_gateway.send_multiple_sms [TEST_SMS, TEST_SMS2], 'Test from Ruby - return an array NoCredit responses when send_multiple_sms is called'
|
136
|
+
assert_kind_of Array, @res
|
137
|
+
assert_equal 2, @res.length, "send_multiple_sms returns results for each sms sent"
|
138
|
+
assert_kind_of InteltechSms::NoCredit, @res[0], "send_multiple_sms returns NoCredit for 1st element"
|
139
|
+
assert_equal InteltechSms::NoCredit.new(TEST_SMS, InteltechSms::NO_CREDIT_RESPONSE_CODE), @res[0]
|
140
|
+
assert_kind_of InteltechSms::NoCredit, @res[1], "send_multiple_sms returns NoCredit for 2nd element"
|
141
|
+
assert_equal InteltechSms::NoCredit.new(TEST_SMS2, InteltechSms::NO_CREDIT_RESPONSE_CODE), @res[1]
|
142
|
+
end
|
143
|
+
|
144
|
+
end
|
145
|
+
|
146
|
+
# --------------------------------------------------
|
147
|
+
# Code 2022 Your Unique Key is incorrect. This may be caused by a recent password change.
|
148
|
+
|
149
|
+
context "With an incorrect secure_key" do
|
150
|
+
setup do
|
151
|
+
@bad_gateway = DummyInteltechSms.new(0, InteltechSms::UNAUTHORIZED_KEY_RESPONSE_CODE)
|
152
|
+
end
|
153
|
+
|
154
|
+
should "raise an Unauthorized Error exception when get_credit is called" do
|
155
|
+
ex = assert_raises InteltechSms::Error do
|
156
|
+
@bad_gateway.get_credit
|
157
|
+
end
|
158
|
+
assert_equal InteltechSms::Unauthorized.new('', InteltechSms::UNAUTHORIZED_KEY_RESPONSE_CODE), ex.response
|
159
|
+
end
|
160
|
+
|
161
|
+
should "raise an Unauthorized Error exception when send_sms is called" do
|
162
|
+
ex = assert_raises InteltechSms::Error do
|
163
|
+
@bad_gateway.send_sms TEST_SMS, 'Test from ruby - incorrect secure key send_sms call'
|
164
|
+
end
|
165
|
+
assert_equal InteltechSms::Unauthorized.new(TEST_SMS, InteltechSms::UNAUTHORIZED_KEY_RESPONSE_CODE), ex.response
|
166
|
+
end
|
167
|
+
|
168
|
+
should "return an array Unauthorized responses when send_multiple_sms is called" do
|
169
|
+
@res = @bad_gateway.send_multiple_sms [TEST_SMS, TEST_SMS2], 'Test from Ruby - with incorrect key return an array Unauthorized responses when send_multiple_sms is called'
|
170
|
+
assert_kind_of Array, @res
|
171
|
+
assert_equal 2, @res.length, "send_multiple_sms returns results for each sms sent"
|
172
|
+
assert_kind_of InteltechSms::Unauthorized, @res[0], "send_multiple_sms returns Unauthorized for 1st element"
|
173
|
+
assert_equal InteltechSms::Unauthorized.new(TEST_SMS, InteltechSms::UNAUTHORIZED_KEY_RESPONSE_CODE), @res[0]
|
174
|
+
assert_kind_of InteltechSms::Unauthorized, @res[1], "send_multiple_sms returns Unauthorized for 2nd element"
|
175
|
+
assert_equal InteltechSms::Unauthorized.new(TEST_SMS2, InteltechSms::UNAUTHORIZED_KEY_RESPONSE_CODE), @res[1]
|
176
|
+
end
|
177
|
+
|
178
|
+
end
|
179
|
+
|
180
|
+
context "with blank secure_key" do
|
181
|
+
setup do
|
182
|
+
@bad_gateway = DummyInteltechSms.new(0, InteltechSms::UNAUTHORIZED_KEY_RESPONSE_CODE)
|
183
|
+
end
|
184
|
+
|
185
|
+
should "raise an Unauthorized Error exception when get_credit is called" do
|
186
|
+
ex = assert_raises InteltechSms::Error do
|
187
|
+
@bad_gateway.get_credit
|
188
|
+
end
|
189
|
+
assert_equal InteltechSms::Unauthorized.new('', InteltechSms::UNAUTHORIZED_KEY_RESPONSE_CODE), ex.response
|
190
|
+
end
|
191
|
+
|
192
|
+
should "raise an Unauthorized Error exception when send_sms is called" do
|
193
|
+
ex = assert_raises InteltechSms::Error do
|
194
|
+
@bad_gateway.send_sms TEST_SMS, 'Test from ruby - blank secure key send_sms call'
|
195
|
+
end
|
196
|
+
assert_equal InteltechSms::Unauthorized.new(TEST_SMS, InteltechSms::UNAUTHORIZED_KEY_RESPONSE_CODE), ex.response
|
197
|
+
end
|
198
|
+
|
199
|
+
should "return an array Unauthorized responses when send_multiple_sms is called" do
|
200
|
+
@res = @bad_gateway.send_multiple_sms [TEST_SMS, TEST_SMS2], 'Test from Ruby - with blank secure key return an array Unauthorized responses when send_multiple_sms is called'
|
201
|
+
assert_kind_of Array, @res
|
202
|
+
assert_equal 2, @res.length, "send_multiple_sms returns results for each sms sent"
|
203
|
+
assert_kind_of InteltechSms::Unauthorized, @res[0], "send_multiple_sms returns Unauthorized for 1st element"
|
204
|
+
assert_equal InteltechSms::Unauthorized.new(TEST_SMS, InteltechSms::UNAUTHORIZED_KEY_RESPONSE_CODE), @res[0]
|
205
|
+
assert_kind_of InteltechSms::Unauthorized, @res[1], "send_multiple_sms returns Unauthorized for 2nd element"
|
206
|
+
assert_equal InteltechSms::Unauthorized.new(TEST_SMS2, InteltechSms::UNAUTHORIZED_KEY_RESPONSE_CODE), @res[1]
|
207
|
+
end
|
208
|
+
|
209
|
+
end
|
210
|
+
|
211
|
+
# --------------------------------------------------
|
212
|
+
# Code 2051 Message is empty.
|
213
|
+
|
214
|
+
context "with an empty message" do
|
215
|
+
|
216
|
+
setup do
|
217
|
+
@good_gateway = DummyInteltechSms.new(0, InteltechSms::EMPTY_MESSAGE_RESPONSE_CODE)
|
218
|
+
end
|
219
|
+
|
220
|
+
should "raise an BadRequest Error exception when send_sms is called" do
|
221
|
+
ex = assert_raises InteltechSms::Error do
|
222
|
+
@good_gateway.send_sms TEST_SMS, ''
|
223
|
+
end
|
224
|
+
assert_equal InteltechSms::BadRequest.new(TEST_SMS, InteltechSms::EMPTY_MESSAGE_RESPONSE_CODE), ex.response
|
225
|
+
end
|
226
|
+
|
227
|
+
should "return an array BadRequest responses when send_multiple_sms is called" do
|
228
|
+
@res = @good_gateway.send_multiple_sms [TEST_SMS, TEST_SMS2, LANDLINE_SMS], ''
|
229
|
+
assert_kind_of Array, @res
|
230
|
+
assert_equal 3, @res.length, "send_multiple_sms returns results for each sms sent"
|
231
|
+
assert_kind_of InteltechSms::BadRequest, @res[0], "send_multiple_sms returns BadRequest for 1st element"
|
232
|
+
assert_equal InteltechSms::BadRequest.new(TEST_SMS, InteltechSms::EMPTY_MESSAGE_RESPONSE_CODE), @res[0]
|
233
|
+
assert_kind_of InteltechSms::BadRequest, @res[1], "send_multiple_sms returns BadRequest for 2nd element"
|
234
|
+
assert_equal InteltechSms::BadRequest.new(TEST_SMS2, InteltechSms::EMPTY_MESSAGE_RESPONSE_CODE), @res[1]
|
235
|
+
assert_kind_of InteltechSms::BadRequest, @res[2], "send_multiple_sms returns BadRequest for 2nd element"
|
236
|
+
assert_equal InteltechSms::BadRequest.new(LANDLINE_SMS, InteltechSms::EMPTY_MESSAGE_RESPONSE_CODE), @res[2]
|
237
|
+
end
|
238
|
+
|
239
|
+
end
|
240
|
+
|
241
|
+
|
242
|
+
# --------------------------------------------------
|
243
|
+
# Code 2100-2199 Internal error
|
244
|
+
|
245
|
+
# (Unable to trigger these errors to test them)
|
246
|
+
|
247
|
+
end
|
248
|
+
|
249
|
+
# vi: sw=2 sm ai:
|
250
|
+
|
data/test/test_inteltech_sms.rb
CHANGED
@@ -84,7 +84,7 @@ class TestInteltechSms < Test::Unit::TestCase
|
|
84
84
|
assert_equal InteltechSms::Success.new(TEST_SMS2, "0000"), @res[0], "send_multiple_sms returns success for 1st element"
|
85
85
|
assert_equal InteltechSms::Success.new(TEST_SMS, "0000"), @res[1], "send_multiple_sms returns success for 2nd element"
|
86
86
|
end
|
87
|
-
|
87
|
+
end
|
88
88
|
end
|
89
89
|
|
90
90
|
# --------------------------------------------------
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: inteltech_sms
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.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: 2013-
|
12
|
+
date: 2013-12-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rdoc
|
@@ -142,8 +142,10 @@ files:
|
|
142
142
|
- Rakefile
|
143
143
|
- VERSION
|
144
144
|
- inteltech_sms.gemspec
|
145
|
+
- lib/dummy_inteltech_sms.rb
|
145
146
|
- lib/inteltech_sms.rb
|
146
147
|
- test/helper.rb
|
148
|
+
- test/test_dummy_inteltech_sms.rb
|
147
149
|
- test/test_inteltech_sms.rb
|
148
150
|
homepage: http://github.com/ianheggie/inteltech_sms
|
149
151
|
licenses:
|
@@ -160,7 +162,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
160
162
|
version: '0'
|
161
163
|
segments:
|
162
164
|
- 0
|
163
|
-
hash:
|
165
|
+
hash: -1430435096325391718
|
164
166
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
165
167
|
none: false
|
166
168
|
requirements:
|