rapns 2.0.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 2.0.1 (July 7, 2012) ##
2
+ * Fix delivery when using Ruby 1.8.
3
+ * MultiJson support.
4
+
1
5
  ## 2.0.0 (June 19, 2012) ##
2
6
 
3
7
  * Support for multiple apps.
@@ -1,59 +1,41 @@
1
1
  module Rapns
2
2
  module Daemon
3
- class DeliveryQueue
3
+ if RUBY_VERSION < '1.9'
4
+ require 'rapns/daemon/delivery_queue_18'
5
+ ancestor_class = DeliveryQueue18
6
+ else
7
+ require 'rapns/daemon/delivery_queue_19'
8
+ ancestor_class = DeliveryQueue19
9
+ end
10
+
11
+ class DeliveryQueue < ancestor_class
4
12
  class WakeupError < StandardError; end
5
13
 
6
14
  def initialize
7
- @mutex = Mutex.new
8
15
  @num_notifications = 0
9
16
  @queue = []
10
17
  @waiting = []
11
- end
12
-
13
- def push(notification)
14
- @mutex.synchronize do
15
- @num_notifications += 1
16
- @queue.push(notification)
17
18
 
18
- begin
19
- t = @waiting.shift
20
- t.wakeup if t
21
- rescue ThreadError
22
- retry
23
- end
24
- end
25
- end
26
-
27
- def pop
28
- @mutex.synchronize do
29
- while true
30
- if @queue.empty?
31
- @waiting.push Thread.current
32
- @mutex.sleep
33
- else
34
- return @queue.shift
35
- end
36
- end
37
- end
19
+ super
38
20
  end
39
21
 
40
22
  def wakeup(thread)
41
- @mutex.synchronize do
23
+ synchronize do
42
24
  t = @waiting.delete(thread)
43
25
  t.raise WakeupError if t
44
26
  end
45
27
  end
46
28
 
47
29
  def size
48
- @mutex.synchronize { @queue.size }
30
+ synchronize { @queue.size }
49
31
  end
50
32
 
51
33
  def notification_processed
52
- @mutex.synchronize { @num_notifications -= 1 }
34
+ synchronize { @num_notifications -= 1 }
53
35
  end
54
36
 
55
37
  def notifications_processed?
56
- @mutex.synchronize { @num_notifications == 0 }
38
+ synchronize { @num_notifications == 0 }
57
39
  end
58
40
  end
59
41
  end
@@ -0,0 +1,44 @@
1
+ module Rapns
2
+ module Daemon
3
+ class DeliveryQueue18
4
+ def push(obj)
5
+ Thread.critical = true
6
+ @queue.push obj
7
+ @num_notifications += 1
8
+ begin
9
+ t = @waiting.shift
10
+ t.wakeup if t
11
+ rescue ThreadError
12
+ retry
13
+ ensure
14
+ Thread.critical = false
15
+ end
16
+ begin
17
+ t.run if t
18
+ rescue ThreadError
19
+ end
20
+ end
21
+
22
+ def pop
23
+ while (Thread.critical = true; @queue.empty?)
24
+ @waiting.push Thread.current
25
+ Thread.stop
26
+ end
27
+ @queue.shift
28
+ ensure
29
+ Thread.critical = false
30
+ end
31
+
32
+ protected
33
+
34
+ def synchronize
35
+ Thread.critical = true
36
+ begin
37
+ yield
38
+ ensure
39
+ Thread.critical = false
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,42 @@
1
+ module Rapns
2
+ module Daemon
3
+ class DeliveryQueue19
4
+ def initialize
5
+ @mutex = Mutex.new
6
+ end
7
+
8
+ def push(notification)
9
+ @mutex.synchronize do
10
+ @num_notifications += 1
11
+ @queue.push(notification)
12
+
13
+ begin
14
+ t = @waiting.shift
15
+ t.wakeup if t
16
+ rescue ThreadError
17
+ retry
18
+ end
19
+ end
20
+ end
21
+
22
+ def pop
23
+ @mutex.synchronize do
24
+ while true
25
+ if @queue.empty?
26
+ @waiting.push Thread.current
27
+ @mutex.sleep
28
+ else
29
+ return @queue.shift
30
+ end
31
+ end
32
+ end
33
+ end
34
+
35
+ protected
36
+
37
+ def synchronize(&blk)
38
+ @mutex.synchronize(&blk)
39
+ end
40
+ end
41
+ end
42
+ end
@@ -18,7 +18,7 @@ module Rapns
18
18
 
