smsc_manager 0.3.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,16 +2,20 @@
2
2
  #require 'monitor'
3
3
  require 'thread'
4
4
  module SmscManager
5
- class UseSend_SmsForListofSize1 < RuntimeError
5
+ class BadList < RuntimeError
6
6
  end
7
7
  # this class helps to broadcast sms to list
8
8
  class Broadcast
9
9
  @@MAX_THROUGHPUT =5 # in messages per second
10
- attr_accessor :text, :source, :list, :num_threads
10
+ attr_accessor :text, :source, :list, :num_threads, :attempts, :sent
11
11
  def initialize(txt,lst,src='888')
12
+ @guard = Mutex.new
12
13
  self.text=txt
13
14
  self.list=lst
14
- raise UseSend_SmsForListofSize1.new("use send_sms for lists of size 1") if lst.size==1
15
+ self.attempts=0
16
+ 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
15
19
  self.source=src
16
20
  self.calculate_threads
17
21
  @list_queue=Queue.new
@@ -39,8 +43,8 @@ class Broadcast
39
43
  smsc=SmscManager::SmscConnection.factory
40
44
  c=0
41
45
  thread_mgr=[]
42
- puts "queue size is #{@list_queue.size} "
43
- puts "queue empty is #{@list_queue.empty?}"
46
+ # puts "queue size is #{@list_queue.size} "
47
+ # puts "queue empty is #{@list_queue.empty?}"
44
48
  while c < self.num_threads
45
49
  thread_mgr << Thread.new(c+=1) { |ctmp|
46
50
  #puts " #{Time.now}Creating retry thread: #{ctmp}"
@@ -57,7 +61,10 @@ class Broadcast
57
61
  protected
58
62
  def send_sms(smsc,sms)
59
63
  begin
64
+
60
65
  res= smsc.send(sms)
66
+ @guard.synchronize { self.attempts +=1
67
+ self.sent +=1 if res.kind_of? Net::HTTPAccepted }
61
68
  rescue Exception => e
62
69
  puts "Exception found #{e.message}"
63
70
  ensure
@@ -2,7 +2,7 @@ module SmscManager #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 3
5
- TINY = 2
5
+ TINY = 3
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -43,18 +43,22 @@ class SmscManagerTest < Test::Unit::TestCase
43
43
  def test_broadcast_two
44
44
  list = %w(9991 9992)
45
45
  b=SmscManager::Broadcast.new("hello there",list)
46
+ assert b.attempts ==2, "did not send two sms"
46
47
  end
47
48
  def test_broadcast_five
48
- list = %w(9991 9992 9993 9994 9995 9996)
49
+ list = %w(9991 9992 9993 9994 9995)
49
50
  b=SmscManager::Broadcast.new("hello there",list)
51
+ assert b.attempts ==5, "did not send 5 sms"
50
52
  end
51
- def test_broadcast_ten
53
+ def test_broadcast_12
52
54
  list = %w(9991 9992 9993 9994 9995 9996 99910 99920 99930 99940 99950 99960)
53
55
  b=SmscManager::Broadcast.new("hello there",list)
56
+ assert b.attempts ==12, "did not send 12 sms"
54
57
  end
55
58
  def test_broadcast_six
56
- list = %w(9991 9992 9993 9994 9995 9996 9997)
59
+ list = %w(9991 9992 9993 9994 9995 9996)
57
60
  b=SmscManager::Broadcast.new("second hello there",list)
61
+ assert b.attempts ==6, "did not send 6 sms"
58
62
  end
59
63
  def test_find_google_mod
60
64
  @smsc.hostname='www.google.com'
metadata CHANGED
@@ -3,7 +3,7 @@ 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.2
6
+ version: 0.3.3
7
7
  date: 2007-03-21 00:00:00 +08:00
8
8
  summary: connection to smsc via http using kannel
9
9
  require_paths: