aql_sms_api 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/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.md +39 -0
- data/Rakefile +54 -0
- data/VERSION +1 -0
- data/aql_sms_api.gemspec +57 -0
- data/lib/aql_sms_api.rb +63 -0
- data/test/helper.rb +10 -0
- data/test/test_aql_sms_api.rb +7 -0
- metadata +98 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 Aaron Russell
|
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.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# AQL SMS API
|
2
|
+
|
3
|
+
A ruby wrapper for the AQL SMS API. I am building this for use in a specific project, nothing more. If you feel it can be enhanced and devloped then please feel free to fork away.
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
#### Authentication
|
8
|
+
|
9
|
+
# @params username, password [, originator]
|
10
|
+
#
|
11
|
+
AQL::SMS.authenticate "username", "password"
|
12
|
+
|
13
|
+
#### Check credit
|
14
|
+
|
15
|
+
# @return integer number of credits
|
16
|
+
#
|
17
|
+
AQL::SMS.check_credit
|
18
|
+
|
19
|
+
#### Send message
|
20
|
+
|
21
|
+
# @params desitnation, message [, options]
|
22
|
+
# destination can be single number string or array of multiple numbers
|
23
|
+
# options can be hash of :originator, :max_concat, :sendtime, :unix_sendtime, :replace_sms, :flash, :dlr_url
|
24
|
+
#
|
25
|
+
AQL::SMS.send_message "07777 777 777", "R U coming rnd 2 mine 2nite?"
|
26
|
+
|
27
|
+
## Note on Patches/Pull Requests
|
28
|
+
|
29
|
+
* Fork the project.
|
30
|
+
* Make your feature addition or bug fix.
|
31
|
+
* Add tests for it. This is important so I don't break it in a
|
32
|
+
future version unintentionally.
|
33
|
+
* Commit, do not mess with rakefile, version, or history.
|
34
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
35
|
+
* Send me a pull request. Bonus points for topic branches.
|
36
|
+
|
37
|
+
## Copyright
|
38
|
+
|
39
|
+
Copyright (c) 2010 Aaron Russell. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "aql_sms_api"
|
8
|
+
gem.summary = %Q{A ruby wrapper for the AQL SMS API.}
|
9
|
+
gem.description = %Q{A ruby wrapper for the AQL SMS API.}
|
10
|
+
gem.email = "aaron@gc4.co.uk"
|
11
|
+
gem.homepage = "http://github.com/aaronrussell/aql_sms_api"
|
12
|
+
gem.authors = ["Aaron Russell"]
|
13
|
+
gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
|
14
|
+
gem.add_dependency "httparty", ">= 0.5.2"
|
15
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
16
|
+
end
|
17
|
+
Jeweler::GemcutterTasks.new
|
18
|
+
rescue LoadError
|
19
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
20
|
+
end
|
21
|
+
|
22
|
+
require 'rake/testtask'
|
23
|
+
Rake::TestTask.new(:test) do |test|
|
24
|
+
test.libs << 'lib' << 'test'
|
25
|
+
test.pattern = 'test/**/test_*.rb'
|
26
|
+
test.verbose = true
|
27
|
+
end
|
28
|
+
|
29
|
+
begin
|
30
|
+
require 'rcov/rcovtask'
|
31
|
+
Rcov::RcovTask.new do |test|
|
32
|
+
test.libs << 'test'
|
33
|
+
test.pattern = 'test/**/test_*.rb'
|
34
|
+
test.verbose = true
|
35
|
+
end
|
36
|
+
rescue LoadError
|
37
|
+
task :rcov do
|
38
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
task :test => :check_dependencies
|
43
|
+
|
44
|
+
task :default => :test
|
45
|
+
|
46
|
+
require 'rake/rdoctask'
|
47
|
+
Rake::RDocTask.new do |rdoc|
|
48
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
49
|
+
|
50
|
+
rdoc.rdoc_dir = 'rdoc'
|
51
|
+
rdoc.title = "aql_sms_api #{version}"
|
52
|
+
rdoc.rdoc_files.include('README*')
|
53
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
54
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/aql_sms_api.gemspec
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{aql_sms_api}
|
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 = ["Aaron Russell"]
|
12
|
+
s.date = %q{2010-05-28}
|
13
|
+
s.description = %q{A ruby wrapper for the AQL SMS API.}
|
14
|
+
s.email = %q{aaron@gc4.co.uk}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.md"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
"LICENSE",
|
23
|
+
"README.md",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"aql_sms_api.gemspec",
|
27
|
+
"lib/aql_sms_api.rb",
|
28
|
+
"test/helper.rb",
|
29
|
+
"test/test_aql_sms_api.rb"
|
30
|
+
]
|
31
|
+
s.homepage = %q{http://github.com/aaronrussell/aql_sms_api}
|
32
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
33
|
+
s.require_paths = ["lib"]
|
34
|
+
s.rubygems_version = %q{1.3.6}
|
35
|
+
s.summary = %q{A ruby wrapper for the AQL SMS API.}
|
36
|
+
s.test_files = [
|
37
|
+
"test/helper.rb",
|
38
|
+
"test/test_aql_sms_api.rb"
|
39
|
+
]
|
40
|
+
|
41
|
+
if s.respond_to? :specification_version then
|
42
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
43
|
+
s.specification_version = 3
|
44
|
+
|
45
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
46
|
+
s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
47
|
+
s.add_runtime_dependency(%q<httparty>, [">= 0.5.2"])
|
48
|
+
else
|
49
|
+
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
50
|
+
s.add_dependency(%q<httparty>, [">= 0.5.2"])
|
51
|
+
end
|
52
|
+
else
|
53
|
+
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
54
|
+
s.add_dependency(%q<httparty>, [">= 0.5.2"])
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
data/lib/aql_sms_api.rb
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
|
3
|
+
module AQL
|
4
|
+
|
5
|
+
class SMS
|
6
|
+
|
7
|
+
include HTTParty
|
8
|
+
base_uri "https://gw.aql.com/sms/"
|
9
|
+
|
10
|
+
def self.authenticate(user = nil, pass = nil, orig = nil)
|
11
|
+
@auth = {:username => user, :password => pass, :originator => orig}
|
12
|
+
end
|
13
|
+
|
14
|
+
authenticate
|
15
|
+
|
16
|
+
def self.check_credit
|
17
|
+
res = get "/postmsg.php", :query => @auth.merge(:cmd => "credit")
|
18
|
+
valid?(res) ? (res == "AQSMS-AUTHERROR" ? false : res.match(/\=(\d+)/)[1]).to_i : res
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.send_message(dests = [], msg = "", opts = {})
|
22
|
+
numbers = dests.collect{|n| format_number(n)}.join(",")
|
23
|
+
res = get "/sms_gw.php", :query => @auth.merge(:destination => numbers, :message => msg).merge(opts)
|
24
|
+
valid?(res) ? SMSResponse.new(res) : res
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.format_number(number, format = :uk)
|
28
|
+
NumberFormat.send(format, number)
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def self.valid?(res)
|
34
|
+
res.code == 200
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
class SMSResponse
|
40
|
+
|
41
|
+
attr_reader :code, :credits, :message
|
42
|
+
|
43
|
+
def initialize(res)
|
44
|
+
parts = res.match(/^([0-9]):(\d+)\s(.+)$/)
|
45
|
+
@code = parts[1]
|
46
|
+
@credits = parts[2]
|
47
|
+
@message = parts[3].strip
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
module NumberFormat
|
53
|
+
|
54
|
+
def self.uk(number)
|
55
|
+
number.
|
56
|
+
gsub(/\D/, ""). # removes all non digit characters
|
57
|
+
gsub(/^00([1-9]{2})/, "\\1"). # asumes numbers beginning 00 are int and strips leading 00
|
58
|
+
gsub(/^0([1-9])/, "44\\1") # removes leading 0 and add international code
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
data/test/helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: aql_sms_api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
version: 0.1.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Aaron Russell
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-05-28 00:00:00 +01:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: thoughtbot-shoulda
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
version: "0"
|
30
|
+
type: :development
|
31
|
+
version_requirements: *id001
|
32
|
+
- !ruby/object:Gem::Dependency
|
33
|
+
name: httparty
|
34
|
+
prerelease: false
|
35
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
segments:
|
40
|
+
- 0
|
41
|
+
- 5
|
42
|
+
- 2
|
43
|
+
version: 0.5.2
|
44
|
+
type: :runtime
|
45
|
+
version_requirements: *id002
|
46
|
+
description: A ruby wrapper for the AQL SMS API.
|
47
|
+
email: aaron@gc4.co.uk
|
48
|
+
executables: []
|
49
|
+
|
50
|
+
extensions: []
|
51
|
+
|
52
|
+
extra_rdoc_files:
|
53
|
+
- LICENSE
|
54
|
+
- README.md
|
55
|
+
files:
|
56
|
+
- .document
|
57
|
+
- .gitignore
|
58
|
+
- LICENSE
|
59
|
+
- README.md
|
60
|
+
- Rakefile
|
61
|
+
- VERSION
|
62
|
+
- aql_sms_api.gemspec
|
63
|
+
- lib/aql_sms_api.rb
|
64
|
+
- test/helper.rb
|
65
|
+
- test/test_aql_sms_api.rb
|
66
|
+
has_rdoc: true
|
67
|
+
homepage: http://github.com/aaronrussell/aql_sms_api
|
68
|
+
licenses: []
|
69
|
+
|
70
|
+
post_install_message:
|
71
|
+
rdoc_options:
|
72
|
+
- --charset=UTF-8
|
73
|
+
require_paths:
|
74
|
+
- lib
|
75
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
segments:
|
80
|
+
- 0
|
81
|
+
version: "0"
|
82
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
segments:
|
87
|
+
- 0
|
88
|
+
version: "0"
|
89
|
+
requirements: []
|
90
|
+
|
91
|
+
rubyforge_project:
|
92
|
+
rubygems_version: 1.3.6
|
93
|
+
signing_key:
|
94
|
+
specification_version: 3
|
95
|
+
summary: A ruby wrapper for the AQL SMS API.
|
96
|
+
test_files:
|
97
|
+
- test/helper.rb
|
98
|
+
- test/test_aql_sms_api.rb
|