smsc_manager 0.3.1 → 0.3.2
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/Manifest.txt
CHANGED
@@ -4,11 +4,12 @@ CHANGELOG.txt
|
|
4
4
|
Manifest.txt
|
5
5
|
setup.rb
|
6
6
|
config/smsc.yml
|
7
|
-
bin/
|
8
|
-
bin/
|
7
|
+
bin/smsc_config.rb
|
8
|
+
bin/smsc_print_config.rb
|
9
9
|
bin/send_sms.rb
|
10
10
|
lib/smsc_manager/version.rb
|
11
11
|
lib/smsc_manager/sms.rb
|
12
|
+
lib/smsc_manager/broadcast.rb
|
12
13
|
lib/smsc_manager/smsc_connection.rb
|
13
14
|
lib/smsc_manager.rb
|
14
15
|
test/test_helper.rb
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# Sms stuff for handling sms
|
2
|
+
#require 'monitor'
|
3
|
+
require 'thread'
|
4
|
+
module SmscManager
|
5
|
+
class UseSend_SmsForListofSize1 < RuntimeError
|
6
|
+
end
|
7
|
+
# this class helps to broadcast sms to list
|
8
|
+
class Broadcast
|
9
|
+
@@MAX_THROUGHPUT =5 # in messages per second
|
10
|
+
attr_accessor :text, :source, :list, :num_threads
|
11
|
+
def initialize(txt,lst,src='888')
|
12
|
+
self.text=txt
|
13
|
+
self.list=lst
|
14
|
+
raise UseSend_SmsForListofSize1.new("use send_sms for lists of size 1") if lst.size==1
|
15
|
+
self.source=src
|
16
|
+
self.calculate_threads
|
17
|
+
@list_queue=Queue.new
|
18
|
+
self.populate_queue(lst)
|
19
|
+
self.send
|
20
|
+
# raise InvalidPrefix.new("invalid prefix: valid prefix area:" + Sms.valid ) if !prefix_test
|
21
|
+
end
|
22
|
+
# populate thread safe queue
|
23
|
+
def populate_queue(lst)
|
24
|
+
|
25
|
+
# puts "list is #{lst}"
|
26
|
+
lst.each {|dst| @list_queue << dst
|
27
|
+
# puts " dst is #{dst}"
|
28
|
+
}
|
29
|
+
puts "populate queue list size #{@list_queue.size}"
|
30
|
+
end
|
31
|
+
#calculate number of threads
|
32
|
+
def calculate_threads
|
33
|
+
self.num_threads = @@MAX_THROUGHPUT +1 #sleep 1 after every message
|
34
|
+
self.num_threads =1 if self.list.size<=@@MAX_THROUGHPUT
|
35
|
+
end
|
36
|
+
|
37
|
+
# send using number of threads
|
38
|
+
def send
|
39
|
+
smsc=SmscManager::SmscConnection.factory
|
40
|
+
c=0
|
41
|
+
thread_mgr=[]
|
42
|
+
puts "queue size is #{@list_queue.size} "
|
43
|
+
puts "queue empty is #{@list_queue.empty?}"
|
44
|
+
while c < self.num_threads
|
45
|
+
thread_mgr << Thread.new(c+=1) { |ctmp|
|
46
|
+
#puts " #{Time.now}Creating retry thread: #{ctmp}"
|
47
|
+
begin
|
48
|
+
dest = @list_queue.pop
|
49
|
+
sms=SmscManager::Sms.new(self.text,dest,self.source)
|
50
|
+
puts "Thread #{ctmp} destination: #{dest} text: #{self.text}"
|
51
|
+
self.send_sms(smsc,sms)
|
52
|
+
end until @list_queue.empty?
|
53
|
+
}
|
54
|
+
end
|
55
|
+
thread_mgr.each { |aThread| aThread.join if aThread.alive? } #wait till all end
|
56
|
+
end
|
57
|
+
protected
|
58
|
+
def send_sms(smsc,sms)
|
59
|
+
begin
|
60
|
+
res= smsc.send(sms)
|
61
|
+
rescue Exception => e
|
62
|
+
puts "Exception found #{e.message}"
|
63
|
+
ensure
|
64
|
+
sleep(1)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
data/lib/smsc_manager/version.rb
CHANGED
data/test/smsc_manager_test.rb
CHANGED
@@ -8,7 +8,7 @@ class SmscManagerTest < Test::Unit::TestCase
|
|
8
8
|
# Replace this with your real tests.
|
9
9
|
def test_sms_send
|
10
10
|
smsc_new=@smsc
|
11
|
-
sms=SmscManager::Sms.new('hello scott','
|
11
|
+
sms=SmscManager::Sms.new('hello scott','09996557890','websource')
|
12
12
|
begin
|
13
13
|
r=smsc_new.test(sms)
|
14
14
|
rescue Exception
|
@@ -37,9 +37,25 @@ class SmscManagerTest < Test::Unit::TestCase
|
|
37
37
|
|
38
38
|
end
|
39
39
|
def test_sms_text_nil
|
40
|
-
sms=SmscManager::Sms.new(nil,'
|
41
|
-
assert sms.text==" ", "text not correct"
|
40
|
+
sms=SmscManager::Sms.new(nil,'09996557890','websource')
|
41
|
+
assert sms.text==" ", "text not correct for nil"
|
42
42
|
end
|
43
|
+
def test_broadcast_two
|
44
|
+
list = %w(9991 9992)
|
45
|
+
b=SmscManager::Broadcast.new("hello there",list)
|
46
|
+
end
|
47
|
+
def test_broadcast_five
|
48
|
+
list = %w(9991 9992 9993 9994 9995 9996)
|
49
|
+
b=SmscManager::Broadcast.new("hello there",list)
|
50
|
+
end
|
51
|
+
def test_broadcast_ten
|
52
|
+
list = %w(9991 9992 9993 9994 9995 9996 99910 99920 99930 99940 99950 99960)
|
53
|
+
b=SmscManager::Broadcast.new("hello there",list)
|
54
|
+
end
|
55
|
+
def test_broadcast_six
|
56
|
+
list = %w(9991 9992 9993 9994 9995 9996 9997)
|
57
|
+
b=SmscManager::Broadcast.new("second hello there",list)
|
58
|
+
end
|
43
59
|
def test_find_google_mod
|
44
60
|
@smsc.hostname='www.google.com'
|
45
61
|
#assert @smsc.save==true, 'could not save google mod'
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.2
|
|
3
3
|
specification_version: 1
|
4
4
|
name: smsc_manager
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.3.
|
7
|
-
date: 2007-03-
|
6
|
+
version: 0.3.2
|
7
|
+
date: 2007-03-21 00:00:00 +08:00
|
8
8
|
summary: connection to smsc via http using kannel
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -35,11 +35,12 @@ files:
|
|
35
35
|
- Manifest.txt
|
36
36
|
- setup.rb
|
37
37
|
- config/smsc.yml
|
38
|
-
- bin/
|
39
|
-
- bin/
|
38
|
+
- bin/smsc_config.rb
|
39
|
+
- bin/smsc_print_config.rb
|
40
40
|
- bin/send_sms.rb
|
41
41
|
- lib/smsc_manager/version.rb
|
42
42
|
- lib/smsc_manager/sms.rb
|
43
|
+
- lib/smsc_manager/broadcast.rb
|
43
44
|
- lib/smsc_manager/smsc_connection.rb
|
44
45
|
- lib/smsc_manager.rb
|
45
46
|
- test/test_helper.rb
|
@@ -52,8 +53,8 @@ rdoc_options: []
|
|
52
53
|
extra_rdoc_files: []
|
53
54
|
|
54
55
|
executables:
|
55
|
-
-
|
56
|
-
-
|
56
|
+
- smsc_config.rb
|
57
|
+
- smsc_print_config.rb
|
57
58
|
- send_sms.rb
|
58
59
|
extensions: []
|
59
60
|
|