truesenses 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +22 -0
- data/LICENSE +20 -0
- data/README.rdoc +17 -0
- data/Rakefile +54 -0
- data/VERSION +1 -0
- data/lib/truesenses.rb +6 -0
- data/lib/truesenses/config.rb +25 -0
- data/lib/truesenses/hash.rb +10 -0
- data/lib/truesenses/sms_gateway.rb +63 -0
- data/lib/truesenses/sms_gateway_error.rb +9 -0
- data/test/helper.rb +10 -0
- data/test/test_truesenses.rb +7 -0
- metadata +96 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 pascalbetz
|
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,17 @@
|
|
1
|
+
= truesenses
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Note on Patches/Pull Requests
|
6
|
+
|
7
|
+
* Fork the project.
|
8
|
+
* Make your feature addition or bug fix.
|
9
|
+
* Add tests for it. This is important so I don't break it in a
|
10
|
+
future version unintentionally.
|
11
|
+
* Commit, do not mess with rakefile, version, or history.
|
12
|
+
(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)
|
13
|
+
* Send me a pull request. Bonus points for topic branches.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2010 pascalbetz. 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 = "truesenses"
|
8
|
+
gem.summary = %Q{implementation of the http api for truesenses.com SMS gateway}
|
9
|
+
gem.description = %Q{implementation of the http/https api for truesenses.com SMS gateway}
|
10
|
+
gem.email = "info@simplificator.com"
|
11
|
+
gem.homepage = "http://github.com/simplificator/truesenses"
|
12
|
+
gem.authors = ["pascalbetz"]
|
13
|
+
gem.add_dependency 'httparty', '>=0.6.1'
|
14
|
+
#gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
|
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 = "truesenses #{version}"
|
52
|
+
rdoc.rdoc_files.include('README*')
|
53
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
54
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.0
|
data/lib/truesenses.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
module Truesenses
|
2
|
+
class Config
|
3
|
+
attr_reader :password, :username, :protocol
|
4
|
+
def initialize(options)
|
5
|
+
options = options.stringify_keys
|
6
|
+
@password = options['password']
|
7
|
+
@username = options['username']
|
8
|
+
@protocol = options['protocol'] || :http
|
9
|
+
verify!
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.load(filename, root = nil)
|
13
|
+
data = YAML.load_file(filename)
|
14
|
+
Config.new(root ? data[root] : data)
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
private
|
19
|
+
def verify!
|
20
|
+
raise ArgumentError.new('Please specify a password with password option') if self.password.nil?
|
21
|
+
raise ArgumentError.new('Please specify a username with username option') if self.username.nil?
|
22
|
+
raise ArgumentError.new('protocol must either of :http or :https') unless [:https, :http].include?(self.protocol)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module Truesenses
|
2
|
+
class SMSGateway
|
3
|
+
RESPONSE_FORMAT = /(\d{2}) (.*)/
|
4
|
+
SUCCESS = 1
|
5
|
+
HTTP_BASE = 'http://www.truesenses.com/cgi-bin/smsgateway.cgi'
|
6
|
+
HTTPS_BASE = 'https://secure.simmcomm.ch/cgi-bin/smsgateway.cgi'
|
7
|
+
include HTTParty
|
8
|
+
|
9
|
+
attr_reader :config
|
10
|
+
def initialize(config)
|
11
|
+
@config = config
|
12
|
+
end
|
13
|
+
|
14
|
+
def credits_left
|
15
|
+
raise "not yet implemented"
|
16
|
+
post_request({'CMD' => 'CHECKCREDITS'})
|
17
|
+
end
|
18
|
+
|
19
|
+
def send_text_message(message, receipient)
|
20
|
+
get_request({
|
21
|
+
'CMD' => 'SENDMESSAGE',
|
22
|
+
'NUMBER' => receipient,
|
23
|
+
'MESSAGE' => message
|
24
|
+
})
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def get_request(options = {})
|
33
|
+
parse_response!(SMSGateway.get(base_url, :query => options.merge(default_options)))
|
34
|
+
end
|
35
|
+
|
36
|
+
def post_request(options = {})
|
37
|
+
parse_response!(SMSGateway.post(base_url, :query => options.merge(default_options)))
|
38
|
+
end
|
39
|
+
|
40
|
+
def parse_response!(response)
|
41
|
+
parsed = RESPONSE_FORMAT.match(response)
|
42
|
+
code, message = parsed[1].to_i, parsed[2]
|
43
|
+
if code == SUCCESS
|
44
|
+
message
|
45
|
+
else
|
46
|
+
raise SMSGatewayError.new(code, message)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
def default_options
|
52
|
+
default_options = {
|
53
|
+
'ACCOUNT' => self.config.username,
|
54
|
+
'PASSWORD' => self.config.password
|
55
|
+
}
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
def base_url
|
60
|
+
self.config.protocol == :http ? HTTP_BASE : HTTPS_BASE
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
data/test/helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: truesenses
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 31
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 0
|
10
|
+
version: 0.0.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- pascalbetz
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-09-05 00:00:00 +02:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: httparty
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 5
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
- 6
|
33
|
+
- 1
|
34
|
+
version: 0.6.1
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
description: implementation of the http/https api for truesenses.com SMS gateway
|
38
|
+
email: info@simplificator.com
|
39
|
+
executables: []
|
40
|
+
|
41
|
+
extensions: []
|
42
|
+
|
43
|
+
extra_rdoc_files:
|
44
|
+
- LICENSE
|
45
|
+
- README.rdoc
|
46
|
+
files:
|
47
|
+
- .document
|
48
|
+
- .gitignore
|
49
|
+
- LICENSE
|
50
|
+
- README.rdoc
|
51
|
+
- Rakefile
|
52
|
+
- VERSION
|
53
|
+
- lib/truesenses.rb
|
54
|
+
- lib/truesenses/config.rb
|
55
|
+
- lib/truesenses/hash.rb
|
56
|
+
- lib/truesenses/sms_gateway.rb
|
57
|
+
- lib/truesenses/sms_gateway_error.rb
|
58
|
+
- test/helper.rb
|
59
|
+
- test/test_truesenses.rb
|
60
|
+
has_rdoc: true
|
61
|
+
homepage: http://github.com/simplificator/truesenses
|
62
|
+
licenses: []
|
63
|
+
|
64
|
+
post_install_message:
|
65
|
+
rdoc_options:
|
66
|
+
- --charset=UTF-8
|
67
|
+
require_paths:
|
68
|
+
- lib
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
hash: 3
|
75
|
+
segments:
|
76
|
+
- 0
|
77
|
+
version: "0"
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
+
none: false
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
hash: 3
|
84
|
+
segments:
|
85
|
+
- 0
|
86
|
+
version: "0"
|
87
|
+
requirements: []
|
88
|
+
|
89
|
+
rubyforge_project:
|
90
|
+
rubygems_version: 1.3.7
|
91
|
+
signing_key:
|
92
|
+
specification_version: 3
|
93
|
+
summary: implementation of the http api for truesenses.com SMS gateway
|
94
|
+
test_files:
|
95
|
+
- test/helper.rb
|
96
|
+
- test/test_truesenses.rb
|