smsc_manager 0.4.5 → 0.4.7

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,5 @@
1
+ Version 0.4.6
2
+ fix blank destination
1
3
  Version 0.4.3
2
4
  improve om server and message handling characteristics
3
5
 
data/Manifest.txt CHANGED
@@ -6,8 +6,10 @@ setup.rb
6
6
  config/smsc.yml
7
7
  bin/smsc_config.rb
8
8
  bin/smsc_print_config.rb
9
+ bin/send_sms_post.rb
9
10
  bin/send_sms.rb
10
11
  bin/send_sms_load_test.rb
12
+ bin/sms_print_xml.rb
11
13
  bin/send_sms_http.rb
12
14
  bin/sms_topic_server.rb
13
15
  bin/sms_topic_server_control.rb
@@ -15,6 +15,9 @@ def parse_options(params)
15
15
  opts.on("-u","--user VAL", String) {|val| temp_hash[:user ] = val
16
16
  puts "user is #{val}"
17
17
  user_flag=false }
18
+ opts.on("-h","--host VAL", String) {|val| temp_hash[:host ] = val
19
+ puts "host is #{val}"
20
+ }
18
21
 
19
22
  opts.on("-c","--count VAL", Integer) {|val| temp_hash[:count ] = val
20
23
  puts "count is #{val}"
@@ -46,7 +49,7 @@ require 'smsc_manager'
46
49
 
47
50
  puts "Finding sms topic to use:"
48
51
  begin
49
- sms_sender=SmscManager::SmsSendTopic.new
52
+ sms_sender=SmscManager::SmsSendTopic.new(arg_hash)
50
53
  rescue Exception => e
51
54
  puts "exception found #{e.backtrace}"
52
55
  end
@@ -0,0 +1,72 @@
1
+ #!/usr/bin/env ruby
2
+ 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)
46
+ require 'pp'
47
+
48
+ require 'rubygems'
49
+ gem 'smsc_manager'
50
+ require 'smsc_manager'
51
+ require 'net/http'
52
+
53
+ user=arg_hash[:user]
54
+ destination=arg_hash[:msisdn]
55
+ source=arg_hash[:source]
56
+ text=arg_hash[:text]
57
+ puts "create stomp message"
58
+ m=SmscManager::SmsSendTopic.create_stomp_message(text,destination,source)
59
+ puts "message is #{m.to_xml}"
60
+ 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
72
+
data/bin/sms_om_server.rb CHANGED
@@ -13,7 +13,7 @@ require 'smsc_manager'
13
13
  # begin
14
14
  # can add additional options to change host/port etc
15
15
  sms_listener=SmscManager::SmsStatisticsListener.new({:topic => '/topic/sms'}).run
16
- sms_listener.join
16
+ # sms_listener.join
17
17
  # rescue Exception => e
18
18
  puts "exception found #{e.backtrace}"
19
19
  # end
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+ gem 'smsc_manager'
4
+ require 'smsc_manager'
5
+ #require 'lib/smsc_manager/smsc_connection'
6
+ #require 'lib/smsc_manager/sms'
7
+ require 'pp'
8
+ puts "printing sms xml configuration"
9
+ puts "#{SmscManager::SmsSendTopic.print_example_xml}"
10
+
@@ -8,7 +8,7 @@ module SmscManager
8
8
  class BroadcastTopic
9
9
  @@MAX_THROUGHPUT =5 # in messages per second
10
10
  # old attr_accessor :text, :source, :list, :num_threads, :attempts, :sent
11
- attr_accessor :text, :source, :list, :num_threads, :attempts, :sent
11
+ attr_accessor :text, :source, :list, :num_threads, :attempts, :sent, :sms_sender
12
12
  def common_setup(src)
13
13
  @guard = Mutex.new
14
14
  self.attempts=0
@@ -33,26 +33,30 @@ class BroadcastTopic
33
33
  def populate_topic(lst)
34
34
  # puts "list is #{lst}"
35
35
  arg_hash = {:host => 'localhost'}
