smsc_manager 0.3.6 → 0.4.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/CHANGELOG.txt CHANGED
@@ -1,3 +1,6 @@
1
+ Version 0.4.0
2
+ Major improvement to use active mq topics and stomp to send messages and added load test
3
+
1
4
  Version 0.3.5
2
5
  Added small improvements to send_sms.rb usage to use flags
3
6
 
data/Manifest.txt CHANGED
@@ -7,8 +7,17 @@ config/smsc.yml
7
7
  bin/smsc_config.rb
8
8
  bin/smsc_print_config.rb
9
9
  bin/send_sms.rb
10
+ bin/send_sms_load_test.rb
11
+ bin/send_sms_http.rb
12
+ bin/sms_topic_server.rb
13
+ bin/sms_topic_server_control.rb
14
+ bin/sms_om_server_control.rb
15
+ bin/sms_om_server.rb
10
16
  lib/smsc_manager/version.rb
11
17
  lib/smsc_manager/sms.rb
18
+ lib/smsc_manager/smsc_listener.rb
19
+ lib/smsc_manager/sms_statistics_listener.rb
20
+ lib/smsc_manager/sms_send_topic.rb
12
21
  lib/smsc_manager/broadcast.rb
13
22
  lib/smsc_manager/smsc_connection.rb
14
23
  lib/smsc_manager.rb
data/bin/send_sms.rb CHANGED
@@ -40,24 +40,22 @@ require 'rubygems'
40
40
  gem 'smsc_manager'
41
41
  require 'smsc_manager'
42
42
 
43
- puts "Finding smsc to use:"
43
+ puts "Finding sms topic to use:"
44
44
  begin
45
- smsc=SmscManager::SmscConnection.factory
45
+ sms_sender=SmscManager::SmsSendTopic.new
46
46
  rescue Exception => e
47
- puts "exception found"
48
- end
49
- puts "Found smsc: #{smsc.hostname} port #{smsc.port}"
50
-
47
+ puts "exception found #{e.backtrace}"
48
+ end
51
49
  user=arg_hash[:user]
52
50
  destination=arg_hash[:msisdn]
53
51
  source=arg_hash[:source]
54
52
  text=arg_hash[:text]
55
- sms=SmscManager::Sms.new(text,destination,source)
53
+ sms_sender.send_sms(text,destination,source)
56
54
  puts "Sending user: #{user} destination: #{destination} text: #{text}"
57
- res= smsc.send(sms)
55
+ # res= smsc.send(sms)
58
56
  # puts "Response code: #{res.response} body: #{res.response_body}"
59
- puts "Response code: #{res}" if res.kind_of? String
60
- puts "pretty print response:"
61
- pp res
57
+ # puts "Response code: #{res}" if res.kind_of? String
58
+ # puts "pretty print response:"
59
+ # pp res
62
60
  # puts "Response code: #{res.} body: #{res.code}" if res.kind_of? Net::Http
63
61
 
@@ -0,0 +1,64 @@
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)
38
+ require 'pp'
39
+
40
+ require 'rubygems'
41
+ gem 'smsc_manager'
42
+ require 'smsc_manager'
43
+
44
+ puts "Finding smsc to use:"
45
+ begin
46
+ smsc=SmscManager::SmscConnection.factory
47
+ rescue Exception => e
48
+ puts "exception found"
49
+ end
50
+ puts "Found smsc: #{smsc.hostname} port #{smsc.port}"
51
+
52
+ user=arg_hash[:user]
53
+ destination=arg_hash[:msisdn]
54
+ source=arg_hash[:source]
55
+ text=arg_hash[:text]
56
+ sms=SmscManager::Sms.new(text,destination,source)
57
+ puts "Sending user: #{user} destination: #{destination} text: #{text}"
58
+ res= smsc.send(sms)
59
+ # puts "Response code: #{res.response} body: #{res.response_body}"
60
+ puts "Response code: #{res}" if res.kind_of? String
61
+ puts "pretty print response:"
62
+ pp res
63
+ # puts "Response code: #{res.} body: #{res.code}" if res.kind_of? Net::Http
64
+
@@ -0,0 +1,75 @@
1
+ #!/usr/bin/env ruby
2
+ require 'optparse'
3
+ def usage
4
+ puts "Usage: send_sms_load_test.rb -u user -m msisdn -s source -t text -c count"
5
+ puts "to test how long to send c sms"
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=count_flag=true
14
+ temp_hash = {}
15
+ opts.on("-u","--user VAL", String) {|val| temp_hash[:user ] = val
16
+ puts "user is #{val}"
17
+ user_flag=false }
18
+
19
+ opts.on("-c","--count VAL", Integer) {|val| temp_hash[:count ] = val
20
+ puts "count is #{val}"
21
+ count_flag=false }
22
+ opts.on("-m","--msisdn VAL", String) {|val| temp_hash[:msisdn ] = val
23
+ puts "msiddn is #{val}"
24
+ msisdn_flag=false }
25
+ opts.on("-s","--source VAL", String) {|val| temp_hash[:source ] = val
26
+ puts "source is #{val}"
27
+ source_flag=false }
28
+ opts.on("-t","--text VAL", String) {|val| temp_hash[:text ] = val
29
+ puts "text is #{val}"
30
+ text_flag=false }
31
+ #opts.on("-d","--database VAL", String) {|val| temp_hash[:db ] = val }
32
+ #opts.on("-p","--password VAL", String) {|val| temp_hash[:password ] = val }
33
+ #opts.on("-u","--user VAL", String) {|val| temp_hash[:user ] = val }
34
+ #puts " in test commander option parse #{port} #{url}"
35
+ opts.parse(params)
36
+ # puts " in HTTP #{hostname} port #{port} url: #{url}"
37
+ usage if user_flag or msisdn_flag or source_flag or text_flag or count_flag
38
+ return temp_hash
39
+ end
40
+ arg_hash=parse_options(ARGV)
41
+ require 'pp'
42
+
43
+ require 'rubygems'
44
+ gem 'smsc_manager'
45
+ require 'smsc_manager'
46
+
47
+ puts "Finding sms topic to use:"
48
+ begin
49
+ sms_sender=SmscManager::SmsSendTopic.new
50
+ rescue Exception => e
51
+ puts "exception found #{e.backtrace}"
52
+ end
53
+ user=arg_hash[:user]
54
+ destination=arg_hash[:msisdn]
55
+ source=arg_hash[:source]
56
+ text=arg_hash[:text]
57
+ count=arg_hash[:count]
58
+ start=Time.now
59
+ puts "Time now: #{start}"
60
+ 1.upto(count) { |c|
61
+ puts "sent #{c} messages" if c % 100 == 0
62
+ final_text = "count: #{c}: #{text} "
63
+ sms_sender.send_sms(final_text,destination,source)
64
+ }
65
+ diff = Time.now - start
66
+
67
+ puts "#{Time.now} Sent #{count} in #{diff} seconds";
68
+ # puts "Sending user: #{user} destination: #{destination} text: #{text}"
69
+ # res= smsc.send(sms)
70
+ # puts "Response code: #{res.response} body: #{res.response_body}"
71
+ # puts "Response code: #{res}" if res.kind_of? String
72
+ # puts "pretty print response:"
73
+ # pp res
74
+ # puts "Response code: #{res.} body: #{res.code}" if res.kind_of? Net::Http
75
+
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env ruby
2
+ require 'optparse'
3
+ def usage
4
+ puts "Usage: sms_topic_server.rb to start up listener "
5
+ exit
6
+ end
7
+
8
+ require 'rubygems'
9
+ gem 'smsc_manager'
10
+ require 'smsc_manager'
11
+
12
+ puts "Starting Operational Measurement (OM) server:"
13
+ # begin
14
+ sms_listener=SmscManager::SmsStatisticsListener.new.run
15
+ sms_listener.join
16
+ # rescue Exception => e
17
+ puts "exception found #{e.backtrace}"
18
+ # end
19
+
20
+
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+ require 'optparse'
3
+ require 'rubygems'
4
+ gem 'smsc_manager'
5
+ require 'smsc_manager'
6
+ gem 'daemons'
7
+ require 'daemons'
8
+ puts "#{ARGV[0]} Operational Measurement (OM) server:"
9
+ # begin
10
+ Daemons.run('sms_om_server.rb')
11
+
12
+
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env ruby
2
+ require 'optparse'
3
+ def usage
4
+ puts "Usage: sms_topic_server.rb to start up listener "
5
+ exit
6
+ end
7
+
8
+ require 'rubygems'
9
+ gem 'smsc_manager'
10
+ require 'smsc_manager'
11
+
12
+ puts "Starting topic server:"
13
+ # begin
14
+ sms_listener=SmscManager::SmscListener.new.run
15
+ sms_listener.join
16
+ # rescue Exception => e
17
+ puts "exception found #{e.backtrace}"
18
+ # end
19
+
20
+
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+ require 'optparse'
3
+ require 'rubygems'
4
+ gem 'smsc_manager'
5
+ require 'smsc_manager'
6
+ gem 'daemons'
7
+ require 'daemons'
8
+ puts "#{ARGV[0]} SMS Topic server:"
9
+ # begin
10
+ Daemons.run('sms_topic_server.rb')
11
+
12
+
@@ -40,10 +40,11 @@ class Broadcast
40
40
  puts "text is #{txt2} dest is #{dst}"
41
41
  begin
42
42
  sms=SmscManager::Sms.new(txt2,dst,self.source)
43
+ @list_queue << sms
43
44
  rescue Exception => e
44
45
  puts "bad values dst: #{dst} txt: #{txt2} msg: #{e.message}"
45
46
  end
46
- @list_queue << sms
47
+
47
48
  # puts " dst is #{dst}"
48
49
  }
49
50
  puts "populate queue list size #{@list_queue.size}"
@@ -68,8 +69,10 @@ class Broadcast
68
69
  #puts " #{Time.now}Creating retry thread: #{ctmp}"
69
70
  begin
70
71
  sms = @list_queue.pop
71
- puts "Thread #{ctmp} destination: #{sms.destination} text: #{sms.text}"
72
- self.send_sms(smsc,sms)
72
+ if sms!=nil
73
+ puts "Thread #{ctmp} destination: #{sms.destination} text: #{sms.text}"
74
+ self.send_sms(smsc,sms)
75
+ end
73
76
  end until @list_queue.empty?
74
77
  }
75
78
  end
@@ -85,7 +88,7 @@ class Broadcast
85
88
  rescue Exception => e
86
89
  puts "Exception found #{e.message}"
87
90
  ensure
88
- sleep(1)
91
+ sleep(1)
89
92
  end
90
93
  end
91
94
  end
@@ -1,3 +1,4 @@
1
+ require 'rexml/document'
1
2
  # Sms stuff for handling sms
2
3
  module SmscManager
3
4
  class InvalidPrefix < RuntimeError
@@ -35,8 +36,30 @@ class Sms
35
36
  flag=true if k }
36
37
  flag
37
38
  end
39
+ def to_xml
40
+ sms_xml = REXML::Element.new "sms"
41
+ destination_xml = REXML::Element.new "destination"
42
+ destination_xml.text=self.destination
43
+ source_xml =REXML::Element.new "source"
44
+ source_xml.text=self.source
45
+ text_xml =REXML::Element.new "text"
46
+ text_xml.text=self.text
47
+ sms_xml.add_element destination_xml
48
+ sms_xml.add_element source_xml
49
+ sms_xml.add_element text_xml
50
+ sms_xml.to_s
51
+ # doc= REXML::Document.new sms_xml.to_s
52
+ # doc.to_s
53
+ end
54
+ def self.load_xml(xml_string)
55
+ doc=REXML::Document.new(xml_string)
56
+ dest=REXML::XPath.first(doc, "//destination").text
57
+ src=REXML::XPath.first(doc, "//source").text
58
+ text=REXML::XPath.first(doc, "//text").text
59
+ sms=SmscManager::Sms.new(text,dest,src)
60
+ end
38
61
  def limit_text(val)
39
- #limit to 300 characters
62
+ #limit to @@MAX_SIZE characters
40
63
  ret=""
41
64
  size=[val.size,@@MAX_SIZE].min-1
42
65
  0.upto(size) do |i|
@@ -51,6 +74,7 @@ class Sms
51
74
  # result=result.gsub(/\n/," ") # replace all new lines return result
52
75
  # result=result.gsub(/\r/," ") # replace all new lines return result
53
76
  result=result.gsub(/_/,"-") # replace all new lines return result
77
+ result=result.gsub(/-/," ") # replace all - with space...angelo bug return result
54
78
  # result=result4.gsub(/\//,"") # replace all new lines return result
55
79
  limit_text(result)
56
80
  end
@@ -0,0 +1,24 @@
1
+ require 'yaml'
2
+ require 'rubygems'
3
+ gem 'stomp'
4
+ require 'stomp'
5
+ # This sends the sms to a activemq topic
6
+ module SmscManager
7
+ class SmsSendTopic
8
+ attr_accessor :conn
9
+ #need to define topic, host properly
10
+ @@TOPIC='/topic/sms'
11
+ def initialize
12
+ self.conn = Stomp::Connection.open '', '', 'localhost', 61613, false
13
+ # self.conn.subscribe @@TOPIC, { :ack =>"auto" }
14
+ puts "finished initializing"
15
+ end
16
+ def send_sms(text,destination,source)
17
+ sms=SmscManager::Sms.new(text,destination,source)
18
+ msgbody=sms.to_xml
19
+ # puts "message body is #{msgbody}"
20
+ self.conn.send @@TOPIC, msgbody, {'persistent'=>'false'}
21
+ end #send_sms
22
+ end # smsc listener
23
+
24
+ end #module
@@ -0,0 +1,51 @@
1
+ require 'yaml'
2
+ require 'rubygems'
3
+ gem 'stomp'
4
+ require 'stomp'
5
+
6
+ module SmscManager
7
+ class SmsStatisticsListener
8
+ @@MAX_THROUGHPUT =5 # in messages per second
9
+ attr_accessor :conn, :count, :source
10
+ #need to define topic, host properly
11
+ @@TOPIC='/topic/sms'
12
+ def initialize
13
+ self.conn = Stomp::Connection.open '', '', 'localhost', 61613, false
14
+ self.count = 0
15
+ self.conn.subscribe @@TOPIC, { :ack =>"auto" }
16
+ self.source ={}
17
+ puts "finished initializing"
18
+ end
19
+ def statistics(sms)
20
+ self.count+=1
21
+ self.source[sms.source] = 0 if !self.source.key?(sms.source)
22
+ self.source[sms.source] += 1
23
+ end
24
+ def report
25
+ puts "SMS OM Report: #{Time.now}"
26
+ puts "message count is: #{count}"
27
+ self.source.each_pair {|i,val|
28
+ puts " source #{i} count #{val}"
29
+ }
30
+ end
31
+ def run
32
+ Thread.new {
33
+ while true #loop forever
34
+ # puts "before receive"
35
+ msg = self.conn.receive
36
+ # puts "after receive"
37
+ begin
38
+ sms=SmscManager::Sms.load_xml(msg.body)
39
+ statistics(sms)
40
+ report if self.count % 100 == 0
41
+ # puts "sms text is: #{sms.text} dest is: #{sms.destination} result is: #{res}"
42
+ rescue Exception => e
43
+ puts "exception found #{e.backtrace}"
44
+ end
45
+ end # while
46
+ }
47
+ # t.join # wait for t to die..
48
+ end #run
49
+ end # smsc listener
50
+
51
+ end #module
@@ -0,0 +1,40 @@
1
+ require 'yaml'
2
+ require 'rubygems'
3
+ gem 'stomp'
4
+ require 'stomp'
5
+
6
+ module SmscManager
7
+ class SmscListener
8
+ @@MAX_THROUGHPUT =5 # in messages per second
9
+ SLEEP_TIME=1/@@MAX_THROUGHPUT #sleep x seconds to slow down system
10
+ attr_accessor :conn, :smsc, :count
11
+ #need to define topic, host properly
12
+ @@TOPIC='/topic/sms'
13
+ def initialize
14
+ self.conn = Stomp::Connection.open '', '', 'localhost', 61613, false
15
+ self.count = 0
16
+ self.conn.subscribe @@TOPIC, { :ack =>"auto" }
17
+ self.smsc=SmscManager::SmscConnection.factory
18
+ puts "finished initializing"
19
+ end
20
+ def run
21
+ Thread.new {
22
+ while true #loop forever
23
+ # puts "before receive"
24
+ msg = self.conn.receive
25
+ # puts "after receive"
26
+ begin
27
+ sms=SmscManager::Sms.load_xml(msg.body)
28
+ res= self.smsc.send(sms)
29
+ sleep(SLEEP_TIME) #only 5 messages per second max
30
+ # puts "sms text is: #{sms.text} dest is: #{sms.destination} result is: #{res}"
31
+ rescue Exception => e
32
+ puts "exception found #{e.backtrace}"
33
+ end
34
+ end # while
35
+ }
36
+ # t.join # wait for t to die..
37
+ end #run
38
+ end # smsc listener
39
+
40
+ end #module
@@ -1,8 +1,8 @@
1
1
  module SmscManager #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
