sms_xchange 0.1.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/Manifest +10 -0
- data/README.rdoc +52 -0
- data/Rakefile +77 -0
- data/config.yml +4 -0
- data/init.rb +2 -0
- data/lib/sms_xchange.rb +70 -0
- data/sms_xchange.gemspec +31 -0
- data/test/mocks/sms_xchange_mock.rb +16 -0
- data/test/test_helper.rb +3 -0
- data/test/unit/sms_xchange_test.rb +47 -0
- metadata +71 -0
data/Manifest
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
= SmsXchange
|
2
|
+
|
3
|
+
Send SMS messages via the SMS Xchange service.
|
4
|
+
|
5
|
+
|
6
|
+
== SMS Xchange Gateway
|
7
|
+
|
8
|
+
See http://www.smsxchange.com/
|
9
|
+
|
10
|
+
|
11
|
+
== Features
|
12
|
+
|
13
|
+
* So easy to use, even a baby (with an SMS Xchange account) could SMS his
|
14
|
+
baby pals.
|
15
|
+
* Tested under Ruby 1.8.7 and Ruby 1.9
|
16
|
+
|
17
|
+
== Example
|
18
|
+
|
19
|
+
require 'sms_xchange'
|
20
|
+
client = SmsExchange.new(:username => 'username', :password => 'password')
|
21
|
+
client.send("6599998888", "Hi, this is a test message")
|
22
|
+
|
23
|
+
|
24
|
+
== References
|
25
|
+
|
26
|
+
* http://www.smsxchange.com/main/sms_delivery.asp
|
27
|
+
|
28
|
+
|
29
|
+
== License
|
30
|
+
|
31
|
+
(The MIT License)
|
32
|
+
|
33
|
+
Copyright (c) 2009 Global IT Creations Pte Ltd http://www.globalitcreations.com
|
34
|
+
|
35
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
36
|
+
of this software and associated documentation files (the "Software"), to deal
|
37
|
+
in the Software without restriction, including without limitation the rights
|
38
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
39
|
+
copies of the Software, and to permit persons to whom the Software is
|
40
|
+
furnished to do so, subject to the following conditions:
|
41
|
+
|
42
|
+
The above copyright notice and this permission notice shall be included in
|
43
|
+
all copies or substantial portions of the Software.
|
44
|
+
|
45
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
46
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
47
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
48
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
49
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
50
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
51
|
+
THE SOFTWARE.
|
52
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'rake/testtask'
|
4
|
+
require 'echoe'
|
5
|
+
require 'yaml'
|
6
|
+
|
7
|
+
APP_NAME = "sms_xchange"
|
8
|
+
APP_URL = "http://github.com/scottbarr/sms_xchange"
|
9
|
+
APP_DESCRIPTION = "Ruby client for the smsxchange.com service."
|
10
|
+
AUTHOR_NAME = "Scott Barr"
|
11
|
+
AUTHOR_EMAIL = "scottb@globalitcreations.com"
|
12
|
+
|
13
|
+
#
|
14
|
+
# Create a version for this build from the config.yml and the BUILD_NUMBER
|
15
|
+
# environment variable.
|
16
|
+
#
|
17
|
+
def get_version
|
18
|
+
# read the config file
|
19
|
+
config = open("config.yml") {|f| YAML.load(f)}
|
20
|
+
|
21
|
+
# build the version number
|
22
|
+
version_major = config["version"]["major"]
|
23
|
+
version_minor = config["version"]["minor"]
|
24
|
+
version_build = ENV["BUILD_NUMBER"] || "0"
|
25
|
+
"#{version_major}.#{version_minor}.#{version_build}"
|
26
|
+
end
|
27
|
+
|
28
|
+
Rake::TestTask.new("test:units") { |t|
|
29
|
+
t.pattern = 'test/unit/*_test.rb'
|
30
|
+
t.verbose = true
|
31
|
+
t.warning = false
|
32
|
+
}
|
33
|
+
|
34
|
+
Rake::TestTask.new("test:integration") { |t|
|
35
|
+
t.pattern = 'test/integration/*_test.rb'
|
36
|
+
t.verbose = true
|
37
|
+
t.warning = false
|
38
|
+
}
|
39
|
+
|
40
|
+
# setup the gem
|
41
|
+
Echoe.new(APP_NAME, get_version) do |p|
|
42
|
+
p.description = APP_DESCRIPTION
|
43
|
+
p.url = APP_URL
|
44
|
+
p.author = AUTHOR_NAME
|
45
|
+
p.email = AUTHOR_EMAIL
|
46
|
+
p.ignore_pattern = ["tmp/*", "script/*"]
|
47
|
+
p.development_dependencies = []
|
48
|
+
end
|
49
|
+
|
50
|
+
task :publish => [:test, :clean, :manifest, :repackage, :upload]
|
51
|
+
|
52
|
+
task :upload do
|
53
|
+
version = get_version
|
54
|
+
|
55
|
+
retval = system "rsync -av pkg/#{APP_NAME}-#{version}.gem git.globalitcreations.com:/var/www/gems.globalitcreations.com/gems/"
|
56
|
+
Exception.new("rsync of gem failed") unless retval
|
57
|
+
|
58
|
+
retval = system "ssh git.globalitcreations.com 'cd /var/www/gems.globalitcreations.com/ ; gem generate_index'"
|
59
|
+
Exception.new("regenerating gem index failed") unless retval
|
60
|
+
end
|
61
|
+
|
62
|
+
# define a remove task method so the "test" task isn't breaking my stuff
|
63
|
+
Rake::TaskManager.class_eval do
|
64
|
+
def remove_task(task_name)
|
65
|
+
@tasks.delete(task_name.to_s)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
# helper method to remove a task
|
70
|
+
def remove_task(task_name)
|
71
|
+
Rake.application.remove_task(task_name)
|
72
|
+
end
|
73
|
+
|
74
|
+
# remove the original test task
|
75
|
+
remove_task :test
|
76
|
+
|
77
|
+
task :test => ["test:units", "test:integration"]
|
data/config.yml
ADDED
data/init.rb
ADDED
data/lib/sms_xchange.rb
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'net/https'
|
3
|
+
require 'cgi'
|
4
|
+
|
5
|
+
class SmsXchange
|
6
|
+
|
7
|
+
OK = "01"
|
8
|
+
|
9
|
+
ERRORS = {
|
10
|
+
"02" => "No Such User",
|
11
|
+
"03" => "Password is wrong",
|
12
|
+
"04" => "Domain Name of server is wrong",
|
13
|
+
"05" => "Message not sent. Undocumented error.",
|
14
|
+
"06" => "Phone Number is empty.",
|
15
|
+
"07" => "SMS parameter missing. No message to send.",
|
16
|
+
"09" => "Insufficient SMS Credits."
|
17
|
+
}
|
18
|
+
|
19
|
+
SERVER = "https://www.smsxchange.com"
|
20
|
+
URL = "/scripts/sendsms.asp"
|
21
|
+
PARAMS = "userid=%s&password=%s&phone=%s&sms=%s"
|
22
|
+
|
23
|
+
attr_reader :username, :password, :server
|
24
|
+
|
25
|
+
def initialize(opts)
|
26
|
+
@server = opts[:server] || SERVER
|
27
|
+
@username = opts[:username]
|
28
|
+
@password = opts[:password]
|
29
|
+
end
|
30
|
+
|
31
|
+
#
|
32
|
+
# Get the data to send to the service
|
33
|
+
#
|
34
|
+
def get_data(phone, message, test = false)
|
35
|
+
sprintf(PARAMS, @username, @password, CGI.escape(phone), CGI.escape(message))
|
36
|
+
end
|
37
|
+
|
38
|
+
#
|
39
|
+
#
|
40
|
+
# Get the url for the service
|
41
|
+
def get_url
|
42
|
+
URI.parse("#{@server}#{URL}")
|
43
|
+
end
|
44
|
+
|
45
|
+
def get_error_message(code)
|
46
|
+
sprintf "Gateway application response code %s - %s", code, ERRORS[code] || "Unknown error code"
|
47
|
+
end
|
48
|
+
|
49
|
+
#
|
50
|
+
# Send an sms message
|
51
|
+
#
|
52
|
+
def send(phone, message)
|
53
|
+
url = get_url
|
54
|
+
url.query = get_data(phone, message, test)
|
55
|
+
|
56
|
+
https = Net::HTTP.new(url.host, url.port)
|
57
|
+
https.use_ssl = (url.scheme == 'https')
|
58
|
+
|
59
|
+
res = https.get(url.request_uri)
|
60
|
+
|
61
|
+
if res.code.to_i != 200
|
62
|
+
raise Exception.new("Server responded with HTTP " + res.code)
|
63
|
+
end
|
64
|
+
|
65
|
+
if res.body != OK
|
66
|
+
raise Exception.new(get_error_message(res.body))
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
data/sms_xchange.gemspec
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{sms_xchange}
|
5
|
+
s.version = "0.1.0"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Scott Barr"]
|
9
|
+
s.date = %q{2009-12-07}
|
10
|
+
s.description = %q{Ruby client for the smsxchange.com service.}
|
11
|
+
s.email = %q{scottb@globalitcreations.com}
|
12
|
+
s.extra_rdoc_files = ["lib/sms_xchange.rb", "README.rdoc"]
|
13
|
+
s.files = ["config.yml", "init.rb", "lib/sms_xchange.rb", "Manifest", "Rakefile", "README.rdoc", "sms_xchange.gemspec", "test/mocks/sms_xchange_mock.rb", "test/test_helper.rb", "test/unit/sms_xchange_test.rb"]
|
14
|
+
s.homepage = %q{http://github.com/scottbarr/sms_xchange}
|
15
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Sms_xchange", "--main", "README.rdoc"]
|
16
|
+
s.require_paths = ["lib"]
|
17
|
+
s.rubyforge_project = %q{sms_xchange}
|
18
|
+
s.rubygems_version = %q{1.3.5}
|
19
|
+
s.summary = %q{Ruby client for the smsxchange.com service.}
|
20
|
+
s.test_files = ["test/test_helper.rb", "test/unit/sms_xchange_test.rb"]
|
21
|
+
|
22
|
+
if s.respond_to? :specification_version then
|
23
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
24
|
+
s.specification_version = 3
|
25
|
+
|
26
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
27
|
+
else
|
28
|
+
end
|
29
|
+
else
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
#
|
2
|
+
# A mock of the SmsXchange class
|
3
|
+
#
|
4
|
+
|
5
|
+
# require the real class
|
6
|
+
require 'lib/sms_xchange'
|
7
|
+
|
8
|
+
# reopen and override the class
|
9
|
+
class SmsXchange
|
10
|
+
|
11
|
+
def send(phone, message)
|
12
|
+
# raise an Exception = "Message not sent. Undocumented error."
|
13
|
+
raise Exception.new(get_error_message("05"))
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'test/test_helper'
|
2
|
+
|
3
|
+
# unit test will be working against the mock
|
4
|
+
require 'test/mocks/sms_xchange_mock'
|
5
|
+
|
6
|
+
class SmsXchangeTest < Test::Unit::TestCase
|
7
|
+
|
8
|
+
def setup
|
9
|
+
@client = SmsXchange.new(:username => "scott", :password => "pass1")
|
10
|
+
@phone = "6597528429"
|
11
|
+
@message = "Test message"
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_default_server
|
15
|
+
assert_equal SmsXchange::SERVER, @client.server
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_get_url
|
19
|
+
url = @client.get_url()
|
20
|
+
|
21
|
+
assert_equal "https", url.scheme
|
22
|
+
assert_equal "www.smsxchange.com", url.host
|
23
|
+
assert_equal "/scripts/sendsms.asp", url.path
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_get_data
|
27
|
+
expected = "userid=scott&password=pass1&phone=6597528429&sms=Test+message"
|
28
|
+
assert_equal expected, @client.get_data(@phone, @message)
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_authentication_details
|
32
|
+
assert_equal "scott", @client.username
|
33
|
+
assert_equal "pass1", @client.password
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_send
|
37
|
+
assert_raise Exception do
|
38
|
+
@client.send("6597529999", "This is a test message")
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_get_error_message
|
43
|
+
expected = "Gateway application response code 02 - No Such User"
|
44
|
+
assert_equal expected, @client.get_error_message("02")
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
metadata
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sms_xchange
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Scott Barr
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-12-07 00:00:00 +08:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Ruby client for the smsxchange.com service.
|
17
|
+
email: scottb@globalitcreations.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- lib/sms_xchange.rb
|
24
|
+
- README.rdoc
|
25
|
+
files:
|
26
|
+
- config.yml
|
27
|
+
- init.rb
|
28
|
+
- lib/sms_xchange.rb
|
29
|
+
- Manifest
|
30
|
+
- Rakefile
|
31
|
+
- README.rdoc
|
32
|
+
- sms_xchange.gemspec
|
33
|
+
- test/mocks/sms_xchange_mock.rb
|
34
|
+
- test/test_helper.rb
|
35
|
+
- test/unit/sms_xchange_test.rb
|
36
|
+
has_rdoc: true
|
37
|
+
homepage: http://github.com/scottbarr/sms_xchange
|
38
|
+
licenses: []
|
39
|
+
|
40
|
+
post_install_message:
|
41
|
+
rdoc_options:
|
42
|
+
- --line-numbers
|
43
|
+
- --inline-source
|
44
|
+
- --title
|
45
|
+
- Sms_xchange
|
46
|
+
- --main
|
47
|
+
- README.rdoc
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: "0"
|
55
|
+
version:
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: "1.2"
|
61
|
+
version:
|
62
|
+
requirements: []
|
63
|
+
|
64
|
+
rubyforge_project: sms_xchange
|
65
|
+
rubygems_version: 1.3.5
|
66
|
+
signing_key:
|
67
|
+
specification_version: 3
|
68
|
+
summary: Ruby client for the smsxchange.com service.
|
69
|
+
test_files:
|
70
|
+
- test/test_helper.rb
|
71
|
+
- test/unit/sms_xchange_test.rb
|