36
- sms_sender=SmscManager::SmsSendTopic.new(arg_hash)
36
+ self.sms_sender=SmscManager::SmsSendTopic.new(arg_hash)
37
37
  lst.each {|key, val|
38
38
  # txt=line[1] ||
39
39
  # if value set then send it else send default text value
40
40
  txt2 = val==nil ? self.text : val
41
41
  dst = key
42
- puts "text is #{txt2} dest is #{dst}"
43
- begin
44
- sms=SmscManager::Sms.new(txt2,dst,self.source)
45
- sms_sender.send_topic(sms)
46
- self.attempts+=1
47
- self.sent+=1
48
- rescue Exception => e
49
- self.sent-=1
50
- puts "bad values dst: #{dst} txt: #{txt2} msg: #{e.message}"
51
- end
42
+ # puts "text is #{txt2} dest is #{dst}"
43
+ send_it(txt2,dst) if SmscManager::Sms.check_destination(dst)
52
44
 
53
45
  # puts " dst is #{dst}"
54
46
  }
55
47
  puts "populate topic sent #{self.sent}"
56
48
  end
49
+ def send_it(txt,dst)
50
+ # puts "hello from send it"
51
+ begin
52
+ sms=SmscManager::Sms.new(txt,dst,self.source)
53
+ self.sms_sender.send_topic(sms)
54
+ self.attempts+=1
55
+ self.sent+=1
56
+ rescue Exception => e
57
+ self.sent-=1
58
+ puts "bad values dst: #{dst} txt: #{txt2} msg: #{e.message}"
59
+ end
60
+ end
57
61
  end
58
62
  end
@@ -22,9 +22,10 @@ class Sms
22
22
  @@msisdn_valid_prefix.each {|t| sentence << t <<" " }
23
23
  sentence
24
24
  end
25
- def starts_with?(prefix)
25
+ def self.starts_with?(prefix,dest)
26
26
  prefix = prefix.to_s
27
- self.destination[0, prefix.length] == prefix
27
+ return false if dest == nil
28
+ dest[0, prefix.length] == prefix
28
29
  end
29
30
  def initialize(txt,dest,src='888')
30
31
  self.orig_txt=txt
@@ -34,9 +35,12 @@ class Sms
34
35
  raise InvalidPrefix.new("invalid prefix: valid prefix area:" + Sms.valid ) if !prefix_test
35
36
  end
36
37
  def prefix_test
38
+ Sms.check_destination(self.destination)
39
+ end
40
+ def self.check_destination(dst)
37
41
  flag = false
38
42
 