19
19
  def alert=(alert)
20
20
  if alert.is_a?(Hash)
21
- write_attribute(:alert, ActiveSupport::JSON.encode(alert))
21
+ write_attribute(:alert, MultiJson.dump(alert))
22
22
  self.alert_is_json = true if has_attribute?(:alert_is_json)
23
23
  else
24
24
  write_attribute(:alert, alert)
@@ -31,22 +31,22 @@ module Rapns
31
31
 
32
32
  if has_attribute?(:alert_is_json)
33
33
  if alert_is_json?
34
- ActiveSupport::JSON.decode(string_or_json)
34
+ MultiJson.load(string_or_json)
35
35
  else
36
36
  string_or_json
37
37
  end
38
38
  else
39
- ActiveSupport::JSON.decode(string_or_json) rescue string_or_json
39
+ MultiJson.load(string_or_json) rescue string_or_json
40
40
  end
41
41
  end
42
42
 
43
43
  def attributes_for_device=(attrs)
44
44
  raise ArgumentError, "attributes_for_device must be a Hash" if !attrs.is_a?(Hash)
45
- write_attribute(:attributes_for_device, ActiveSupport::JSON.encode(attrs))
45
+ write_attribute(:attributes_for_device, MultiJson.dump(attrs))
46
46
  end
47
47
 
48
48
  def attributes_for_device
49
- ActiveSupport::JSON.decode(read_attribute(:attributes_for_device)) if read_attribute(:attributes_for_device)
49
+ MultiJson.load(read_attribute(:attributes_for_device)) if read_attribute(:attributes_for_device)
50
50
  end
51
51
 
52
52
  MDM_OVERIDE_KEY = '__rapns_mdm__'
@@ -71,7 +71,7 @@ module Rapns
71
71
  end
72
72
 
73
73
  def payload
74
- as_json.to_json
74
+ MultiJson.dump(as_json)
75
75
  end
76
76
 
77
77
  def payload_size
@@ -85,4 +85,4 @@ module Rapns
85
85
  [1, id_for_pack, expiry, 0, 32, device_token, payload_size, payload].pack("cNNccH*na*")
86
86
  end
87
87
  end
88
- end
88
+ end
data/lib/rapns/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Rapns
2
- VERSION = '2.0.0'
2
+ VERSION = '2.0.1'
3
3
  end
data/lib/rapns.rb CHANGED
@@ -1,8 +1,9 @@
1
1
  require 'active_record'
2
+ require 'multi_json'
2
3
 
3
4
  require 'rapns/version'
4
5
  require 'rapns/binary_notification_validator'
5
6
  require 'rapns/device_token_format_validator'
6
7
  require 'rapns/notification'
7
8
  require 'rapns/feedback'
8
- require 'rapns/app'
9
+ require 'rapns/app'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rapns
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,8 +9,24 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-19 00:00:00.000000000 Z
13
- dependencies: []
12
+ date: 2012-07-08 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: multi_json
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.0'
14
30
  description: Easy to use library for Apple's Push Notification Service with Rails
15
31
  3
16
32
  email:
@@ -37,6 +53,8 @@ files:
37
53
  - lib/rapns/daemon/delivery_handler.rb
38
54
  - lib/rapns/daemon/delivery_handler_pool.rb
39
55
  - lib/rapns/daemon/delivery_queue.rb
56
+ - lib/rapns/daemon/delivery_queue_18.rb
57
+ - lib/rapns/daemon/delivery_queue_19.rb
40
58
  - lib/rapns/daemon/disconnection_error.rb
41
59
  - lib/rapns/daemon/feedback_receiver.rb
42
60
  - lib/rapns/daemon/feeder.rb