smsc_manager 0.3.3 → 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/smsc_manager/broadcast.rb +28 -15
- data/lib/smsc_manager/sms.rb +3 -2
- data/lib/smsc_manager/version.rb +1 -1
- data/test/smsc_manager_test.rb +9 -4
- metadata +2 -2
@@ -7,31 +7,44 @@ module SmscManager
|
|
7
7
|
# this class helps to broadcast sms to list
|
8
8
|
class Broadcast
|
9
9
|
@@MAX_THROUGHPUT =5 # in messages per second
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
self.list=lst
|
10
|
+
# old attr_accessor :text, :source, :list, :num_threads, :attempts, :sent
|
11
|
+
attr_accessor :text, :source, :list, :num_threads, :attempts, :sent
|
12
|
+
def common_setup(src)
|
13
|
+
@guard = Mutex.new
|
15
14
|
self.attempts=0
|
16
15
|
self.sent=0
|
17
|
-
# puts "lst.size is #{lst.size}"
|
18
|
-
raise BadList.new("use send_sms for lists of size 1") if lst.class==String
|
19
16
|
self.source=src
|
20
|
-
|
17
|
+
end
|
18
|
+
# initialize with list of destionations, texts eg different text for each destination
|
19
|
+
# initialize with common text and list of destinations
|
20
|
+
def initialize(src, lst, txt=nil)
|
21
|
+
common_setup(src)
|
22
|
+
self.list=lst
|
23
|
+
self.text=txt
|
24
|
+
# puts "lst.size is #{lst.size}"
|
25
|
+
raise BadList.new("use send_sms for lists of size 1") if lst.class==String
|
21
26
|
@list_queue=Queue.new
|
22
|
-
self.populate_queue(lst)
|
27
|
+
self.populate_queue(lst)
|
23
28
|
self.send
|
24
29
|
# raise InvalidPrefix.new("invalid prefix: valid prefix area:" + Sms.valid ) if !prefix_test
|
25
30
|
end
|
31
|
+
|
26
32
|
# populate thread safe queue
|
27
33
|
def populate_queue(lst)
|
28
|
-
|
29
|
-
|
30
|
-
|
34
|
+
puts "list is #{lst}"
|
35
|
+
lst.each {|key, val|
|
36
|
+
# txt=line[1] ||
|
37
|
+
# if value set then send it else send default text value
|
38
|
+
txt2 = val==nil ? self.text : val
|
39
|
+
dst = key
|
40
|
+
puts "text is #{txt2} dest is #{dst}"
|
41
|
+
sms=SmscManager::Sms.new(txt2,dst,self.source)
|
42
|
+
@list_queue << sms
|
31
43
|
# puts " dst is #{dst}"
|
32
44
|
}
|
33
45
|
puts "populate queue list size #{@list_queue.size}"
|
34
46
|
end
|
47
|
+
|
35
48
|
#calculate number of threads
|
36
49
|
def calculate_threads
|
37
50
|
self.num_threads = @@MAX_THROUGHPUT +1 #sleep 1 after every message
|
@@ -40,6 +53,7 @@ class Broadcast
|
|
40
53
|
|
41
54
|
# send using number of threads
|
42
55
|
def send
|
56
|
+
self.calculate_threads
|
43
57
|
smsc=SmscManager::SmscConnection.factory
|
44
58
|
c=0
|
45
59
|
thread_mgr=[]
|
@@ -49,9 +63,8 @@ class Broadcast
|
|
49
63
|
thread_mgr << Thread.new(c+=1) { |ctmp|
|
50
64
|
#puts " #{Time.now}Creating retry thread: #{ctmp}"
|
51
65
|
begin
|
52
|
-
|
53
|
-
sms
|
54
|
-
puts "Thread #{ctmp} destination: #{dest} text: #{self.text}"
|
66
|
+
sms = @list_queue.pop
|
67
|
+
puts "Thread #{ctmp} destination: #{sms.destination} text: #{sms.text}"
|
55
68
|
self.send_sms(smsc,sms)
|
56
69
|
end until @list_queue.empty?
|
57
70
|
}
|
data/lib/smsc_manager/sms.rb
CHANGED
@@ -2,9 +2,10 @@
|
|
2
2
|
module SmscManager
|
3
3
|
class InvalidPrefix < RuntimeError
|
4
4
|
end
|
5
|
-
# this class defines
|
5
|
+
# this class defines creating a sms
|
6
|
+
# and strips out the unnecessary junk
|
6
7
|
class Sms
|
7
|
-
@@MAX_SIZE=1500 # 3*160 # max
|
8
|
+
@@MAX_SIZE=1500 # 3*160 # max 1500 characters, change if your smsc suports less
|
8
9
|
@@msisdn_valid_prefix= %w{ 63999 999 0999 1000 888 +63999 }
|
9
10
|
attr_accessor :text, :source, :destination, :orig_txt
|
10
11
|
def self.max_length
|
data/lib/smsc_manager/version.rb
CHANGED
data/test/smsc_manager_test.rb
CHANGED
@@ -42,22 +42,27 @@ class SmscManagerTest < Test::Unit::TestCase
|
|
42
42
|
end
|
43
43
|
def test_broadcast_two
|
44
44
|
list = %w(9991 9992)
|
45
|
-
b=SmscManager::Broadcast.new("hello there"
|
45
|
+
b=SmscManager::Broadcast.new('888',list,"hello there")
|
46
46
|
assert b.attempts ==2, "did not send two sms"
|
47
47
|
end
|
48
48
|
def test_broadcast_five
|
49
49
|
list = %w(9991 9992 9993 9994 9995)
|
50
|
-
b=SmscManager::Broadcast.new("hello there"
|
50
|
+
b=SmscManager::Broadcast.new('888',list,"hello there")
|
51
51
|
assert b.attempts ==5, "did not send 5 sms"
|
52
52
|
end
|
53
53
|
def test_broadcast_12
|
54
54
|
list = %w(9991 9992 9993 9994 9995 9996 99910 99920 99930 99940 99950 99960)
|
55
|
-
b=SmscManager::Broadcast.new("hello there"
|
55
|
+
b=SmscManager::Broadcast.new('888',list,"hello there")
|
56
56
|
assert b.attempts ==12, "did not send 12 sms"
|
57
57
|
end
|
58
|
+
def test_broadcast_multi_text
|
59
|
+
list = {'9991' => 'text1', '9992' => 'text2', '9993' => 'text3'}
|
60
|
+
b=SmscManager::Broadcast.new('888',list)
|
61
|
+
assert b.attempts ==3, "did not send 3 sms"
|
62
|
+
end
|
58
63
|
def test_broadcast_six
|
59
64
|
list = %w(9991 9992 9993 9994 9995 9996)
|
60
|
-
b=SmscManager::Broadcast.new("second hello there"
|
65
|
+
b=SmscManager::Broadcast.new('888',list,"second hello there")
|
61
66
|
assert b.attempts ==6, "did not send 6 sms"
|
62
67
|
end
|
63
68
|
def test_find_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.4
|
7
|
+
date: 2007-03-22 00:00:00 +08:00
|
8
8
|
summary: connection to smsc via http using kannel
|
9
9
|
require_paths:
|
10
10
|
- lib
|