39
- @@msisdn_valid_prefix.each { |w| k= self.starts_with? w
43
+ @@msisdn_valid_prefix.each { |w| k= Sms.starts_with? w , dst
40
44
  flag=true if k }
41
45
  flag
42
46
  end
@@ -10,6 +10,8 @@ class SmsSendTopic
10
10
  attr_accessor :conn
11
11
  #need to define topic, host properly
12
12
  @@TOPIC='/topic/sms'
13
+ # must be defined as method in sms_listener
14
+ @@STOMP_SMS_MESSAGE='stomp_SMS'
13
15
  def initialize(options={})
14
16
  # set up variables using hash
15
17
  host = options[:host]==nil ? 'localhost' : options[:host]
@@ -31,10 +33,28 @@ class SmsSendTopic
31
33
  def send_topic(sms)
32
34
  #sms=SmscManager::Sms.new(text,destination,source)
33
35
  # msgbody=sms.to_xml
34
- m=StompMessage::Message.new('stomp_SMS', sms.to_xml)
36
+ m=StompMessage::Message.new(@@STOMP_SMS_MESSAGE, sms.to_xml)
35
37
  # puts "message body is #{msgbody}"
36
38
  self.conn.send @@TOPIC, m.to_xml, {'persistent'=>'false'}
37
39
  end #send_sms
40
+ # simple script to show xml message
41
+ def self.create_stomp_message(txt,dest,src)
42
+ sms=SmscManager::Sms.new(txt,dest,src)
43
+ m=StompMessage::Message.new(@@STOMP_SMS_MESSAGE, sms.to_xml)
44
+ end
45
+ def self.print_example_xml
46
+ text= "hello there #{Time.now}"
47
+ destination = "639993130030" #must be valid destination
48
+ source = '888'
49
+ sms=SmscManager::Sms.new(text,destination,source)
50
+ m=SmscManager::SmsSendTopic.create_stomp_message( text,destination,source)
51
+ result = "------------ SMS XML----------------\n"
52
+ result << "#{sms.to_xml}\n"
53
+ result << "------------STOMP XML--------------\n"
54
+ result << "#{m.to_xml}\n"
55
+ result << "------------END--------------------"
56
+ result
57
+ end
38
58
  end # smsc listener
39
59
 
40
60
  end #module
@@ -23,17 +23,18 @@ class SmsStatisticsListener < StompMessage::StompStatisticsServer
23
23
  # self.source[sms.source] += 1
24
24
  end
25
25
  def stomp_REPORT(msg, stomp_msg)
26
- super(msg, stomp_msg)
27
- puts " --------------------------------- details"
26
+ result = super(msg, stomp_msg)
27
+ #puts " --------------------------------- details"
28
28
  # self.source.each_pair { |key,val| puts " key: #{key} value: #{val}"}
29
29
  # puts " --------------------------------- "
30
+
30
31
  end
31
32
  def stomp_SMS(msg, stomp_msg)
32
33
  puts "msg command #{msg.command} msg body #{msg.body}" if @debug
33
34
  sms=SmscManager::Sms.load_xml(msg.body)
34
35
  create_m_statistics(sms)
35
36
  puts "#{self.topic} OM report stomp_SMS" if @debug
36
- stomp_REPORT(msg) if self.msg_count % 100 == 0
37
+ # stomp_REPORT(msg) if self.msg_count % 100 == 0
37
38
  end
38
39
  end # smsc listener
39
40
 
@@ -17,6 +17,16 @@ class SmscListener < StompMessage::StompServer
17
17
  self.smsc=SmscManager::SmscConnection.factory
18
18
  puts "finished initializing"
19
19
  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
20
30
  # name is message command
21
31
  def stomp_SMS(msg, stomp_msg)
22
32
  sms=SmscManager::Sms.load_xml(msg.body)
@@ -2,7 +2,7 @@ module SmscManager #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 4
5
- TINY = 5
5
+ TINY = 7
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -65,6 +65,18 @@ class SmscManagerTest < Test::Unit::TestCase
65
65
  b=SmscManager::Broadcast.new('888',list,"hello there")
66
66
  assert b.attempts ==2, "did not send two sms"
67
67
  end
68
+ def test_broadcast_blank
69
+ list = %w(9991 '')
70
+ b=SmscManager::BroadcastTopic.new('888',list,"hello there")
71
+ assert b.attempts ==1, "did not send one sms"
72
+ end
73
+ def test_broadcast_nil
74
+ list = %w(9991 nil)
75
+ list << nil
76
+ b=SmscManager::BroadcastTopic.new('888',list,"hello there")
77
+ assert b.attempts ==1, "did not send one sms"
78
+ end
79
+
68
80
  def test_broadcast_topic_one
69
81
  list = %w(9991 9992)
70
82
  b=SmscManager::BroadcastTopic.new('888',list,"hello there")
@@ -94,5 +106,12 @@ class SmscManagerTest < Test::Unit::TestCase
94
106
  @smsc.hostname='www.google.com'
95
107
  #assert @smsc.save==true, 'could not save google mod'
96
108
  assert @smsc.hostname == 'www.google.com', "assign not working"
109
+
97
110
  end
111
+ def test_print_xml
112
+ b=SmscManager::SmsSendTopic.print_example_xml
113
+ puts "#{b}"
114
+ res = b.include? "<sms>"
115
+ assert res, "xml looks wrong"
116
+ end
98
117
  end
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.4.5
7
- date: 2007-09-24 00:00:00 +08:00
6
+ version: 0.4.7
7
+ date: 2007-10-01 00:00:00 +08:00
8
8
  summary: connection to smsc via http using kannel
9
9
  require_paths:
10
10
  - lib
@@ -37,8 +37,10 @@ files:
37
37
  - config/smsc.yml
38
38
  - bin/smsc_config.rb
39
39
  - bin/smsc_print_config.rb
40
+ - bin/send_sms_post.rb
40
41
  - bin/send_sms.rb
41
42
  - bin/send_sms_load_test.rb
43
+ - bin/sms_print_xml.rb
42
44
  - bin/send_sms_http.rb
43
45
  - bin/sms_topic_server.rb
44
46
  - bin/sms_topic_server_control.rb
@@ -69,8 +71,10 @@ extra_rdoc_files:
69
71
  executables:
70
72
  - smsc_config.rb
71
73
  - smsc_print_config.rb
74
+ - send_sms_post.rb
72
75
  - send_sms.rb
73
76
  - send_sms_load_test.rb
77
+ - sms_print_xml.rb
74
78
  - send_sms_http.rb
75
79
  - sms_topic_server.rb
76
80
  - sms_topic_server_control.rb