- MINOR = 3
5
- TINY = 6
4
+ MINOR = 4
5
+ TINY = 0
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -6,6 +6,15 @@ class SmscManagerTest < Test::Unit::TestCase
6
6
  @smsc=SmscManager::SmscConnection.factory
7
7
  end
8
8
  # Replace this with your real tests.
9
+ def test_sms_to_xml
10
+ sms=SmscManager::Sms.new('hello scott','09996557890','websource')
11
+ c=sms.to_xml
12
+ puts "sms to xml is #{c}"
13
+ assert_match "destination", c
14
+ sms2=SmscManager::Sms.load_xml(c)
15
+ assert sms.destination == sms2.destination, 'to from xml did not work'
16
+ assert sms.text == sms2.text, 'to from xml did not work'
17
+ end
9
18
  def test_sms_send
10
19
  smsc_new=@smsc
11
20
  sms=SmscManager::Sms.new('hello scott','09996557890','websource')
metadata CHANGED
@@ -1,10 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.2
2
+ 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.3.6
7
- date: 2007-04-24 00:00:00 +08:00
6
+ version: 0.4.0
7
+ date: 2007-09-18 00:00:00 +08:00
8
8
  summary: connection to smsc via http using kannel
9
9
  require_paths:
10
10
  - lib
@@ -38,8 +38,17 @@ files:
38
38
  - bin/smsc_config.rb
39
39
  - bin/smsc_print_config.rb
40
40
  - bin/send_sms.rb
41
+ - bin/send_sms_load_test.rb
42
+ - bin/send_sms_http.rb
43
+ - bin/sms_topic_server.rb
44
+ - bin/sms_topic_server_control.rb
45
+ - bin/sms_om_server_control.rb
46
+ - bin/sms_om_server.rb
41
47
  - lib/smsc_manager/version.rb
42
48
  - lib/smsc_manager/sms.rb
49
+ - lib/smsc_manager/smsc_listener.rb
50
+ - lib/smsc_manager/sms_statistics_listener.rb
51
+ - lib/smsc_manager/sms_send_topic.rb
43
52
  - lib/smsc_manager/broadcast.rb
44
53
  - lib/smsc_manager/smsc_connection.rb
45
54
  - lib/smsc_manager.rb
@@ -48,14 +57,23 @@ files:
48
57
  - examples/receive_sms_controller.rb
49
58
  test_files:
50
59
  - test/smsc_manager_test.rb
51
- rdoc_options: []
52
-
53
- extra_rdoc_files: []
54
-
60
+ rdoc_options:
61
+ - --main
62
+ - README.txt
63
+ extra_rdoc_files:
64
+ - README.txt
65
+ - CHANGELOG.txt
66
+ - Manifest.txt
55
67
  executables:
56
68
  - smsc_config.rb
57
69
  - smsc_print_config.rb
58
70
  - send_sms.rb
71
+ - send_sms_load_test.rb
72
+ - send_sms_http.rb
73
+ - sms_topic_server.rb
74
+ - sms_topic_server_control.rb
75
+ - sms_om_server_control.rb
76
+ - sms_om_server.rb
59
77
  extensions: []
60
78
 
61
79
  requirements: []