inteltech_sms 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.travis.yml +13 -0
- data/Gemfile +15 -0
- data/Gemfile.lock +25 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +70 -0
- data/Rakefile +53 -0
- data/VERSION +1 -0
- data/inteltech_sms.gemspec +63 -0
- data/lib/inteltech_sms.rb +135 -0
- data/test/helper.rb +18 -0
- data/test/test_inteltech_sms.rb +277 -0
- metadata +151 -0
data/.document
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
# Add dependencies to develop your gem here.
|
7
|
+
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
group :development do
|
9
|
+
gem "rdoc", "~> 3.12"
|
10
|
+
gem "bundler", "~> 1.2.3"
|
11
|
+
gem "jeweler", "~> 1.8.4"
|
12
|
+
gem "rcov", ">= 0"
|
13
|
+
gem 'shoulda-context', '>= 0'
|
14
|
+
end
|
15
|
+
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
git (1.2.5)
|
5
|
+
jeweler (1.8.4)
|
6
|
+
bundler (~> 1.0)
|
7
|
+
git (>= 1.2.5)
|
8
|
+
rake
|
9
|
+
rdoc
|
10
|
+
json (1.7.6)
|
11
|
+
rake (10.0.3)
|
12
|
+
rcov (1.0.0)
|
13
|
+
rdoc (3.12)
|
14
|
+
json (~> 1.4)
|
15
|
+
shoulda-context (1.0.2)
|
16
|
+
|
17
|
+
PLATFORMS
|
18
|
+
ruby
|
19
|
+
|
20
|
+
DEPENDENCIES
|
21
|
+
bundler (~> 1.2.3)
|
22
|
+
jeweler (~> 1.8.4)
|
23
|
+
rcov
|
24
|
+
rdoc (~> 3.12)
|
25
|
+
shoulda-context
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2013 Ian Heggie
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
= inteltech_sms
|
2
|
+
|
3
|
+
InteltechSms is a ruby gem that provides an InteltechSms class to check credit and send SMS text messages to single or multiple recipients
|
4
|
+
|
5
|
+
== Contributing to inteltech_sms
|
6
|
+
|
7
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
8
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
9
|
+
* Fork the project.
|
10
|
+
* Start a feature/bugfix branch.
|
11
|
+
* Commit and push until you are happy with your contribution.
|
12
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
|
+
|
15
|
+
== Installation
|
16
|
+
|
17
|
+
As a Plugin (eg rails 2.3.x)
|
18
|
+
|
19
|
+
% cd vendor/plugins
|
20
|
+
% git clone git://github.com/ianheggie/inteltech_sms.git
|
21
|
+
|
22
|
+
As a Gem from gemcutter
|
23
|
+
|
24
|
+
% gem install inteltech_sms
|
25
|
+
|
26
|
+
== Usage
|
27
|
+
|
28
|
+
You will require an account with inteltech.com.au for the username and secret key. New accounts come with some free credits.
|
29
|
+
|
30
|
+
Note: Inteltech's gateway assumes numbers not in international format (ie starting with a plus sign) are australian numbers.
|
31
|
+
|
32
|
+
Example ruby code:
|
33
|
+
|
34
|
+
require 'rubygems'
|
35
|
+
|
36
|
+
require 'inteltech_sms'
|
37
|
+
|
38
|
+
username = ENV['SMS_USERNAME'] || abort("Missing SMS_USERNAME env variable")
|
39
|
+
secure_key = ENV['SMS_KEY'] || abort("Missing SMS_KEY env variable")
|
40
|
+
|
41
|
+
test_sms = '0411111111'
|
42
|
+
test_sms2 = '+8611111111111'
|
43
|
+
landline_sms = '0862252608' # Inteltech's landline number
|
44
|
+
|
45
|
+
gateway = InteltechSms.new(username, secure_key)
|
46
|
+
|
47
|
+
credit = gateway.get_credit.inspect
|
48
|
+
|
49
|
+
puts "You have #{credit} Credit/s left"
|
50
|
+
|
51
|
+
begin
|
52
|
+
res = gateway.send_sms(test_sms,'Test from Ruby')
|
53
|
+
puts "send_sms to #{res.sms} was successfull."
|
54
|
+
rescue ex => InteltechSms::Error
|
55
|
+
puts "send_sms to #{res.sms} failed. Gateway response #{ex.response.class} with code #{ex.response.response_code}."
|
56
|
+
end
|
57
|
+
|
58
|
+
res2 = gateway.send_multiple_sms([test_sms, test_sms2, landline_sms],'Test from Ruby to multiple numbers')
|
59
|
+
|
60
|
+
puts "send_multiple_sms (sending to mobiles should work, sending to a landline should fail):"
|
61
|
+
puts res2.collect {|r| "sms to #{r.sms} #{r.success? ? 'was successfull' : "failed (#{r.class} with code #{r.response_code})"}."}.join("\n")
|
62
|
+
|
63
|
+
== Continuous integration tests
|
64
|
+
|
65
|
+
Travis CI testing result: {<img src="https://travis-ci.org/ianheggie/inteltech_sms.png" />}[https://travis-ci.org/ianheggie/inteltech_sms]
|
66
|
+
|
67
|
+
== Copyright
|
68
|
+
|
69
|
+
Copyright (c) 2013 Ian Heggie. See LICENSE.txt for further details.
|
70
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "inteltech_sms"
|
18
|
+
gem.homepage = "http://github.com/ianheggie/inteltech_sms"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{Ruby Gem to send SMS via inteltech.com.au}
|
21
|
+
gem.description = %Q{Ruby gem that provides an InteltechSms class to check credit and send SMS text messages to single or multiple recipients}
|
22
|
+
gem.email = "ian@heggie.biz"
|
23
|
+
gem.authors = ["Ian Heggie"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rake/testtask'
|
29
|
+
Rake::TestTask.new(:test) do |test|
|
30
|
+
test.libs << 'lib' << 'test'
|
31
|
+
test.pattern = 'test/**/test_*.rb'
|
32
|
+
test.verbose = true
|
33
|
+
end
|
34
|
+
|
35
|
+
require 'rcov/rcovtask'
|
36
|
+
Rcov::RcovTask.new do |test|
|
37
|
+
test.libs << 'test'
|
38
|
+
test.pattern = 'test/**/test_*.rb'
|
39
|
+
test.verbose = true
|
40
|
+
test.rcov_opts << '--exclude "gems/*"'
|
41
|
+
end
|
42
|
+
|
43
|
+
task :default => :test
|
44
|
+
|
45
|
+
require 'rdoc/task'
|
46
|
+
Rake::RDocTask.new do |rdoc|
|
47
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
48
|
+
|
49
|
+
rdoc.rdoc_dir = 'rdoc'
|
50
|
+
rdoc.title = "inteltech_sms #{version}"
|
51
|
+
rdoc.rdoc_files.include('README*')
|
52
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
53
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "inteltech_sms"
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Ian Heggie"]
|
12
|
+
s.date = "2013-01-22"
|
13
|
+
s.description = "Ruby gem that provides an InteltechSms class to check credit and send SMS text messages to single or multiple recipients"
|
14
|
+
s.email = "ian@heggie.biz"
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".travis.yml",
|
22
|
+
"Gemfile",
|
23
|
+
"Gemfile.lock",
|
24
|
+
"LICENSE.txt",
|
25
|
+
"README.rdoc",
|
26
|
+
"Rakefile",
|
27
|
+
"VERSION",
|
28
|
+
"inteltech_sms.gemspec",
|
29
|
+
"lib/inteltech_sms.rb",
|
30
|
+
"test/helper.rb",
|
31
|
+
"test/test_inteltech_sms.rb"
|
32
|
+
]
|
33
|
+
s.homepage = "http://github.com/ianheggie/inteltech_sms"
|
34
|
+
s.licenses = ["MIT"]
|
35
|
+
s.require_paths = ["lib"]
|
36
|
+
s.rubygems_version = "1.8.24"
|
37
|
+
s.summary = "Ruby Gem to send SMS via inteltech.com.au"
|
38
|
+
|
39
|
+
if s.respond_to? :specification_version then
|
40
|
+
s.specification_version = 3
|
41
|
+
|
42
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
43
|
+
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
44
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.2.3"])
|
45
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
|
46
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
47
|
+
s.add_development_dependency(%q<shoulda-context>, [">= 0"])
|
48
|
+
else
|
49
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
50
|
+
s.add_dependency(%q<bundler>, ["~> 1.2.3"])
|
51
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
52
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
53
|
+
s.add_dependency(%q<shoulda-context>, [">= 0"])
|
54
|
+
end
|
55
|
+
else
|
56
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
57
|
+
s.add_dependency(%q<bundler>, ["~> 1.2.3"])
|
58
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
59
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
60
|
+
s.add_dependency(%q<shoulda-context>, [">= 0"])
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
@@ -0,0 +1,135 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require "rexml/document"
|
3
|
+
|
4
|
+
class InteltechSms
|
5
|
+
|
6
|
+
class Error < StandardError
|
7
|
+
attr_reader :response
|
8
|
+
def initialize(response)
|
9
|
+
@response = response
|
10
|
+
super(response.to_s)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class Response
|
15
|
+
attr_reader :sms
|
16
|
+
attr_reader :response_code
|
17
|
+
|
18
|
+
def initialize(sms, response_code = '')
|
19
|
+
@sms = sms.strip
|
20
|
+
@response_code = response_code.strip
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.factory(sms, response_code)
|
24
|
+
case response_code.strip
|
25
|
+
when '0000'
|
26
|
+
Success.new(sms, response_code)
|
27
|
+
when '2006'
|
28
|
+
Unauthorized.new(sms, response_code)
|
29
|
+
when '2015'
|
30
|
+
BadRequest.new(sms, response_code)
|
31
|
+
when '2018'
|
32
|
+
NoCredit.new(sms, response_code)
|
33
|
+
when '2022'
|
34
|
+
Unauthorized.new(sms, response_code)
|
35
|
+
when '2051'
|
36
|
+
BadRequest.new(sms, response_code)
|
37
|
+
else
|
38
|
+
Failure.new(sms, response_code)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def ==(another)
|
43
|
+
self.sms == another.sms and self.response_code == another.response_code
|
44
|
+
end
|
45
|
+
|
46
|
+
def to_s
|
47
|
+
"#{self.class.name} sms: #{@sms}, response_code: #{@response_code}"
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
class Success < Response
|
53
|
+
def success?
|
54
|
+
true
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
class Failure < Response
|
59
|
+
def success?
|
60
|
+
false
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
class BadRequest < Failure
|
65
|
+
end
|
66
|
+
|
67
|
+
class Unauthorized < Failure
|
68
|
+
end
|
69
|
+
|
70
|
+
class NoCredit < Failure
|
71
|
+
end
|
72
|
+
|
73
|
+
# class InteltechSms
|
74
|
+
|
75
|
+
|
76
|
+
def initialize(username, secret_key)
|
77
|
+
@username = username
|
78
|
+
@secret_key = secret_key
|
79
|
+
end
|
80
|
+
|
81
|
+
def get_credit
|
82
|
+
uri = URI('http://inteltech.com.au/secure-api/credit.php')
|
83
|
+
res = Net::HTTP.post_form(uri, 'username' => @username, 'key' => @secret_key, 'method' => 'ruby')
|
84
|
+
case res
|
85
|
+
when Net::HTTPSuccess, Net::HTTPRedirection
|
86
|
+
if res.body =~ /credit,(\d*)/
|
87
|
+
$1.to_i
|
88
|
+
elsif res.body =~ /\d\d\d\d/
|
89
|
+
raise InteltechSms::Error.new(Response.factory('', res.body))
|
90
|
+
else
|
91
|
+
raise StandardError.new("Response not formatted as expected: #{res.body}")
|
92
|
+
end
|
93
|
+
else
|
94
|
+
res.error!
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def send_sms(sms, message, options = { })
|
99
|
+
uri = URI('http://inteltech.com.au/secure-api/send.single.php')
|
100
|
+
|
101
|
+
args = { :username => @username, :key => @secret_key, :sms => sms, :message => message, :method => 'ruby' }.merge(options)
|
102
|
+
res = Net::HTTP.post_form(uri, args)
|
103
|
+
case res
|
104
|
+
when Net::HTTPSuccess, Net::HTTPRedirection
|
105
|
+
r= Response.factory(sms, res.body)
|
106
|
+
raise InteltechSms::Error.new(r) unless r.success?
|
107
|
+
r
|
108
|
+
else
|
109
|
+
res.error!
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
def send_multiple_sms(sms, message, options = { })
|
114
|
+
uri = URI('http://inteltech.com.au/secure-api/send.php')
|
115
|
+
sms_string = sms.respond_to?(:join) ? sms.join(',') : sms.to_s
|
116
|
+
args = { :username => @username, :key => @secret_key, :sms => sms_string, :message => message, :method => 'ruby' }.merge(options)
|
117
|
+
res = Net::HTTP.post_form(uri, args)
|
118
|
+
case res
|
119
|
+
when Net::HTTPSuccess, Net::HTTPRedirection
|
120
|
+
doc = REXML::Document.new res.body
|
121
|
+
ret = [ ]
|
122
|
+
doc.elements.each("xml/message") do |element|
|
123
|
+
sms = element.elements['sms'].text.strip
|
124
|
+
response_code = element.elements['result'].text.strip
|
125
|
+
ret << Response.factory(sms, response_code)
|
126
|
+
end
|
127
|
+
ret
|
128
|
+
else
|
129
|
+
res.error!
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
end
|
134
|
+
|
135
|
+
# vi:ai sw=2:
|
data/test/helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'test/unit'
|
11
|
+
require 'shoulda-context'
|
12
|
+
|
13
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
14
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
15
|
+
require 'inteltech_sms'
|
16
|
+
|
17
|
+
class Test::Unit::TestCase
|
18
|
+
end
|
@@ -0,0 +1,277 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestInteltechSms < Test::Unit::TestCase
|
4
|
+
|
5
|
+
# ==================================================
|
6
|
+
# Useful constants
|
7
|
+
|
8
|
+
USERNAME_WITHOUT_CREDIT = 'nocredit'
|
9
|
+
SECURE_KEY_WITHOUT_CREDIT = 'e7e62e1826d6f9ac1dcc208963b58b8cdad9aa12b53'
|
10
|
+
|
11
|
+
BAD_SECURE_KEY = '00000000011111111122222222233333333334444444444445555555566666666'
|
12
|
+
|
13
|
+
TEST_SMS = '0411111111'
|
14
|
+
TEST_SMS2 = '+8611111111111'
|
15
|
+
BAD_SMS = '049999999'
|
16
|
+
|
17
|
+
LANDLINE_SMS = '0862252608' # InteltechSms's landline
|
18
|
+
|
19
|
+
if ENV['SMS_USERNAME'].to_s.empty? or ENV['SMS_KEY'].to_s.empty?
|
20
|
+
puts "Tests for non error conditions are disabled (missing SMS_USERNAME and SMS_KEY values for a valid account)"
|
21
|
+
else
|
22
|
+
@@username = ENV['SMS_USERNAME']
|
23
|
+
@@secure_key = ENV['SMS_KEY']
|
24
|
+
if ENV['MOBILE_NUMBER'].to_s.empty?
|
25
|
+
puts "If MOBILE_NUMBER is supplied, then a test sms will be sent (using one credit)"
|
26
|
+
else
|
27
|
+
@@mobile_number = ENV['MOBILE_NUMBER']
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
# ==================================================
|
32
|
+
# Tests
|
33
|
+
|
34
|
+
# Code 0000 Message added to queue OK.
|
35
|
+
|
36
|
+
if defined? @@username
|
37
|
+
|
38
|
+
context "with a good username and secure_key" do
|
39
|
+
|
40
|
+
setup do
|
41
|
+
@good_gateway = InteltechSms.new(@@username, @@secure_key)
|
42
|
+
end
|
43
|
+
|
44
|
+
should "get_credit should return non zero credit" do
|
45
|
+
assert_operator @good_gateway.get_credit, :>, 0
|
46
|
+
end
|
47
|
+
|
48
|
+
should "send a single test sms via send_sms" do
|
49
|
+
expected = InteltechSms::Success.new(TEST_SMS, "0000")
|
50
|
+
assert_equal expected, @good_gateway.send_sms(TEST_SMS,'Test from Ruby')
|
51
|
+
end
|
52
|
+
|
53
|
+
if defined? @@mobile_number
|
54
|
+
should "send a single real sms via send_sms" do
|
55
|
+
expected = InteltechSms::Success.new(@@mobile_number, "0000")
|
56
|
+
assert_equal expected, @good_gateway.send_sms(@@mobile_number,"Test sms from InteltechSms account #{@@username} - any replies will be emailed to account holder")
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
context "#send_multiple_sms" do
|
63
|
+
setup do
|
64
|
+
@good_gateway = InteltechSms.new(@@username, @@secure_key)
|
65
|
+
@res = @good_gateway.send_multiple_sms [TEST_SMS, TEST_SMS2],'Test from Ruby'
|
66
|
+
end
|
67
|
+
|
68
|
+
should "return an array with a response for each sms sent" do
|
69
|
+
assert_kind_of Array, @res
|
70
|
+
assert_equal 2, @res.length
|
71
|
+
assert_equal InteltechSms::Success.new(TEST_SMS, "0000"), @res[0], "send_multiple_sms returns success for 1st element"
|
72
|
+
assert_equal InteltechSms::Success.new(TEST_SMS2, "0000"), @res[1], "send_multiple_sms returns success for 2nd element"
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
# --------------------------------------------------
|
79
|
+
# Code 2006 Not enough information has been supplied for authentication. Please ensure that your Username and Unique Key are supplied in your request.
|
80
|
+
|
81
|
+
context "with blank username" do
|
82
|
+
setup do
|
83
|
+
@bad_gateway = InteltechSms.new('', @@secure_key)
|
84
|
+
end
|
85
|
+
|
86
|
+
should "raise an Unauthorized Error exception when get_credit is called" do
|
87
|
+
ex = assert_raises InteltechSms::Error do
|
88
|
+
@bad_gateway.get_credit
|
89
|
+
end
|
90
|
+
assert_equal InteltechSms::Unauthorized.new('', "2006"), ex.response
|
91
|
+
end
|
92
|
+
|
93
|
+
should "raise an Unauthorized Error exception when send_sms is called" do
|
94
|
+
ex = assert_raises InteltechSms::Error do
|
95
|
+
@bad_gateway.send_sms TEST_SMS, 'test'
|
96
|
+
end
|
97
|
+
assert_equal InteltechSms::Unauthorized.new(TEST_SMS, "2006"), ex.response
|
98
|
+
end
|
99
|
+
|
100
|
+
should "return an array Unauthorized responses when send_multiple_sms is called" do
|
101
|
+
@res = @bad_gateway.send_multiple_sms [TEST_SMS, TEST_SMS2], 'Test from Ruby'
|
102
|
+
assert_kind_of Array, @res
|
103
|
+
assert_equal 2, @res.length, "send_multiple_sms returns results for each sms sent"
|
104
|
+
assert_kind_of InteltechSms::Unauthorized, @res[0], "send_multiple_sms returns Unauthorized for 1st element"
|
105
|
+
assert_equal InteltechSms::Unauthorized.new(TEST_SMS, "2006"), @res[0]
|
106
|
+
assert_kind_of InteltechSms::Unauthorized, @res[1], "send_multiple_sms returns Unauthorized for 2nd element"
|
107
|
+
assert_equal InteltechSms::Unauthorized.new(TEST_SMS2, "2006"), @res[1]
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
111
|
+
|
112
|
+
# --------------------------------------------------
|
113
|
+
# Code 2015 The destination mobile number is invalid.
|
114
|
+
|
115
|
+
context "with a bad sms number" do
|
116
|
+
setup do
|
117
|
+
@good_gateway = InteltechSms.new(@@username, @@secure_key)
|
118
|
+
end
|
119
|
+
|
120
|
+
should "raise a BadRequest Error exception when send_sms is called" do
|
121
|
+
ex = assert_raises InteltechSms::Error do
|
122
|
+
@good_gateway.send_sms BAD_SMS, 'test'
|
123
|
+
end
|
124
|
+
assert_equal InteltechSms::BadRequest.new(BAD_SMS, "2015"), ex.response
|
125
|
+
end
|
126
|
+
|
127
|
+
should "return an array with BadRequest responses when send_multiple_sms is called with some bad numbers" do
|
128
|
+
@res = @good_gateway.send_multiple_sms [BAD_SMS, TEST_SMS, LANDLINE_SMS], 'Test from Ruby'
|
129
|
+
assert_kind_of Array, @res
|
130
|
+
assert_equal 3, @res.length, "send_multiple_sms returns results for each sms sent"
|
131
|
+
assert_kind_of InteltechSms::BadRequest, @res[0], "send_multiple_sms returns BadRequest for 1st element"
|
132
|
+
assert_equal InteltechSms::BadRequest.new(BAD_SMS, "2015"), @res[0]
|
133
|
+
assert_kind_of InteltechSms::Success, @res[1], "send_multiple_sms returns Success for 2nd element"
|
134
|
+
assert_equal InteltechSms::Success.new(TEST_SMS, "0000"), @res[1]
|
135
|
+
assert_kind_of InteltechSms::BadRequest, @res[2], "send_multiple_sms returns BadRequest for 2nd element"
|
136
|
+
assert_equal InteltechSms::BadRequest.new(LANDLINE_SMS, "2015"), @res[2]
|
137
|
+
end
|
138
|
+
|
139
|
+
end
|
140
|
+
|
141
|
+
# --------------------------------------------------
|
142
|
+
# Code 2018 You have reached the end of your message credits. You will need to purchase more messages.
|
143
|
+
|
144
|
+
context "With an account without credit" do
|
145
|
+
setup do
|
146
|
+
@nocredit_gateway = InteltechSms.new(USERNAME_WITHOUT_CREDIT, SECURE_KEY_WITHOUT_CREDIT)
|
147
|
+
end
|
148
|
+
|
149
|
+
should "have get_credit return zero credit" do
|
150
|
+
assert_equal 0, @nocredit_gateway.get_credit
|
151
|
+
end
|
152
|
+
|
153
|
+
should "raise an NoCredit Error exception when send_sms is called" do
|
154
|
+
ex = assert_raises InteltechSms::Error do
|
155
|
+
@nocredit_gateway.send_sms TEST_SMS, 'test'
|
156
|
+
end
|
157
|
+
assert_equal InteltechSms::NoCredit.new(TEST_SMS, "2018"), ex.response
|
158
|
+
end
|
159
|
+
|
160
|
+
should "return an array NoCredit responses when send_multiple_sms is called" do
|
161
|
+
@res = @nocredit_gateway.send_multiple_sms [TEST_SMS, TEST_SMS2], 'Test from Ruby'
|
162
|
+
assert_kind_of Array, @res
|
163
|
+
assert_equal 2, @res.length, "send_multiple_sms returns results for each sms sent"
|
164
|
+
assert_kind_of InteltechSms::NoCredit, @res[0], "send_multiple_sms returns NoCredit for 1st element"
|
165
|
+
assert_equal InteltechSms::NoCredit.new(TEST_SMS, "2018"), @res[0]
|
166
|
+
assert_kind_of InteltechSms::NoCredit, @res[1], "send_multiple_sms returns NoCredit for 2nd element"
|
167
|
+
assert_equal InteltechSms::NoCredit.new(TEST_SMS2, "2018"), @res[1]
|
168
|
+
end
|
169
|
+
|
170
|
+
end
|
171
|
+
|
172
|
+
# --------------------------------------------------
|
173
|
+
# Code 2022 Your Unique Key is incorrect. This may be caused by a recent password change.
|
174
|
+
|
175
|
+
context "With an incorrect secure_key" do
|
176
|
+
setup do
|
177
|
+
@bad_gateway = InteltechSms.new(@@username, BAD_SECURE_KEY)
|
178
|
+
end
|
179
|
+
|
180
|
+
should "raise an Unauthorized Error exception when get_credit is called" do
|
181
|
+
ex = assert_raises InteltechSms::Error do
|
182
|
+
@bad_gateway.get_credit
|
183
|
+
end
|
184
|
+
assert_equal InteltechSms::Unauthorized.new('', "2022"), ex.response
|
185
|
+
end
|
186
|
+
|
187
|
+
should "raise an Unauthorized Error exception when send_sms is called" do
|
188
|
+
ex = assert_raises InteltechSms::Error do
|
189
|
+
@bad_gateway.send_sms TEST_SMS, 'test'
|
190
|
+
end
|
191
|
+
assert_equal InteltechSms::Unauthorized.new(TEST_SMS, "2022"), ex.response
|
192
|
+
end
|
193
|
+
|
194
|
+
should "return an array Unauthorized responses when send_multiple_sms is called" do
|
195
|
+
@res = @bad_gateway.send_multiple_sms [TEST_SMS, TEST_SMS2], 'Test from Ruby'
|
196
|
+
assert_kind_of Array, @res
|
197
|
+
assert_equal 2, @res.length, "send_multiple_sms returns results for each sms sent"
|
198
|
+
assert_kind_of InteltechSms::Unauthorized, @res[0], "send_multiple_sms returns Unauthorized for 1st element"
|
199
|
+
assert_equal InteltechSms::Unauthorized.new(TEST_SMS, "2022"), @res[0]
|
200
|
+
assert_kind_of InteltechSms::Unauthorized, @res[1], "send_multiple_sms returns Unauthorized for 2nd element"
|
201
|
+
assert_equal InteltechSms::Unauthorized.new(TEST_SMS2, "2022"), @res[1]
|
202
|
+
end
|
203
|
+
|
204
|
+
end
|
205
|
+
|
206
|
+
context "with blank secure_key" do
|
207
|
+
setup do
|
208
|
+
@bad_gateway = InteltechSms.new(@@username, '')
|
209
|
+
end
|
210
|
+
|
211
|
+
should "raise an Unauthorized Error exception when get_credit is called" do
|
212
|
+
ex = assert_raises InteltechSms::Error do
|
213
|
+
@bad_gateway.get_credit
|
214
|
+
end
|
215
|
+
assert_equal InteltechSms::Unauthorized.new('', "2022"), ex.response
|
216
|
+
end
|
217
|
+
|
218
|
+
should "raise an Unauthorized Error exception when send_sms is called" do
|
219
|
+
ex = assert_raises InteltechSms::Error do
|
220
|
+
@bad_gateway.send_sms TEST_SMS, 'test'
|
221
|
+
end
|
222
|
+
assert_equal InteltechSms::Unauthorized.new(TEST_SMS, "2022"), ex.response
|
223
|
+
end
|
224
|
+
|
225
|
+
should "return an array Unauthorized responses when send_multiple_sms is called" do
|
226
|
+
@res = @bad_gateway.send_multiple_sms [TEST_SMS, TEST_SMS2], 'Test from Ruby'
|
227
|
+
assert_kind_of Array, @res
|
228
|
+
assert_equal 2, @res.length, "send_multiple_sms returns results for each sms sent"
|
229
|
+
assert_kind_of InteltechSms::Unauthorized, @res[0], "send_multiple_sms returns Unauthorized for 1st element"
|
230
|
+
assert_equal InteltechSms::Unauthorized.new(TEST_SMS, "2022"), @res[0]
|
231
|
+
assert_kind_of InteltechSms::Unauthorized, @res[1], "send_multiple_sms returns Unauthorized for 2nd element"
|
232
|
+
assert_equal InteltechSms::Unauthorized.new(TEST_SMS2, "2022"), @res[1]
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
236
|
+
# --------------------------------------------------
|
237
|
+
# Code 2051 Message is empty.
|
238
|
+
|
239
|
+
if defined? @@username
|
240
|
+
|
241
|
+
context "with an empty message" do
|
242
|
+
|
243
|
+
setup do
|
244
|
+
@good_gateway = InteltechSms.new(@@username, @@secure_key)
|
245
|
+
end
|
246
|
+
|
247
|
+
should "raise an BadRequest Error exception when send_sms is called" do
|
248
|
+
ex = assert_raises InteltechSms::Error do
|
249
|
+
@good_gateway.send_sms TEST_SMS, ''
|
250
|
+
end
|
251
|
+
assert_equal InteltechSms::BadRequest.new(TEST_SMS, "2051"), ex.response
|
252
|
+
end
|
253
|
+
|
254
|
+
should "return an array BadRequest responses when send_multiple_sms is called" do
|
255
|
+
@res = @good_gateway.send_multiple_sms [TEST_SMS, TEST_SMS2, LANDLINE_SMS], ''
|
256
|
+
assert_kind_of Array, @res
|
257
|
+
assert_equal 3, @res.length, "send_multiple_sms returns results for each sms sent"
|
258
|
+
assert_kind_of InteltechSms::BadRequest, @res[0], "send_multiple_sms returns BadRequest for 1st element"
|
259
|
+
assert_equal InteltechSms::BadRequest.new(TEST_SMS, "2051"), @res[0]
|
260
|
+
assert_kind_of InteltechSms::BadRequest, @res[1], "send_multiple_sms returns BadRequest for 2nd element"
|
261
|
+
assert_equal InteltechSms::BadRequest.new(TEST_SMS2, "2051"), @res[1]
|
262
|
+
assert_kind_of InteltechSms::BadRequest, @res[2], "send_multiple_sms returns BadRequest for 2nd element"
|
263
|
+
assert_equal InteltechSms::BadRequest.new(LANDLINE_SMS, "2051"), @res[2]
|
264
|
+
end
|
265
|
+
|
266
|
+
end
|
267
|
+
end
|
268
|
+
|
269
|
+
|
270
|
+
# --------------------------------------------------
|
271
|
+
# Code 2100-2199 Internal error
|
272
|
+
|
273
|
+
# (Unable to trigger these errors to test them)
|
274
|
+
|
275
|
+
end
|
276
|
+
|
277
|
+
# vi: sw=2 sm ai:
|
metadata
ADDED
@@ -0,0 +1,151 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: inteltech_sms
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Ian Heggie
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2013-01-22 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
22
|
+
none: false
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
hash: 31
|
27
|
+
segments:
|
28
|
+
- 3
|
29
|
+
- 12
|
30
|
+
version: "3.12"
|
31
|
+
version_requirements: *id001
|
32
|
+
name: rdoc
|
33
|
+
prerelease: false
|
34
|
+
type: :development
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
38
|
+
requirements:
|
39
|
+
- - ~>
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
hash: 25
|
42
|
+
segments:
|
43
|
+
- 1
|
44
|
+
- 2
|
45
|
+
- 3
|
46
|
+
version: 1.2.3
|
47
|
+
version_requirements: *id002
|
48
|
+
name: bundler
|
49
|
+
prerelease: false
|
50
|
+
type: :development
|
51
|
+
- !ruby/object:Gem::Dependency
|
52
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ~>
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
hash: 63
|
58
|
+
segments:
|
59
|
+
- 1
|
60
|
+
- 8
|
61
|
+
- 4
|
62
|
+
version: 1.8.4
|
63
|
+
version_requirements: *id003
|
64
|
+
name: jeweler
|
65
|
+
prerelease: false
|
66
|
+
type: :development
|
67
|
+
- !ruby/object:Gem::Dependency
|
68
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
69
|
+
none: false
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
hash: 3
|
74
|
+
segments:
|
75
|
+
- 0
|
76
|
+
version: "0"
|
77
|
+
version_requirements: *id004
|
78
|
+
name: rcov
|
79
|
+
prerelease: false
|
80
|
+
type: :development
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
hash: 3
|
88
|
+
segments:
|
89
|
+
- 0
|
90
|
+
version: "0"
|
91
|
+
version_requirements: *id005
|
92
|
+
name: shoulda-context
|
93
|
+
prerelease: false
|
94
|
+
type: :development
|
95
|
+
description: Ruby gem that provides an InteltechSms class to check credit and send SMS text messages to single or multiple recipients
|
96
|
+
email: ian@heggie.biz
|
97
|
+
executables: []
|
98
|
+
|
99
|
+
extensions: []
|
100
|
+
|
101
|
+
extra_rdoc_files:
|
102
|
+
- LICENSE.txt
|
103
|
+
- README.rdoc
|
104
|
+
files:
|
105
|
+
- .document
|
106
|
+
- .travis.yml
|
107
|
+
- Gemfile
|
108
|
+
- Gemfile.lock
|
109
|
+
- LICENSE.txt
|
110
|
+
- README.rdoc
|
111
|
+
- Rakefile
|
112
|
+
- VERSION
|
113
|
+
- inteltech_sms.gemspec
|
114
|
+
- lib/inteltech_sms.rb
|
115
|
+
- test/helper.rb
|
116
|
+
- test/test_inteltech_sms.rb
|
117
|
+
homepage: http://github.com/ianheggie/inteltech_sms
|
118
|
+
licenses:
|
119
|
+
- MIT
|
120
|
+
post_install_message:
|
121
|
+
rdoc_options: []
|
122
|
+
|
123
|
+
require_paths:
|
124
|
+
- lib
|
125
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
126
|
+
none: false
|
127
|
+
requirements:
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
hash: 3
|
131
|
+
segments:
|
132
|
+
- 0
|
133
|
+
version: "0"
|
134
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
135
|
+
none: false
|
136
|
+
requirements:
|
137
|
+
- - ">="
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
hash: 3
|
140
|
+
segments:
|
141
|
+
- 0
|
142
|
+
version: "0"
|
143
|
+
requirements: []
|
144
|
+
|
145
|
+
rubyforge_project:
|
146
|
+
rubygems_version: 1.8.24
|
147
|
+
signing_key:
|
148
|
+
specification_version: 3
|
149
|
+
summary: Ruby Gem to send SMS via inteltech.com.au
|
150
|
+
test_files: []
|
151
|
+
|