smsc_manager 0.5.1 → 0.5.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,6 +4,7 @@ CHANGELOG.txt
4
4
  Manifest.txt
5
5
  setup.rb
6
6
  config/smsc.yml
7
+ config/database.yml
7
8
  bin/smsc_config.rb
8
9
  bin/smsc_print_config.rb
9
10
  bin/send_sms_post.rb
@@ -19,6 +20,7 @@ bin/sms_om_server.rb
19
20
  lib/smsc_manager/version.rb
20
21
  lib/smsc_manager/sms.rb
21
22
  lib/smsc_manager/smsc_listener.rb
23
+ lib/smsc_manager/smsc_stomp_connection.rb
22
24
  lib/smsc_manager/sms_statistics_listener.rb
23
25
  lib/smsc_manager/sms_send_topic.rb
24
26
  lib/smsc_manager/broadcast.rb
@@ -26,6 +28,7 @@ lib/smsc_manager/broadcast_topic.rb
26
28
  lib/smsc_manager/smsc_connection.rb
27
29
  lib/smsc_manager.rb
28
30
  test/test_helper.rb
31
+ app/models/sms_log.rb
29
32
  test/smsc_manager_test.rb
30
33
  examples/receive_sms_controller.rb
31
- examples/stomp
34
+ examples/stomp
data/README.txt CHANGED
@@ -4,7 +4,7 @@ README for smsc_manager
4
4
 
5
5
 
6
6
  For more info: www.ficonab.com
7
- scott.sproule@gmail.com
7
+ scott.sproule@ficonab.com
8
8
 
9
9
  To print smsc settings:
10
10
  bin/print_smsc_config.rb
@@ -0,0 +1,70 @@
1
+
2
+ class SmsLog < ActiveRecord::Base
3
+ def self.log(user, sms)
4
+ sms_transaction_log = SmsLog.new
5
+ # sms_transaction_log.user=user
6
+ sms_transaction_log.setup(sms)
7
+ sms_transaction_log.username=user
8
+ sms_transaction_log.save!
9
+ end
10
+ def self.log_result(res, user, sms,flag)
11
+ sms_transaction_log = SmsLog.new
12
+ # sms_transaction_log.user=user
13
+ sms_transaction_log.setup(sms)
14
+ sms_transaction_log.username=user
15
+ case flag
16
+ when true
17
+ if res.kind_of? Net::HTTPResponse
18
+ sms_transaction_log.response=res.code
19
+ sms_transaction_log.response_body=res.body
20
+ else
21
+ sms_transaction_log.response=202
22
+ sms_transaction_log.response_body=res
23
+ end
24
+ else
25
+ sms_transaction_log.response=9000
26
+ sms_transaction_log.response_body=res.to_s
27
+ end
28
+ sms_transaction_log.save!
29
+ end
30
+ def setup(sms)
31
+ self.sms_content=sms.text
32
+ self.destination=sms.destination
33
+ self.source= sms.source
34
+ end
35
+
36
+ #this needs to be fixed....
37
+ def self.send_sms_and_log(user, sms)
38
+
39
+ # sms_transaction_log.user=user
40
+ successflag=false
41
+ begin
42
+ sms_sender= SmscManager::SmsSendTopic.new
43
+ r= sms_sender.send_topic_sms(sms)
44
+ sms_sender.disconnect_stomp
45
+ successflag=true
46
+ rescue Exception => e
47
+ r = "send failed with #{e.message}"
48
+ end
49
+ SmscManager::SmsLog.log_result(r,user,sms,successflag)
50
+ end
51
+
52
+
53
+ # THIS NEEDs TO bE FixED,,, change to text rather string in database as well.
54
+ def self.send_mms_and_log(user, mms)
55
+
56
+ # sms_transaction_log.user=user
57
+ successflag=false
58
+ begin
59
+
60
+ mms_sender= MmscManager::MmsSendTopic.new
61
+ r= mms_sender.send_topic_mms(mms)
62
+ mms_sender.disconnect_stomp
63
+ successflag=true
64
+
65
+ rescue Exception => e
66
+ r = "send failed with #{e.message}"
67
+ end
68
+ SmscManager::SmsLog.log_result(r,user,mms,successflag)
69
+ end
70
+ end
@@ -64,13 +64,13 @@ def send_group(arg_hash,sms_sender)
64
64
  sms_sender.send_topic_sms_receipt(s) { |m| receipt_count-=1
65
65
  # puts "receipt: #{receipt_count}"
66
66
  }
