apnd 0.1.7 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -100,9 +100,13 @@ push notifications to APND.
100
100
 
101
101
  # Send multiple notifications at once to avoid overhead in
102
102
  # opening/closing the upstream socket connection each time
103
+ #
104
+ # *IMPORTANT!* Use sock.puts as it appends a new line. If you don't,
105
+ # you'll only receive the first notification.
106
+
103
107
  APND::Notification.open_upstream_socket do |sock|
104
- sock.write(notification1.to_bytes)
105
- sock.write(notification2.to_bytes)
108
+ sock.puts(notification1.to_bytes)
109
+ sock.puts(notification2.to_bytes)
106
110
  end
107
111
 
108
112
 
@@ -17,16 +17,11 @@ module APND
17
17
  #
18
18
  # Called when a client connection is closed
19
19
  #
20
- def unbind
21
- APND.ohai "#{@address.last}:#{@address.first} closed connection"
22
- end
23
-
20
+ # Checks @buffer for any pending notifications to be
21
+ # queued
24
22
  #
25
- # Add incoming notification(s) to the queue
26
- #
27
- def receive_data(data)
28
- (@buffer ||= "") << data
29
- @buffer.each_line do |line|
23
+ def unbind
24
+ @buffer.chomp.split("\n").each do |line|
30
25
  if notification = APND::Notification.valid?(line)
31
26
  APND.ohai "#{@address.last}:#{@address.first} added new Notification to queue"
32
27
  queue.push(notification)
@@ -34,6 +29,15 @@ module APND
34
29
  APND.ohai "#{@address.last}:#{@address.first} submitted invalid Notification"
35
30
  end
36
31
  end
32
+ APND.ohai "#{@address.last}:#{@address.first} closed connection"
33
+ end
34
+
35
+ #
36
+ # Add incoming notification(s) to @buffer
37
+ #
38
+ def receive_data(data)
39
+ APND.ohai "#{@address.last}:#{@address.first} buffering data"
40
+ (@buffer ||= "") << data
37
41
  end
38
42
  end
39
43
  end
@@ -2,7 +2,7 @@ module APND
2
2
  class Version #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 1
5
- TINY = 7
5
+ TINY = 8
6
6
 
7
7
  def self.to_s
8
8
  [MAJOR, MINOR, TINY].join('.')
@@ -61,11 +61,13 @@ class APNDTest < Test::Unit::TestCase
61
61
 
62
62
  should "add valid notification to queue" do
63
63
  @daemon.receive_data(@@bytes)
64
+ @daemon.unbind
64
65
  assert_equal 1, @daemon.queue.size
65
66
  end
66
67
 
67
68
  should "receive multiple Notifications in a single packet" do
68
69
  @daemon.receive_data([@@bytes, @@bytes, @@bytes].join("\n"))
70
+ @daemon.unbind
69
71
  assert_equal 3, @daemon.queue.size
70
72
  end
71
73
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apnd
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 11
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 7
10
- version: 0.1.7
9
+ - 8
10
+ version: 0.1.8
11
11
  platform: ruby
12
12
  authors:
13
13
  - Joshua Priddle
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-02-17 00:00:00 -05:00
18
+ date: 2011-02-18 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency