craigp-smartcall 0.0.1

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/.DS_Store ADDED
Binary file
data/README.rdoc ADDED
@@ -0,0 +1,28 @@
1
+ == Installation
2
+
3
+ sudo gem install craigp-smartcall
4
+
5
+ == License
6
+
7
+ (The MIT License)
8
+
9
+ Copyright (c) 2009 Armand du Plessis
10
+
11
+ Permission is hereby granted, free of charge, to any person obtaining
12
+ a copy of this software and associated documentation files (the
13
+ 'Software'), to deal in the Software without restriction, including
14
+ without limitation the rights to use, copy, modify, merge, publish,
15
+ distribute, sublicense, and/or sell copies of the Software, and to
16
+ permit persons to whom the Software is furnished to do so, subject to
17
+ the following conditions:
18
+
19
+ The above copyright notice and this permission notice shall be
20
+ included in all copies or substantial portions of the Software.
21
+
22
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
23
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
25
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
26
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
27
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
28
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.txt ADDED
@@ -0,0 +1,44 @@
1
+ = smartcall sms gem
2
+
3
+ * http://github.com/agilisto/smartcall
4
+
5
+ == DESCRIPTION:
6
+
7
+ Gem to provide sms functionality through the Smartcall Technology Solutions web services. Contact http://www.smartcalltech.co.za for an account.
8
+
9
+ == FEATURES/PROBLEMS:
10
+
11
+ == SYNOPSIS:
12
+ From code:
13
+
14
+ require 'smartcall'
15
+
16
+ api = Smartcall::API.new(<USERNAME>, <PASSWORD>, <CAMPAIGN_ID>, <REFERENCE>)
17
+
18
+ api.send_message("0825559629", "Hello World")
19
+
20
+ You can also specify the parameters in a ~/.smartcall file:
21
+
22
+ # ~/.smartcall
23
+
24
+ username: <username>
25
+
26
+ password: <password>
27
+
28
+ campaign_id: <campaign_id>
29
+
30
+ reference: <reference>
31
+
32
+
33
+ == COMMAND LINE ==
34
+
35
+ Once the gem is installed text messages can be sent from the command line:
36
+
37
+ smartcall 0825559629 "Hello World"
38
+
39
+ == REQUIREMENTS:
40
+
41
+
42
+ == INSTALL:
43
+
44
+ sudo gem install agilisto-smartcall
data/Rakefile ADDED
@@ -0,0 +1,64 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "craigp-smartcall"
8
+ gem.summary = %Q{Gem to provide SMS functionality through the Smartcall}
9
+ gem.description = <<-DESC
10
+ Gem to provide SMS functionality through the Smartcall Technology Solutions web
11
+ services. Contact http://www.smartcalltech.co.za for an account. This gem is based
12
+ on the smartcall gem written by Armand du Plessis (adp@bank.io)
13
+ DESC
14
+ gem.email = "darksavant@gmail.com"
15
+ gem.homepage = "http://github.com/craigp/smartcall"
16
+ gem.authors = ["Craig Paterson"]
17
+ gem.add_development_dependency "shoulda", ">= 2.11.1"
18
+ gem.files.exclude 'example/**/*'
19
+ gem.test_files.exclude 'example/**/*'
20
+ # gem.has_rdoc = true
21
+ # gem.rubyforge_project = 'djinn'
22
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
23
+ end
24
+ Jeweler::GemcutterTasks.new
25
+ # Jeweler::RubyforgeTasks.new do |rubyforge|
26
+ # rubyforge.doc_task = "rdoc"
27
+ # end
28
+ rescue LoadError
29
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
30
+ end
31
+
32
+ require 'rake/testtask'
33
+ Rake::TestTask.new(:test) do |test|
34
+ test.libs << 'lib' << 'test'
35
+ test.pattern = 'test/**/test_*.rb'
36
+ test.verbose = true
37
+ end
38
+
39
+ begin
40
+ require 'rcov/rcovtask'
41
+ Rcov::RcovTask.new do |test|
42
+ test.libs << 'test'
43
+ test.pattern = 'test/**/test_*.rb'
44
+ test.verbose = true
45
+ end
46
+ rescue LoadError
47
+ task :rcov do
48
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
49
+ end
50
+ end
51
+
52
+ task :test => :check_dependencies
53
+
54
+ task :default => :test
55
+
56
+ require 'rake/rdoctask'
57
+ Rake::RDocTask.new do |rdoc|
58
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
59
+
60
+ rdoc.rdoc_dir = 'rdoc'
61
+ rdoc.title = "djinn #{version}"
62
+ rdoc.rdoc_files.include('README*')
63
+ rdoc.rdoc_files.include('lib/**/*.rb')
64
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
data/bin/smartcall ADDED
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ local_libs = [
4
+ File.join(File.dirname(__FILE__), *%w[../lib/smartcall]),
5
+ File.join(File.dirname(__FILE__), *%w[../lib/smartcall/utility])
6
+ ]
7
+
8
+ if File.exist?(local_libs.first)
9
+ local_libs.each { |lib| require lib }
10
+ else
11
+ require 'rubygems'
12
+ require 'smartcall'
13
+ require 'smartcall/utility'
14
+ end
15
+
16
+ # parse command line options
17
+ options = Smartcall::Utility::Options.parse(ARGV)
18
+
19
+ # authenticate and load the API
20
+ api = Smartcall::API.new(options.username, options.password, options.campaign_id, options.reference)
21
+
22
+ begin
23
+ puts "Sending '#{options.message}' to #{options.recipient}..."
24
+ additional_opts = {}
25
+ additional_opts[:from] = options.from if options.from
26
+ msg_id = api.send_message(options.recipient, options.message, additional_opts)
27
+ puts "Message sent successfully (Result: #{msg_id})." unless msg_id == false
28
+ puts "Message sending failed. Switch to debug for more info" if msg_id == false
29
+ exit 0
30
+ rescue Smartcall::Soap::SmartcallError => e
31
+ puts "Unexpected error occurred. #{e.message}"
32
+ exit 1
33
+
34
+ rescue Timeout::Error
35
+ puts "The connection the the Smartcall service timed out"
36
+ puts "Please check your network settings and try again."
37
+ exit 1
38
+ end
@@ -0,0 +1,2 @@
1
+ host: unknown@rubyforge.org
2
+ remote_dir: /var/www/gforge-projects/smartcall
@@ -0,0 +1,64 @@
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 = %q{craigp-smartcall}
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Craig Paterson"]
12
+ s.date = %q{2011-02-09}
13
+ s.default_executable = %q{smartcall}
14
+ s.description = %q{Gem to provide SMS functionality through the Smartcall Technology Solutions web
15
+ services. Contact http://www.smartcalltech.co.za for an account. This gem is based
16
+ on the smartcall gem written by Armand du Plessis (adp@bank.io)
17
+ }
18
+ s.email = %q{darksavant@gmail.com}
19
+ s.executables = ["smartcall"]
20
+ s.extra_rdoc_files = [
21
+ "README.rdoc",
22
+ "README.txt"
23
+ ]
24
+ s.files = [
25
+ ".DS_Store",
26
+ "README.rdoc",
27
+ "README.txt",
28
+ "Rakefile",
29
+ "VERSION",
30
+ "bin/smartcall",
31
+ "config/website.yml.sample",
32
+ "craigp-smartcall.gemspec",
33
+ "lib/smartcall.rb",
34
+ "lib/smartcall/soap/default.rb",
35
+ "lib/smartcall/soap/default_driver.rb",
36
+ "lib/smartcall/soap/smartcall_error.rb",
37
+ "lib/smartcall/soap/sms_ws_client.rb",
38
+ "lib/smartcall/utility.rb",
39
+ "lib/smartcall/utility/options.rb",
40
+ "test/test_helper.rb",
41
+ "test/test_smartcall.rb"
42
+ ]
43
+ s.homepage = %q{http://github.com/craigp/smartcall}
44
+ s.require_paths = ["lib"]
45
+ s.rubygems_version = %q{1.5.0}
46
+ s.summary = %q{Gem to provide SMS functionality through the Smartcall}
47
+ s.test_files = [
48
+ "test/test_helper.rb",
49
+ "test/test_smartcall.rb"
50
+ ]
51
+
52
+ if s.respond_to? :specification_version then
53
+ s.specification_version = 3
54
+
55
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
56
+ s.add_development_dependency(%q<shoulda>, [">= 2.11.1"])
57
+ else
58
+ s.add_dependency(%q<shoulda>, [">= 2.11.1"])
59
+ end
60
+ else
61
+ s.add_dependency(%q<shoulda>, [">= 2.11.1"])
62
+ end
63
+ end
64
+
@@ -0,0 +1,147 @@
1
+ require 'xsd/qname'
2
+
3
+ module Smartcall
4
+ module Soap
5
+ # {http://tempuri.org/}login
6
+ class Login
7
+ @@schema_type = "login"
8
+ @@schema_ns = "http://tempuri.org/"
9
+ @@schema_qualified = "true"
10
+ @@schema_element = [["username", "SOAP::SOAPString"], ["password", "SOAP::SOAPString"]]
11
+
12
+ attr_accessor :username
13
+ attr_accessor :password
14
+
15
+ def initialize(username = nil, password = nil)
16
+ @username = username
17
+ @password = password
18
+ end
19
+ end
20
+
21
+ # {http://tempuri.org/}loginResponse
22
+ class LoginResponse
23
+ @@schema_type = "loginResponse"
24
+ @@schema_ns = "http://tempuri.org/"
25
+ @@schema_qualified = "true"
26
+ @@schema_element = [["loginResult", "SOAP::SOAPBoolean"], ["token", "SOAP::SOAPString"]]
27
+
28
+ attr_accessor :loginResult
29
+ attr_accessor :token
30
+
31
+ def initialize(loginResult = nil, token = nil)
32
+ @loginResult = loginResult
33
+ @token = token
34
+ end
35
+ end
36
+
37
+ # {http://tempuri.org/}sendSMS
38
+ class SendSMS
39
+ @@schema_type = "sendSMS"
40
+ @@schema_ns = "http://tempuri.org/"
41
+ @@schema_qualified = "true"
42
+ @@schema_element = [["token", "SOAP::SOAPString"], ["recipient", "SOAP::SOAPString"], ["message", "SOAP::SOAPString"], ["reference", "SOAP::SOAPString"], ["campaignid", "SOAP::SOAPInt"]]
43
+
44
+ attr_accessor :token
45
+ attr_accessor :recipient
46
+ attr_accessor :message
47
+ attr_accessor :reference
48
+ attr_accessor :campaignid
49
+
50
+ def initialize(token = nil, recipient = nil, message = nil, reference = nil, campaignid = nil)
51
+ @token = token
52
+ @recipient = recipient
53
+ @message = message
54
+ @reference = reference
55
+ @campaignid = campaignid
56
+ end
57
+ end
58
+
59
+ # {http://tempuri.org/}sendSMSResponse
60
+ class SendSMSResponse
61
+ @@schema_type = "sendSMSResponse"
62
+ @@schema_ns = "http://tempuri.org/"
63
+ @@schema_qualified = "true"
64
+ @@schema_element = [["sendSMSResult", "SOAP::SOAPString"]]
65
+
66
+ attr_accessor :sendSMSResult
67
+
68
+ def initialize(sendSMSResult = nil)
69
+ @sendSMSResult = sendSMSResult
70
+ end
71
+ end
72
+
73
+ # {http://tempuri.org/}sendWAPLink
74
+ class SendWAPLink
75
+ @@schema_type = "sendWAPLink"
76
+ @@schema_ns = "http://tempuri.org/"
77
+ @@schema_qualified = "true"
78
+ @@schema_element = [["token", "SOAP::SOAPString"], ["recipient", "SOAP::SOAPString"], ["href", "SOAP::SOAPString"], ["text", "SOAP::SOAPString"], ["reference", "SOAP::SOAPString"], ["campaignid", "SOAP::SOAPInt"]]
79
+
80
+ attr_accessor :token
81
+ attr_accessor :recipient
82
+ attr_accessor :href
83
+ attr_accessor :text
84
+ attr_accessor :reference
85
+ attr_accessor :campaignid
86
+
87
+ def initialize(token = nil, recipient = nil, href = nil, text = nil, reference = nil, campaignid = nil)
88
+ @token = token
89
+ @recipient = recipient
90
+ @href = href
91
+ @text = text
92
+ @reference = reference
93
+ @campaignid = campaignid
94
+ end
95
+ end
96
+
97
+ # {http://tempuri.org/}sendWAPLinkResponse
98
+ class SendWAPLinkResponse
99
+ @@schema_type = "sendWAPLinkResponse"
100
+ @@schema_ns = "http://tempuri.org/"
101
+ @@schema_qualified = "true"
102
+ @@schema_element = [["sendWAPLinkResult", "SOAP::SOAPString"]]
103
+
104
+ attr_accessor :sendWAPLinkResult
105
+
106
+ def initialize(sendWAPLinkResult = nil)
107
+ @sendWAPLinkResult = sendWAPLinkResult
108
+ end
109
+ end
110
+
111
+ # {http://tempuri.org/}sendBinaryString
112
+ class SendBinaryString
113
+ @@schema_type = "sendSMS"
114
+ @@schema_ns = "http://tempuri.org/"
115
+ @@schema_qualified = "true"
116
+ @@schema_element = [["token", "SOAP::SOAPString"], ["recipient", "SOAP::SOAPString"], ["binary", "SOAP::SOAPString"], ["reference", "SOAP::SOAPString"], ["campaignid", "SOAP::SOAPInt"]]
117
+
118
+ attr_accessor :token
119
+ attr_accessor :recipient
120
+ attr_accessor :binary
121
+ attr_accessor :reference
122
+ attr_accessor :campaignid
123
+
124
+ def initialize(token = nil, recipient = nil, binary = nil, reference = nil, campaignid = nil)
125
+ @token = token
126
+ @recipient = recipient
127
+ @binary = binary
128
+ @reference = reference
129
+ @campaignid = campaignid
130
+ end
131
+ end
132
+
133
+ # {http://tempuri.org/}sendBinaryStringResponse
134
+ class SendBinaryStringResponse
135
+ @@schema_type = "sendSMSResponse"
136
+ @@schema_ns = "http://tempuri.org/"
137
+ @@schema_qualified = "true"
138
+ @@schema_element = [["sendBinaryStringResult", "SOAP::SOAPString"]]
139
+
140
+ attr_accessor :sendBinaryStringResult
141
+
142
+ def initialize(sendBinaryStringResult = nil)
143
+ @sendBinaryStringResult = sendBinaryStringResult
144
+ end
145
+ end
146
+ end
147
+ end
@@ -0,0 +1,70 @@
1
+ require 'soap/rpc/driver'
2
+
3
+ module Smartcall
4
+ module Soap
5
+
6
+ class SmsWSSoap < ::SOAP::RPC::Driver
7
+ DefaultEndpointUrl = "http://www.smartcalltech.co.za/SmsWS/Service.asmx"
8
+ MappingRegistry = ::SOAP::Mapping::Registry.new
9
+
10
+ Methods = [
11
+ [ "http://tempuri.org/login",
12
+ "login",
13
+ [ ["in", "parameters", ["::SOAP::SOAPElement", "http://tempuri.org/", "login"], true],
14
+ ["out", "parameters", ["::SOAP::SOAPElement", "http://tempuri.org/", "loginResponse"], true] ],
15
+ { :request_style => :document, :request_use => :literal,
16
+ :response_style => :document, :response_use => :literal }
17
+ ],
18
+ [ "http://tempuri.org/sendSMS",
19
+ "sendSMS",
20
+ [ ["in", "parameters", ["::SOAP::SOAPElement", "http://tempuri.org/", "sendSMS"], true],
21
+ ["out", "parameters", ["::SOAP::SOAPElement", "http://tempuri.org/", "sendSMSResponse"], true] ],
22
+ { :request_style => :document, :request_use => :literal,
23
+ :response_style => :document, :response_use => :literal }
24
+ ],
25
+ [ "http://tempuri.org/sendWAPLink",
26
+ "sendWAPLink",
27
+ [ ["in", "parameters", ["::SOAP::SOAPElement", "http://tempuri.org/", "sendWAPLink"], true],
28
+ ["out", "parameters", ["::SOAP::SOAPElement", "http://tempuri.org/", "sendWAPLinkResponse"], true] ],
29
+ { :request_style => :document, :request_use => :literal,
30
+ :response_style => :document, :response_use => :literal }
31
+ ],
32
+ [ "http://tempuri.org/sendBinaryString",
33
+ "sendBinaryString",
34
+ [ ["in", "parameters", ["::SOAP::SOAPElement", "http://tempuri.org/", "sendBinaryString"]],
35
+ ["out", "parameters", ["::SOAP::SOAPElement", "http://tempuri.org/", "sendBinaryStringResponse"]] ],
36
+ { :request_style => :document, :request_use => :literal,
37
+ :response_style => :document, :response_use => :literal,
38
+ :faults => {} }
39
+ ],
40
+ ]
41
+
42
+ def initialize(endpoint_url = nil)
43
+ endpoint_url ||= DefaultEndpointUrl
44
+ super(endpoint_url, nil)
45
+ self.mapping_registry = MappingRegistry
46
+ init_methods
47
+ end
48
+
49
+ private
50
+
51
+ def init_methods
52
+ Methods.each do |definitions|
53
+ opt = definitions.last
54
+ if opt[:request_style] == :document
55
+ add_document_operation(*definitions)
56
+ else
57
+ add_rpc_operation(*definitions)
58
+ qname = definitions[0]
59
+ name = definitions[2]
60
+ if qname.name != name and qname.name.capitalize == name.capitalize
61
+ ::SOAP::Mapping.define_singleton_method(self, qname.name) do |*arg|
62
+ __send__(name, *arg)
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,9 @@
1
+ module Smartcall
2
+ module Soap
3
+ class SmartcallError < StandardError
4
+ def initialize(message)
5
+ super(message)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,108 @@
1
+ module Smartcall
2
+ module Soap
3
+ class SmsWSClient
4
+
5
+ class << self
6
+ def no_authorisation_error
7
+ raise SmartcallError.new("SmsWSErrors: Unable to Login")
8
+ end
9
+
10
+ def invalid_token_error
11
+ raise SmartcallError.new("SmsWSErrors: Invalid Token")
12
+ end
13
+
14
+ def invalid_source_address_error
15
+ raise SmartcallError.new("SmsWSErrors: Invalid Source Address")
16
+ end
17
+
18
+ def invalid_number_error
19
+ raise SmartcallError.new("SmsWSErrors: InvalidNumber")
20
+ end
21
+
22
+ def not_implemented_error
23
+ raise SmartcallError.new("SmsWSErrors: Not Implemented")
24
+ end
25
+
26
+ def debug_mode=(value)
27
+ @@debug_mode = value
28
+ end
29
+ end
30
+
31
+ @@debug_mode = false
32
+
33
+ RESPONSE_HANDLER = { 'Success' => true , 'InvalidSourceAddress' => Proc.new { SmsWSClient.invalid_source_address_error } ,
34
+ 'InvalidToken' => Proc.new { SmsWSClient.invalid_token_error } , 'Failed' => false ,
35
+ 'InvalidNumber' => Proc.new { SmsWSClient.invalid_number_error } }
36
+
37
+ DEFAULT_ENDPOINT = "http://www.smartcalltech.co.za/SmsWS/Service.asmx"
38
+
39
+ def initialize(username, password, campaign_id, reference)
40
+ @retry = true
41
+ @username, @password, @campaign_id, @reference = username, password, campaign_id, reference
42
+ @obj = SmsWSSoap.new(DEFAULT_ENDPOINT)
43
+ @obj.wiredump_dev = STDERR if @@debug_mode
44
+ end
45
+
46
+ def send_sms(cell , msg)
47
+ @cell = cell
48
+ @msg = msg
49
+ @token ||= self.login
50
+ if @token
51
+ s = SendSMS.new(@token , cell , msg , @reference , @campaign_id)
52
+ response = @obj.sendSMS(s)
53
+ return process_response(RESPONSE_HANDLER[response.sendSMSResult])
54
+ else
55
+ update_token
56
+ end
57
+ end
58
+
59
+ def send_binary_sms(cell, header, part)
60
+ @cell = cell
61
+ @token ||= self.login
62
+ if @token
63
+ s = SendBinaryString.new(@token, cell, header + part, @reference, @campaign_id)
64
+ response = @obj.sendBinaryString(s)
65
+ result = process_response(RESPONSE_HANDLER[response.sendBinaryStringResult])
66
+ return result
67
+ else
68
+ update_token
69
+ end
70
+ end
71
+
72
+ def send_wap_link(cell, href, msg)
73
+ @cell = cell
74
+ @msg = msg
75
+ @token ||= self.login
76
+ if @token
77
+ s = SendWAPLink.new(@token , cell , href, msg , @reference , @campaign_id)
78
+ response = @obj.sendWAPLink(s)
79
+ return process_response(RESPONSE_HANDLER[response.sendWAPLinkResult])
80
+ else
81
+ update_token
82
+ end
83
+ end
84
+
85
+ protected
86
+
87
+ def process_response(response_handler)
88
+ response_handler.class == Proc ? response_handler.call : response_handler
89
+ end
90
+
91
+ def update_token
92
+ @retry ? @token = self.login : ( raise no_authorisation_error )
93
+ @retry = false
94
+ end
95
+
96
+ def retry_sms
97
+ send_sms(@cell , @msg) if @retry
98
+ @retry = false
99
+ end
100
+
101
+ def login
102
+ l = Login.new(@username , @password)
103
+ response = @obj.login(l)
104
+ response.loginResult != 'false' ? @token = response.token : false
105
+ end
106
+ end
107
+ end
108
+ end
@@ -0,0 +1,92 @@
1
+ require 'yaml'
2
+ require 'optparse'
3
+ require 'ostruct'
4
+
5
+ module Smartcall
6
+ module Utility
7
+ class Options #:nodoc:
8
+ class << self
9
+
10
+ def parse(args)
11
+ @options = self.default_options
12
+ parser = OptionParser.new do |opts|
13
+ opts.banner = "Usage: smartcall [options] recipient message"
14
+ opts.separator ""
15
+ opts.separator "Specific options:"
16
+
17
+ opts.on('-u', '--username USERNAME',
18
+ "Specify the smartcall username (overrides ~/.smartcall setting)") do |username|
19
+ @options.username = username
20
+ end
21
+
22
+ opts.on('-p', '--password PASSWORD',
23
+ "Specify the smartcall password (overrides ~/.smartcall setting)") do |password|
24
+ @options.password = password
25
+ end
26
+
27
+ opts.on('-c', '--campaign CAMPAIGN_ID',
28
+ "Specify the campaign key (overrides ~/.smartcall setting)") do |key|
29
+ @options.campaign_id = key
30
+ end
31
+
32
+ opts.on('-r', '--reference REFERENCE',
33
+ "Specify the reference (overrides ~/.smartcall setting)") do |reference|
34
+ @options.reference = reference
35
+ end
36
+
37
+ opts.on('-d', '--debug') do
38
+ Smartcall::Soap::SmsWSClient.debug_mode = true
39
+ end
40
+
41
+ opts.on_tail('-h', '--help', "Show this message") do
42
+ puts opts
43
+ exit
44
+ end
45
+
46
+ opts.on_tail('-v', '--version') do
47
+ puts "Ruby Smartcall SMS Utility #{Smartcall::VERSION}"
48
+ exit
49
+ end
50
+ end
51
+
52
+ parser.parse!(args)
53
+ @options.recipient = ARGV[-2]
54
+ @options.message = ARGV[-1]
55
+
56
+ if (@options.message.nil? || @options.recipient.nil?) && send_message?
57
+ puts "You must specify a recipient and message!"
58
+ puts parser
59
+ exit
60
+ end
61
+
62
+ return @options
63
+
64
+ rescue OptionParser::MissingArgument => e
65
+ switch_given = e.message.split(':').last.strip
66
+ puts "The #{switch_given} option requires an argument."
67
+ puts parser
68
+ exit
69
+ end
70
+
71
+ def default_options
72
+ options = OpenStruct.new
73
+ config_file = File.open(File.join(ENV['HOME'], '.smartcall'))
74
+ config = ::YAML.load(config_file)
75
+ options.username = config['username']
76
+ options.password = config['password']
77
+ options.campaign_id = config['campaign_id']
78
+ options.reference = config['reference']
79
+ return options
80
+ rescue Errno::ENOENT
81
+ return options
82
+ end
83
+
84
+ def send_message?
85
+ (@options.show_status.nil? &&
86
+ @options.show_balance.nil?)
87
+ end
88
+
89
+ end
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,6 @@
1
+ module Smartcall
2
+ module Utility
3
+ end
4
+ end
5
+
6
+ require File.join(File.dirname(__FILE__), *%w[utility/options])
data/lib/smartcall.rb ADDED
@@ -0,0 +1,31 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless
2
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
+
4
+ require 'smartcall/soap/default'
5
+ require 'smartcall/soap/default_driver'
6
+ require 'smartcall/soap/smartcall_error'
7
+ require 'smartcall/soap/sms_ws_client'
8
+
9
+ module Smartcall
10
+
11
+ VERSION = File.exist?('VERSION') ? File.read('VERSION') : ""
12
+
13
+ class API
14
+
15
+ def initialize(username, password, campaign_id, reference)
16
+ @client = Smartcall::Soap::SmsWSClient.new(username, password, campaign_id, reference)
17
+ end
18
+
19
+ def send_message(msisdn, message_body, options = {})
20
+ @client.send_sms(msisdn, message_body)
21
+ end
22
+
23
+ def send_binary_message(msisdn, header, part, options = {})
24
+ raise NotImplementedError.new
25
+ end
26
+
27
+ def send_wap_link(msisdn, href, message, options = {})
28
+ raise NotImplementedError.new
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,3 @@
1
+ require 'stringio'
2
+ require 'test/unit'
3
+ require File.dirname(__FILE__) + '/../lib/smartcall'
@@ -0,0 +1,11 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class TestSmartcall < Test::Unit::TestCase
4
+
5
+ def setup
6
+ end
7
+
8
+ def test_truth
9
+ assert true
10
+ end
11
+ end
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: craigp-smartcall
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Craig Paterson
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-02-09 00:00:00 +02:00
19
+ default_executable: smartcall
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: shoulda
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 33
30
+ segments:
31
+ - 2
32
+ - 11
33
+ - 1
34
+ version: 2.11.1
35
+ type: :development
36
+ version_requirements: *id001
37
+ description: |
38
+ Gem to provide SMS functionality through the Smartcall Technology Solutions web
39
+ services. Contact http://www.smartcalltech.co.za for an account. This gem is based
40
+ on the smartcall gem written by Armand du Plessis (adp@bank.io)
41
+
42
+ email: darksavant@gmail.com
43
+ executables:
44
+ - smartcall
45
+ extensions: []
46
+
47
+ extra_rdoc_files:
48
+ - README.rdoc
49
+ - README.txt
50
+ files:
51
+ - .DS_Store
52
+ - README.rdoc
53
+ - README.txt
54
+ - Rakefile
55
+ - VERSION
56
+ - bin/smartcall
57
+ - config/website.yml.sample
58
+ - craigp-smartcall.gemspec
59
+ - lib/smartcall.rb
60
+ - lib/smartcall/soap/default.rb
61
+ - lib/smartcall/soap/default_driver.rb
62
+ - lib/smartcall/soap/smartcall_error.rb
63
+ - lib/smartcall/soap/sms_ws_client.rb
64
+ - lib/smartcall/utility.rb
65
+ - lib/smartcall/utility/options.rb
66
+ - test/test_helper.rb
67
+ - test/test_smartcall.rb
68
+ has_rdoc: true
69
+ homepage: http://github.com/craigp/smartcall
70
+ licenses: []
71
+
72
+ post_install_message:
73
+ rdoc_options: []
74
+
75
+ require_paths:
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ hash: 3
83
+ segments:
84
+ - 0
85
+ version: "0"
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ none: false
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ hash: 3
92
+ segments:
93
+ - 0
94
+ version: "0"
95
+ requirements: []
96
+
97
+ rubyforge_project:
98
+ rubygems_version: 1.5.0
99
+ signing_key:
100
+ specification_version: 3
101
+ summary: Gem to provide SMS functionality through the Smartcall
102
+ test_files:
103
+ - test/test_helper.rb
104
+ - test/test_smartcall.rb