apnd 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -101,8 +101,8 @@ push notifications to APND.
101
101
  # Send multiple notifications at once to avoid overhead in
102
102
  # opening/closing the upstream socket connection each time
103
103
  APND::Notification.open_upstream_socket do |sock|
104
- sock.puts notification1
105
- sock.puts notification2
104
+ sock.write(notification1.to_bytes)
105
+ sock.write(notification2.to_bytes)
106
106
  end
107
107
 
108
108
 
@@ -21,9 +21,11 @@ module APND
21
21
  yield settings
22
22
  end
23
23
 
24
- end
25
-
24
+ #
25
+ # Write message to stdout with date
26
+ #
27
+ def self.ohai(message) #:nodoc:
28
+ puts "[%s] %s" % [Time.now.strftime("%Y-%m-%d %H:%M:%S"), message]
29
+ end
26
30
 
27
- def ohai(message) #:nodoc:
28
- puts "[%s] %s" % [Time.now.strftime("%Y-%m-%d %H:%M:%S"), message]
29
31
  end
@@ -35,7 +35,7 @@ module APND
35
35
  #
36
36
  def run!
37
37
  EventMachine::run do
38
- ohai "Starting APND Daemon v#{APND::Version} on #{@bind}:#{@port}"
38
+ APND.ohai "Starting APND Daemon v#{APND::Version} on #{@bind}:#{@port}"
39
39
  EventMachine::start_server(@bind, @port, APND::Daemon::ServerConnection) do |server|
40
40
  server.queue = @queue
41
41
  end
@@ -54,19 +54,19 @@ module APND
54
54
  def process_notifications!
55
55
  count = @queue.size
56
56
  if count > 0
57
- ohai "Queue has #{count} item#{count == 1 ? '' : 's'}"
57
+ APND.ohai "Queue has #{count} item#{count == 1 ? '' : 's'}"
58
58
  @apple.connect!
59
59
  count.times do
60
60
  @queue.pop do |notification|
61
61
  begin
62
- ohai "Sending notification for #{notification.token}"
62
+ APND.ohai "Sending notification for #{notification.token}"
63
63
  @apple.write(notification.to_bytes)
64
64
  rescue Errno::EPIPE, OpenSSL::SSL::SSLError
65
- ohai "Error, notification has been added back to the queue"
65
+ APND.ohai "Error, notification has been added back to the queue"
66
66
  @queue.push(notification)
67
67
  @apple.reconnect!
68
68
  rescue RuntimeError => error
69
- ohai "Error: #{error}"
69
+ APND.ohai "Error: #{error}"
70
70
  end
71
71
  end
72
72
  end
@@ -57,7 +57,8 @@ module APND
57
57
  # Disconnect/connect to Apple
58
58
  #
59
59
  def reconnect!
60
- disconnect! && connect!
60
+ disconnect!
61
+ connect!
61
62
  end
62
63
 
63
64
  #
@@ -11,14 +11,14 @@ module APND
11
11
  #
12
12
  def post_init
13
13
  @address = ::Socket.unpack_sockaddr_in(self.get_peername)
14
- ohai "#{@address.last}:#{@address.first} opened connection"
14
+ APND.ohai "#{@address.last}:#{@address.first} opened connection"
15
15
  end
16
16
 
17
17
  #
18
18
  # Called when a client connection is closed
19
19
  #
20
20
  def unbind
21
- ohai "#{@address.last}:#{@address.first} closed connection"
21
+ APND.ohai "#{@address.last}:#{@address.first} closed connection"
22
22
  end
23
23
 
24
24
  #
@@ -28,10 +28,10 @@ module APND
28
28
  (@buffer ||= "") << data
29
29
  @buffer.each_line do |line|
30
30
  if notification = APND::Notification.valid?(line)
31
- ohai "#{@address.last}:#{@address.first} added new Notification to queue"
31
+ APND.ohai "#{@address.last}:#{@address.first} added new Notification to queue"
32
32
  queue.push(notification)
33
33
  else
34
- ohai "#{@address.last}:#{@address.first} submitted invalid Notification"
34
+ APND.ohai "#{@address.last}:#{@address.first} submitted invalid Notification"
35
35
  end