67
- sleep(1) if c % 100 == 0
67
+ #sleep(1) if c % 100 == 0
68
68
  Thread.pass
69
69
  }
70
70
 
71
71
  # sms_sender.close_topic
72
72
  begin
73
- Timeout::timeout(count*0.5) {
73
+ Timeout::timeout(count*0.75) {
74
74
  while true
75
75
  puts "sent #{count} waiting for #{receipt_count} receipts"
76
76
  exit(0) if receipt_count==0
@@ -81,7 +81,7 @@ def send_group(arg_hash,sms_sender)
81
81
  rescue Exception => e
82
82
  puts "exception #{e.message} class: #{e.class}"
83
83
  puts "#{e.backtrace}"
84
- raise e
84
+ # raise e
85
85
 
86
86
  end
87
87
  receipt_count
@@ -89,6 +89,7 @@ end
89
89
  puts "Finding sms topic to use:"
90
90
  begin
91
91
  sms_sender=SmscManager::SmsSendTopic.new(arg_hash)
92
+ sms_sender.setup_auto_close
92
93
  # sms_sender.setup_auto_close #only call this once # servers onlycall cloase
93
94
  rescue Exception => e
94
95
  puts "exception found #{e.backtrace}"
@@ -101,8 +102,14 @@ end
101
102
  no_receipt_count=0
102
103
  1.upto(repeat) { |r|
103
104
  no_receipt_count+=send_group(arg_hash,sms_sender)
104
- sleep(1)
105
-
105
+ # sleep(1)
106
+ diff = Time.now - start
107
+ puts "#{Time.now} Sent #{count*r} in #{diff} seconds with #{no_receipt_count} problems"
108
+
109
+ completion = r.to_f/repeat*100
110
+ puts "Percent complete: #{completion}"
111
+ no_prob = count*r - no_receipt_count
112
+ puts " Average message per second is: #{no_prob/diff}"
106
113
  }
107
114
 
108
115
  diff = Time.now - start
@@ -1,51 +1,34 @@
1
1
  #!/usr/bin/env ruby
2
- require 'optparse'
3
- def usage
4
- puts "Usage: send_sms.rb -u user -m msisdn -s source -t text "
5
- puts "or for example send_sms.rb --user etc. -h hostname optional"
6
- exit
7
- end
8
- def parse_options(params)
9
- opts = OptionParser.new
10
- puts "argv are #{params}"
11
- #params_split = params.split(' ')
12
- #puts "paramsp is #{paramsp}"
13
- user_flag=msisdn_flag=source_flag=text_flag=true
14
- temp_hash = {}
15
- opts.on("-h","--host VAL", String) {|val| temp_hash[:host ] = val
16
- puts "host is #{val}"
17
- }
18
- opts.on("-u","--user VAL", String) {|val| temp_hash[:user ] = val
19
- puts "user is #{val}"
20
- user_flag=false }
21
- opts.on("-m","--msisdn VAL", String) {|val| temp_hash[:msisdn ] = val
22
- puts "msiddn is #{val}"
23
- msisdn_flag=false }
24
- opts.on("-s","--source VAL", String) {|val| temp_hash[:source ] = val
25
- puts "source is #{val}"
26
- source_flag=false }
27
- opts.on("-t","--text VAL", String) {|val| temp_hash[:text ] = val
28
- puts "text is #{val}"
29
- text_flag=false }
30
- #opts.on("-d","--database VAL", String) {|val| temp_hash[:db ] = val }
31
- #opts.on("-p","--password VAL", String) {|val| temp_hash[:password ] = val }
32
- #opts.on("-u","--user VAL", String) {|val| temp_hash[:user ] = val }
33
- #puts " in test commander option parse #{port} #{url}"
34
- opts.parse(params)
35
- # puts " in HTTP #{hostname} port #{port} url: #{url}"
36
- usage if user_flag or msisdn_flag or source_flag or text_flag
37
- return temp_hash
38
- end
39
- arg_hash=parse_options(ARGV)
2
+ # == Synopsis
3
+ # send sms via sdp
4
+ # == Usage
5
+ # send_sms.rb -u user -m msisdn -s source -t text
6
+ # == Useful commands
7
+ # send_sms.rb -u scot -m 639993130030 -s 888 -t 'hello there'
8
+ # == Author
9
+ # Scott Sproule --- Ficonab.com (scott.sproule@ficonab.com)
10
+ # == Copyright
11
+ # Copyright (c) 2007 Ficonab Pte. Ltd.
12
+ # See license for license details
13
+
14
+ require 'optparse'
15
+ require 'rubygems'
16
+ gem 'stomp_message'
17
+ require 'stomp_message'
18
+ require 'rdoc/usage'
19
+
20
+ arg_hash=StompMessage::Options.parse_options(ARGV)
21
+ RDoc::usage if arg_hash[:msisdn]==nil || arg_hash[:text] == nil || arg_hash[:source] == nil || arg_hash[:help]==true
22
+
40
23
  require 'pp'
41
24
 
42
- require 'rubygems'
43
25
  gem 'smsc_manager'
44
26
  require 'smsc_manager'
45
27
 
46
28
  puts "Finding sms topic to use:"
47
29
  begin
48
- sms_sender=SmscManager::SmsSendTopic.new(arg_hash)
30
+ sms_sender=SmscManager::SmsSendTopic.new(arg_hash)
31
+ sms_sender.setup_auto_close
49
32
  rescue Exception => e
50
33
  puts "exception found #{e.backtrace}"
51
34
  end
@@ -1,40 +1,24 @@
1
1
  #!/usr/bin/env ruby
2
- require 'optparse'
3
- def usage
4
- puts "Usage: send_sms_http.rb -u user -m msisdn -s source -t text "
5
- puts " to send via http directly to server"
6
- puts "or for example send_sms_http.rb --user etc."
7
- exit
8
- end
9
- def parse_options(params)
10
- opts = OptionParser.new
11
- puts "argv are #{params}"
12
- #params_split = params.split(' ')
13
- #puts "paramsp is #{paramsp}"
14
- user_flag=msisdn_flag=source_flag=text_flag=true
15
- temp_hash = {}
16
- opts.on("-u","--user VAL", String) {|val| temp_hash[:user ] = val
17
- puts "user is #{val}"
18
- user_flag=false }
19
- opts.on("-m","--msisdn VAL", String) {|val| temp_hash[:msisdn ] = val
20
- puts "msiddn is #{val}"
21
- msisdn_flag=false }
22
- opts.on("-s","--source VAL", String) {|val| temp_hash[:source ] = val
23
- puts "source is #{val}"
24
- source_flag=false }
25
- opts.on("-t","--text VAL", String) {|val| temp_hash[:text ] = val
26
- puts "text is #{val}"
27
- text_flag=false }
28
- #opts.on("-d","--database VAL", String) {|val| temp_hash[:db ] = val }
29
- #opts.on("-p","--password VAL", String) {|val| temp_hash[:password ] = val }
30
- #opts.on("-u","--user VAL", String) {|val| temp_hash[:user ] = val }
31
- #puts " in test commander option parse #{port} #{url}"
32
- opts.parse(params)
33
- # puts " in HTTP #{hostname} port #{port} url: #{url}"
34
- usage if user_flag or msisdn_flag or source_flag or text_flag
35
- return temp_hash
36
- end
37
- arg_hash=parse_options(ARGV)
2
+ # == Synopsis
3
+ # send sms via http
4
+ # == Usage
5
+ # send_sms_http.rb -u user -m msisdn -s source -t text
6
+ # == Useful commands
7
+ # send_sms_http.rb -u scot -m 639993130030 -s 888 -t 'hello there'
8
+ # == Author
9
+ # Scott Sproule --- Ficonab.com (scott.sproule@ficonab.com)
10
+ # == Copyright
11
+ # Copyright (c) 2007 Ficonab Pte. Ltd.
12
+ # See license for license details
13
+
14
+ require 'optparse'
15
+ require 'rubygems'
16
+ gem 'stomp_message'
17
+ require 'stomp_message'
18
+ require 'rdoc/usage'
19
+
20
+ arg_hash=StompMessage::Options.parse_options(ARGV)
21
+ RDoc::usage if arg_hash[:msisdn]==nil || arg_hash[:text] == nil || arg_hash[:source] == nil || arg_hash[:help]==true
38
22
  require 'pp'
39
23
 
40
24
  require 'rubygems'
@@ -50,6 +50,7 @@ require 'smsc_manager'
50
50
  puts "Finding sms topic to use:"
51
51
  begin
52
52
  sms_sender=SmscManager::SmsSendTopic.new(arg_hash)
53
+ sms_sender.setup_auto_close
53
54
  rescue Exception => e
54
55
  puts "exception found #{e.backtrace}"
55
56
  end
@@ -1,51 +1,27 @@
1
1
  #!/usr/bin/env ruby
2
+ #!/usr/bin/env ruby
3
+ # == Synopsis
4
+ # send sms via http post to sdp topic --- example for content providers
5
+ # == Usage
6
+ # send_sms_post.rb -u user -m msisdn -s source -t text -h host -p port -T topic -U url
7
+ # == Sample commands
8
+ # send_sms_post.rb -u scot -s 888 -m 639993130030 -t testing -h localhost -p 8161 -T sms
9
+ # == Author
10
+ # Scott Sproule --- Ficonab.com (scott.sproule@ficonab.com)
11
+ # == Copyright
12
+ # Copyright (c) 2007 Ficonab Pte. Ltd.
13
+ # See license for license details
14
+
2
15
  require 'optparse'
3
- def usage
4
- puts "Usage: send_sms_post.rb -u user -m msisdn -s source -t text -h host -p port -a topic "
5
-
6
- exit
7
- end
8
- def parse_options(params)
9
- opts = OptionParser.new
10
- puts "argv are #{params}"
11
- #params_split = params.split(' ')
12
- #puts "paramsp is #{paramsp}"
13
- user_flag=msisdn_flag=source_flag=text_flag=true
14
- temp_hash = {}
15
- opts.on("-h","--host VAL", String) {|val| temp_hash[:host ] = val
16
- puts "host is #{val}"
17
- }
18
- opts.on("-u","--user VAL", String) {|val| temp_hash[:user ] = val
19
- puts "user is #{val}"
20
- user_flag=false }
21
- opts.on("-p","--port VAL", String) {|val| temp_hash[:port ] = val
22
- puts "port is #{val}"
23
- }
24
- opts.on("-a","--topic VAL", String) {|val| temp_hash[:topic ] = val
25
- puts "user is #{val}"
26
- user_flag=false }
27
- opts.on("-m","--msisdn VAL", String) {|val| temp_hash[:msisdn ] = val
28
- puts "msiddn is #{val}"
29
- msisdn_flag=false }
30
- opts.on("-s","--source VAL", String) {|val| temp_hash[:source ] = val
31
- puts "source is #{val}"
32
- source_flag=false }
33
- opts.on("-t","--text VAL", String) {|val| temp_hash[:text ] = val
34
- puts "text is #{val}"
35
- text_flag=false }
36
- #opts.on("-d","--database VAL", String) {|val| temp_hash[:db ] = val }
37
- #opts.on("-p","--password VAL", String) {|val| temp_hash[:password ] = val }
38
- #opts.on("-u","--user VAL", String) {|val| temp_hash[:user ] = val }
39
- #puts " in test commander option parse #{port} #{url}"
40
- opts.parse(params)
41
- # puts " in HTTP #{hostname} port #{port} url: #{url}"
42
- usage if user_flag or msisdn_flag or source_flag or text_flag
43
- return temp_hash
44
- end
45
- arg_hash=parse_options(ARGV)
16
+ require 'rubygems'
17
+ gem 'stomp_message'
18
+ require 'stomp_message'
19
+ require 'rdoc/usage'
20
+
21
+ arg_hash=StompMessage::Options.parse_options(ARGV)
22
+ RDoc::usage if arg_hash[:msisdn]==nil || arg_hash[:text] == nil || arg_hash[:source] == nil || arg_hash[:help]==true
46
23
  require 'pp'
47
24
 
48
- require 'rubygems'
49
25
  gem 'smsc_manager'
50
26
  require 'smsc_manager'
51
27
  require 'net/http'
@@ -58,15 +34,9 @@ require 'net/http'
58
34
  m=SmscManager::SmsSendTopic.create_stomp_message(text,destination,source)
59
35
  puts "message is #{m.to_xml}"
60
36
  puts "hostname: #{arg_hash[:host]} port #{arg_hash[:port]}"
61
- url="#{arg_hash[:topic]}?m.to_xml"
62
- ht =Net::HTTP.start(arg_hash[:host],arg_hash[:port])
63
- r=ht.post(url)
64
- puts "url was: #{url}"
65
- puts "result: #{r.to_s}"
66
- # res= smsc.send(sms)
67
- # puts "Response code: #{res.response} body: #{res.response_body}"
68
- # puts "Response code: #{res}" if res.kind_of? String
69
- # puts "pretty print response:"
70
- # pp res
71
- # puts "Response code: #{res.} body: #{res.code}" if res.kind_of? Net::Http
37
+ url="#{arg_hash[:topic]}?m.to_xml"
38
+ arg_hash[:url]="/demo/message/" << arg_hash[:topic] if arg_hash[:url]==nil
39
+ msg_sender=StompMessage::StompSendTopic.new(arg_hash)
40
+ msg_sender.post_stomp(m, {})
41
+
72
42
 
@@ -1,4 +1,16 @@
1
1
  #!/usr/bin/env ruby
2
+ # == Synopsis
3
+ # start up the sms om listener. OM = Operational Measurements. This is the statistics/repoting tool listening to sdp message
4
+ # == Usage
5
+ # sms_om_server.rb
6
+ # change the number of threads, and other key variables below to control system performance
7
+ # == Useful commands
8
+ # sms_om_server.rb
9
+ # == Author
10
+ # Scott Sproule --- Ficonab.com (scott.sproule@ficonab.com)
11
+ # == Copyright
12
+ # Copyright (c) 2007 Ficonab Pte. Ltd.
13
+ # See license for license details
2
14
  require 'optparse'
3
15
  def usage
4
16
  puts "Usage: sms_topic_server.rb to start up listener "
@@ -12,7 +24,7 @@ require 'smsc_manager'
12
24
  puts "Starting Operational Measurement (OM) server:"
13
25
  # begin
14
26
  # can add additional options to change host/port etc
15
- sms_listener=SmscManager::SmsStatisticsListener.new({:topic => '/topic/sms', :thread_count => '5'}).run
27
+ sms_listener=SmscManager::SmsStatisticsListener.new({:topic => '/topic/sms', :thread_count => '3'}).run
16
28
  # sms_listener.join
17
29
  # rescue Exception => e
18
30
  puts "exception found #{e.backtrace}"
@@ -1,17 +1,34 @@
1
1
  #!/usr/bin/env ruby
2
+ # == Synopsis
3
+ # start up the sms topic listener. This is the key component for listening to sdp message
4
+ # == Usage
5
+ # sms_topic_server.rb path_to_sms_model_files rails_environment
6
+ # change the number of threads, and other key variables below to control system performance
7
+ # == Useful commands
8
+ # sms_topic_server.rb ./ development --- if in development environment
9
+ # sms_topic_server.rb --- if in production environment and config ok.
10
+ # == Author
11
+ # Scott Sproule --- Ficonab.com (scott.sproule@ficonab.com)
12
+ # == Copyright
13
+ # Copyright (c) 2007 Ficonab Pte. Ltd.
14
+ # See license for license details
2
15
  require 'optparse'
3
16
  def usage
4
17
  puts "Usage: sms_topic_server.rb to start up listener "
18
+ puts "Usage: sms_topic_server.rb path_to_subscriptions_rails_app environment "
19
+ puts "eg: sms_topic_server.rb ./ development "
5
20
  exit
6
21
  end
7
22
 
8
23
  require 'rubygems'
9
24
  gem 'smsc_manager'
10
25
  require 'smsc_manager'
11
-
12
- puts "Starting topic server:"
26
+ env_setting = ARGV[1] || "production"
27
+ path_setting = ARGV[0] || "/opt/local/rails_apps/smsapp/current/"
28
+ puts "Starting SMSC Topic Server topic server: path: #{path_setting} environment: #{env_setting}"
29
+ #puts "Starting topic server:"
13
30
  # begin
14
- SmscManager::SmscListener.new({:topic => '/topic/sms', :thread_count => '14'}).run
31
+ SmscManager::SmscListener.new({:topic => '/topic/sms', :thread_count => '10', :env => env_setting, :root_path => path_setting }).run
15
32
  # sms_listener.join
16
33
  # rescue Exception => e
17
34
  puts "exception found #{e.backtrace}"
@@ -1,4 +1,17 @@
1
1
  #!/usr/bin/env ruby
2
+ #!/usr/bin/env ruby
3
+ # == Synopsis
4
+ # daemonize the sms topic listener. For use in production environment
5
+ # == Usage
6
+ # sms_topic_server_control.rb start
7
+ # sms_topic_server_control.rb stop
8
+ # == Useful commands
9
+ # supports other daemons commands
10
+ # == Author
11
+ # Scott Sproule --- Ficonab.com (scott.sproule@ficonab.com)
12
+ # == Copyright
13
+ # Copyright (c) 2007 Ficonab Pte. Ltd.
14
+ # See license for license details
2
15
  require 'optparse'
3
16
  require 'rubygems'
4
17
  gem 'smsc_manager'
@@ -0,0 +1,35 @@
1
+ # MySQL (default setup). Versions 4.1 and 5.0 are recommended.
2
+ #
3
+ # Install the MySQL driver:
4
+ # gem install mysql
5
+ # On MacOS X:
6
+ # gem install mysql -- --include=/usr/local/lib
7
+ # On Windows:
8
+ # There is no gem for Windows. Install mysql.so from RubyForApache.
9
+ # http://rubyforge.org/projects/rubyforapache
10
+ #
11
+ # And be sure to use new-style password hashing:
12
+ # http://dev.mysql.com/doc/refman/5.0/en/old-client.html
13
+ development:
14
+ adapter: mysql
15
+ database: smsapp_development
16
+ username: root
17
+ password: Abby789
18
+ host: localhost
19
+
20
+ # Warning: The database defined as 'test' will be erased and
21
+ # re-generated from your development database when you run 'rake'.
22
+ # Do not set this db to the same as development or production.
23
+ test:
24
+ adapter: mysql
25
+ database: smsapp_test
26
+ username: root
27
+ password: Abby789
28
+ host: localhost
29
+
30
+ production:
31
+ adapter: mysql
32
+ database: smsapp_production
33
+ username: root
34
+ password: Abby789
35
+ host: localhost
@@ -44,8 +44,11 @@ class BroadcastTopic
44
44
 
45
45
  # puts " dst is #{dst}"
46
46
  }
47
- puts "populate topic sent #{self.sent}"
48
- sleep(1)
47
+
48
+ sleep(2) # should we wait till we get receipts for all?
49
+ puts "populate topic sent #{self.sent}"
50
+ sleep(self.attempts*0.5+1) if self.sent!=self.attempts
51
+ puts "populate topic sent after sleep #{self.sent}"
49
52
  self.sms_sender.disconnect_stomp
50
53
  end
51
54
  def send_it(txt,dst)
@@ -11,7 +11,7 @@ end
11
11
  class Sms
12
12
  @@MAX_SIZE=1500 # 3*160 # max 1500 characters, change if your smsc suports less
13
13
  @@msisdn_valid_prefix= %w{ 63999 999 0999 1000 888 +63999 }
14
- attr_accessor :text, :source, :destination, :orig_txt
14
+ attr_accessor :text, :source, :destination #, :orig_txt
15
15
  def self.max_length
16
16
  @@MAX_SIZE
17
17
  end
@@ -22,13 +22,16 @@ class Sms
22
22
  @@msisdn_valid_prefix.each {|t| sentence << t <<" " }
23
23
  sentence
24
24
  end
25
+ def get_message_content
26
+ self.text
27
+ end
25
28
  def self.starts_with?(prefix,dest)
26
29
  prefix = prefix.to_s
27
30
  return false if dest == nil
28
31
  dest[0, prefix.length] == prefix
29
32
  end
30
33
  def initialize(txt,dest,src='888')
31
- self.orig_txt=txt
34
+ # self.orig_txt=txt
32
35
  self.destination=dest
33
36
  self.source=src
34
37
  self.text=strip_text(txt)
@@ -51,21 +54,7 @@ class Sms
51
54
  # doc= REXML::Document.new sms_xml.to_s
52
55
  # doc.to_s
53
56
  end
54
- def to_xml_old
55
- sms_xml = REXML::Element.new "sms"
56
- destination_xml = REXML::Element.new "destination"
57
- destination_xml.text=self.destination
58
- source_xml =REXML::Element.new "source"
59
- source_xml.text=self.source
60
- text_xml =REXML::Element.new "text"
61
- text_xml.text=self.text
62
- sms_xml.add_element destination_xml
63
- sms_xml.add_element source_xml
64
- sms_xml.add_element text_xml
65
- sms_xml.to_s
66
- # doc= REXML::Document.new sms_xml.to_s
67
- # doc.to_s
68
- end
57
+
69
58
  def self.load_xml(xml_string)
70
59
  doc=REXML::Document.new(xml_string)
71
60
  dest=REXML::XPath.first(doc, "//destination").text
@@ -77,9 +66,10 @@ class Sms
77
66
  #limit to @@MAX_SIZE characters
78
67
  ret=""
79
68
  size=[val.size,@@MAX_SIZE].min-1
80
- 0.upto(size) do |i|
81
- ret << val[i]
82
- end
69
+ # 0.upto(size) do |i|
70
+ # ret << val[i]
71
+ # end
72
+ ret=val[0..size]
83
73
  ret
84
74
  end
85
75
  def strip_text(txt)
@@ -88,9 +78,10 @@ class Sms
88
78
  result=txt.gsub(/@/,"(at)") # replace all at signs return result
89
79
  # result=result.gsub(/\n/," ") # replace all new lines return result
90
80
  # result=result.gsub(/\r/," ") # replace all new lines return result
91
- result=result.gsub(/_/,"-") # replace all new lines return result
92
- result=result.gsub(/-/," ") # replace all - with space...angelo bug return result
81
+ result=result.gsub('_',"-") # replace all new lines return result
82
+ # result=result.gsub(/-/," ") # replace all - with space...angelo bug return result
93
83
  # result=result4.gsub(/\//,"") # replace all new lines return result
84
+
94
85
  limit_text(result)
95
86
  end
96
87
  end
@@ -24,7 +24,7 @@ class SmscConnection
24
24
  s= Time.now - s
25
25
  end
26
26
  # puts "#{Time.now} result #{hostname} flag: #{flag} res: #{res} time #{s}"
27
- puts "-res #{@res} -time #{s}"
27
+ puts "-res #{@res} -time #{s} dest: #{destination} src: #{source}"
28
28
  return @res
29
29
  end
30
30
  def self.path_to_config
@@ -71,8 +71,8 @@ class SmscConnection
71
71
 
72
72
  # URL Encoded specific to Kannel that is why not part of model
73
73
  def sms_send(sms)
74
-
75
- txt_encoded=ERB::Util.url_encode(sms.text)
74
+ text= ERB::Util.html_escape(sms.text)
75
+ txt_encoded=ERB::Util.url_encode(text)
76
76
  # txt_encoded=limit_text(txt_encoded)
77
77
  # smsc=SmscManager::SmscConnection.factory
78
78
  internal_send(txt_encoded,sms.destination,sms.source)
@@ -6,33 +6,34 @@ require 'stomp'
6
6
  gem 'stomp_message'
7
7
  require 'stomp_message'
8
8
  module SmscManager
9
- class SmscListener < StompMessage::StompServer
9
+ class SmscListener < StompMessage::StompZActiveRecordServer
10
10
  @@MAX_THROUGHPUT =5 # in messages per second
11
11
  SLEEP_TIME=1/@@MAX_THROUGHPUT #sleep x seconds to slow down system
12
12
  attr_accessor :smsc
13
13
  #need to define topic, host properly
14
14
  # @@TOPIC='/topic/sms'
15
15
  def initialize(options={})
16
+ self.model_list = []
17
+ self.model_list << "sms_log.rb"
16
18
  super(options)
17
- self.smsc=SmscManager::SmscConnection.factory
19
+ #self.smsc=SmscManager::SmscConnection.factory
18
20
  puts "finished initializing"
19
21
  end
20
- # def send_reply(headers,msg)
21
- # msisdn = headers['msisdn']
22
- # reply_topic=headers['reply-to']
23
- # puts "headers: #{headers['msisdn']} reply topic #{headers['reply-to']}"
24
- # internal_conn = Stomp::Connection.open '', '', self.host, self.port, false
25
- # internal_conn.subscribe reply_topic, { :ack =>"auto" }
26
- # m=StompMessage::Message.new('stomp_REPLY', msg_body)
27
- # internal_conn.send(reply_topic, msg.to_xml, {'persistent'=>'false', 'msisdn' => "#{msisdn}" })
28
- # internal_conn.unsubscribe reply_topic
29
- # end
30
- # name is message command
22
+ def archive_sms(res,sms)
23
+ # do I need to do exception handling in here
24
+ flag= res.kind_of? Net::HTTPResponse
25
+ SmsLog.log_result(res, 'stomp_message', sms,flag )
26
+ end
27
+ def setup_thread_specific_items(mythread_number)
28
+ super(mythread_number)
29
+ puts " ----creating smsc for #{Thread.current[:name]}"
30
+ Thread.current[:smsc]= SmscManager::SmscConnection.factory
31
+ end
31
32
  def stomp_SMS(msg, stomp_msg)
32
33
  sms=SmscManager::Sms.load_xml(msg.body)
33
- puts "sending sms #{msg.body}" if @debug
34
- res= self.smsc.send(sms)
35
-
34
+ puts "#{Thread.current[:name]}sending sms #{msg.body}" if @debug
35
+ res= Thread.current[:smsc].send(sms)
36
+ archive_sms(res,sms)
36
37
  # sleep(SLEEP_TIME) #only 5 messages per second max
37
38
  end
38
39
 
@@ -0,0 +1,41 @@
1
+ require 'yaml'
2
+ require 'erb'
3
+ require 'timeout'
4
+ require 'net/http'
5
+ module SmscManager
6
+ class SmscStompConnection
7
+ # use block for timers etc
8
+ @@timeout_max = 10 #10 second timeout to contact sms server
9
+ attr_accessor :hostname, :port, :username, :password, :url, :topic
10
+ def intialize(args)
11
+ self.url="/TopicSMS/TopicSMS"
12
+ self.topic = 'sms'
13
+ self.hostname = 'x.x.x.x'
14
+ self.port='8161'
15
+ end
16
+
17
+ def send(sms)
18
+ sms_send(sms)
19
+ end
20
+ def test(sms)
21
+ send(sms)
22
+ end
23
+ # asssumes http post --- can be modified for other messaging of course
24
+ def sms_send(sms)
25
+ puts "create stomp message"
26
+ m=SmscManager::SmsSendTopic.create_stomp_message(sms.text,sms.destination,sms.source)
27
+ puts "message is #{m.to_xml}"
28
+ # original puts "hostname: #{arg_hash[:host]} port #{arg_hash[:port]}"
29
+ arg_hash={}
30
+ arg_hash[:host]=self.hostname
31
+ argh_hash[:port]=self.port
32
+ puts "hostname: #{self.hostname} port #{arg_hash[:port]}"
33
+ url="#{arg_hash[:topic]}?m.to_xml"
34
+ arg_hash[:url]=self.url
35
+ arg_hash[:topic]=self.topic
36
+ msg_sender=StompMessage::StompSendTopic.new(arg_hash)
37
+ msg_sender.post_stomp(m, {})
38
+ end
39
+
40
+ end
41
+ end
@@ -2,7 +2,7 @@ module SmscManager #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 5
5
- TINY = 1
5
+ TINY = 6
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -60,6 +60,11 @@ class SmscManagerTest < Test::Unit::TestCase
60
60
  sms=SmscManager::Sms.new(nil,'09996557890','websource')
61
61
  assert sms.text==" ", "text not correct for nil"
62
62
  end
63
+ def test_sms_text_ampersand
64
+ sms=SmscManager::Sms.new('test & test','639996557890','websource')
65
+ sms2=SmscManager::Sms.load_xml(sms.to_xml)
66
+ assert sms.to_xml==sms2.to_xml, "xml bad with ampersand"
67
+ end
63
68
  def test_broadcast_two
64
69
  list = %w(9991 9992)
65
70
  b=SmscManager::Broadcast.new('888',list,"hello there")
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: smsc_manager
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.5.1
7
- date: 2007-10-08 00:00:00 +08:00
6
+ version: 0.5.6
7
+ date: 2007-11-02 00:00:00 +08:00
8
8
  summary: connection to smsc via http using kannel
9
9
  require_paths:
10
10
  - lib
@@ -35,6 +35,7 @@ files:
35
35
  - Manifest.txt
36
36
  - setup.rb
37
37
  - config/smsc.yml
38
+ - config/database.yml
38
39
  - bin/smsc_config.rb
39
40
  - bin/smsc_print_config.rb
40
41
  - bin/send_sms_post.rb
@@ -50,6 +51,7 @@ files:
50
51
  - lib/smsc_manager/version.rb
51
52
  - lib/smsc_manager/sms.rb
52
53
  - lib/smsc_manager/smsc_listener.rb
54
+ - lib/smsc_manager/smsc_stomp_connection.rb
53
55
  - lib/smsc_manager/sms_statistics_listener.rb
54
56
  - lib/smsc_manager/sms_send_topic.rb
55
57
  - lib/smsc_manager/broadcast.rb
@@ -57,6 +59,7 @@ files:
57
59
  - lib/smsc_manager/smsc_connection.rb
58
60
  - lib/smsc_manager.rb
59
61
  - test/test_helper.rb
62
+ - app/models/sms_log.rb
60
63
  - test/smsc_manager_test.rb
61
64
  - examples/receive_sms_controller.rb
62
65
  - examples/stomp