36
36
  end
37
37
  end
@@ -2,7 +2,7 @@ module APND
2
2
  class Version #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 1
5
- TINY = 6
5
+ TINY = 7
6
6
 
7
7
  def self.to_s
8
8
  [MAJOR, MINOR, TINY].join('.')
@@ -66,14 +66,14 @@ class APNDTest < Test::Unit::TestCase
66
66
 
67
67
  should "receive multiple Notifications in a single packet" do
68
68
  @daemon.receive_data([@@bytes, @@bytes, @@bytes].join("\n"))
69
- assert 3, @daemon.queue.size
69
+ assert_equal 3, @daemon.queue.size
70
70
  end
71
71
 
72
72
  should "raise InvalidNotificationHeader parsing a bad packet" do
73
73
  assert_raise APND::Errors::InvalidNotificationHeader do
74
74
  APND::Notification.parse("I'm not a packet!")
75
75
  end
76
- assert 0, @daemon.queue.size
76
+ assert_equal 0, @daemon.queue.size
77
77
  end
78
78
  end
79
79
  end
@@ -23,5 +23,5 @@ class TestDaemon
23
23
 
24
24
  end
25
25
 
26
- # Silence ohai in testing
27
- def ohai(*args); end
26
+ # Silence APND.ohai in testing
27
+ def APND.ohai(*args); end
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apnd
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
4
+ hash: 21
5
+ prerelease:
5
6
  segments:
6
7
  - 0
7
8
  - 1
8
- - 6
9
- version: 0.1.6
9
+ - 7
10
+ version: 0.1.7
10
11
  platform: ruby
11
12
  authors:
12
13
  - Joshua Priddle
@@ -14,16 +15,18 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-12-09 00:00:00 -05:00
18
+ date: 2011-02-17 00:00:00 -05:00
18
19
  default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
21
22
  name: eventmachine
22
23
  prerelease: false
23
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
24
26
  requirements:
25
27
  - - "="
26
28
  - !ruby/object:Gem::Version
29
+ hash: 59
27
30
  segments:
28
31
  - 0
29
32
  - 12
@@ -35,9 +38,11 @@ dependencies:
35
38
  name: json
36
39
  prerelease: false
37
40
  requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
38
42
  requirements:
39
43
  - - "="
40
44
  - !ruby/object:Gem::Version
45
+ hash: 11
41
46
  segments:
42
47
  - 1
43
48
  - 4
@@ -49,9 +54,11 @@ dependencies:
49
54
  name: daemons
50
55
  prerelease: false
51
56
  requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
52
58
  requirements:
53
59
  - - "="
54
60
  - !ruby/object:Gem::Version
61
+ hash: 19
55
62
  segments:
56
63
  - 1
57
64
  - 1
@@ -63,9 +70,11 @@ dependencies:
63
70
  name: shoulda
64
71
  prerelease: false
65
72
  requirement: &id004 !ruby/object:Gem::Requirement
73
+ none: false
66
74
  requirements:
67
75
  - - ">="
68
76
  - !ruby/object:Gem::Version
77
+ hash: 3
69
78
  segments:
70
79
  - 0
71
80
  version: "0"
@@ -106,23 +115,27 @@ rdoc_options:
106
115
  require_paths:
107
116
  - lib
108
117
  required_ruby_version: !ruby/object:Gem::Requirement
118
+ none: false
109
119
  requirements:
110
120
  - - ">="
111
121
  - !ruby/object:Gem::Version
122
+ hash: 3
112
123
  segments:
113
124
  - 0
114
125
  version: "0"
115
126
  required_rubygems_version: !ruby/object:Gem::Requirement
127
+ none: false
116
128
  requirements:
117
129
  - - ">="
118
130
  - !ruby/object:Gem::Version
131
+ hash: 3
119
132
  segments:
120
133
  - 0
121
134
  version: "0"
122
135
  requirements: []
123
136
 
124
137
  rubyforge_project:
125
- rubygems_version: 1.3.6
138
+ rubygems_version: 1.5.0
126
139
  signing_key:
127
140
  specification_version: 3
128
141
  summary: "APND: Apple Push Notification Daemon sends Apple Push Notifications to iPhones"