apnd 0.1.3 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -52,14 +52,14 @@ notifications to a running APND instance, or Apple directly. It is only
52
52
  recommended to send notifications directly to Apple for testing purposes.
53
53
 
54
54
  Usage:
55
- apnd-push [OPTIONS] --token <token> --alert <alert>
55
+ apnd-push [OPTIONS] --token <token>
56
56
 
57
57
  Required Arguments:
58
58
  --token [TOKEN] Set Notification's iPhone token to TOKEN
59
- --alert [MESSAGE] Set Notification's alert to MESSAGE
60
59
 
61
60
  Optional Arguments:
62
- --sound [SOUND] Set Notification's sound to SOUND (default is 'default')
61
+ --alert [MESSAGE] Set Notification's alert to MESSAGE
62
+ --sound [SOUND] Set Notification's sound to SOUND
63
63
  --badge [NUMBER] Set Notification's badge number to NUMBER
64
64
  --custom [JSON] Set Notification's custom data to JSON
65
65
  --host [HOST] Send Notification to HOST, usually the one running APND (default is 'localhost')
data/Rakefile CHANGED
@@ -1,5 +1,9 @@
1
+ $:.unshift 'lib'
2
+
1
3
  require 'rubygems'
2
4
 
5
+ task :default => :test
6
+
3
7
  require 'rake/testtask'
4
8
  Rake::TestTask.new(:test) do |test|
5
9
  test.libs << 'lib' << 'test' << '.'
@@ -8,7 +8,7 @@ require 'optparse'
8
8
 
9
9
  help = <<HELP
10
10
  Usage:
11
- apnd-push [OPTIONS] --token <token> --alert <alert>
11
+ apnd-push [OPTIONS] --token <token>
12
12
 
13
13
  HELP
14
14
 
@@ -23,13 +23,13 @@ opts = OptionParser.new do |opt|
23
23
  options[:token] = token
24
24
  end
25
25
 
26
+ opt.separator "\nOptional Arguments:\n"
27
+
26
28
  opt.on('--alert [MESSAGE]', "Set Notification's alert to MESSAGE") do |alert|
27
29
  options[:alert] = alert
28
30
  end
29
31
 
30
- opt.separator "\nOptional Arguments:\n"
31
-
32
- opt.on('--sound [SOUND]', "Set Notification's sound to SOUND (default is 'default')") do |sound|
32
+ opt.on('--sound [SOUND]', "Set Notification's sound to SOUND") do |sound|
33
33
  options[:sound] = sound
34
34
  end
35
35
 
@@ -74,8 +74,8 @@ begin
74
74
  exit
75
75
  end
76
76
 
77
- unless options[:token] && options[:alert]
78
- raise OptionParser::MissingArgument, "must specify --token and --alert"
77
+ unless options[:token]
78
+ raise OptionParser::MissingArgument, "must specify --token"
79
79
  end
80
80
  rescue OptionParser::InvalidOption, OptionParser::MissingArgument
81
81
  puts "#{$0}: #{$!.message}"
@@ -58,7 +58,7 @@ module APND
58
58
  count.times do
59
59
  @queue.pop do |notification|
60
60
  begin
61
- ohai "Sending notification"
61
+ ohai "Sending notification for #{notification.token}"
62
62
  @apple.write(notification.to_bytes)
63
63
  rescue Errno::EPIPE, OpenSSL::SSL::SSLError
64
64
  ohai "Error, notification has been added back to the queue"
@@ -25,15 +25,17 @@ module APND
25
25
  end
26
26
 
27
27
  #
28
- # Add incoming notification to the queue if it is valid
28
+ # Add incoming notification(s) to the queue
29
29
  #
30
30
  def receive_data(data)
31
31
  (@buffer ||= "") << data
32
- if notification = APND::Notification.valid?(@buffer)
33
- ohai "#{@address.last}:#{@address.first} added new Notification to queue"
34
- queue.push(notification)
35
- else
36
- ohai "#{@address.last}:#{@address.first} submitted invalid Notification"
32
+ @buffer.each_line do |line|
33
+ if notification = APND::Notification.valid?(line)
34
+ ohai "#{@address.last}:#{@address.first} added new Notification to queue"
35
+ queue.push(notification)
36
+ else
37
+ ohai "#{@address.last}:#{@address.first} submitted invalid Notification"
38
+ end
37
39
  end
38
40
  end
39
41
  end
@@ -81,8 +81,6 @@ module APND
81
81
  #
82
82
  def self.valid?(data)
83
83
  parse(data)
84
- rescue
85
- false
86
84
  end
87
85
 
88
86
  #
@@ -119,6 +117,8 @@ module APND
119
117
  end
120
118
 
121
119
  notification
120
+ rescue
121
+ false
122
122
  end
123
123
 
124
124
  #
@@ -128,7 +128,7 @@ module APND
128
128
  @token = params[:token]
129
129
  @alert = params[:alert]
130
130
  @badge = params[:badge]
131
- @sound = params[:sound] || 'default'
131
+ @sound = params[:sound]
132
132
  @custom = params[:custom]
133
133
  end
134
134
 
@@ -2,7 +2,7 @@ module APND
2
2
  class Version #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 1
5
- TINY = 3
5
+ TINY = 4
6
6
 
7
7
  def self.to_s
8
8
  [MAJOR, MINOR, TINY].join('.')
@@ -1,29 +1,41 @@
1
1
  require File.dirname(__FILE__) + '/test_helper.rb'
2
2
 
3
- context "APND Notification" do
3
+ context "APND" do
4
4
  setup do
5
5
  @bytes = %|\000\000 \376\025\242}]\363\303Gx\336\373\037O8\200&\\\305,\f\004v\202";\345\237\266\205\000\251\242\000;{"aps":{"sound":"default","alert":"Red Alert, Numba One!"}}|
6
6
  @notification = APND::Notification.new({
7
7
  :token => 'fe15a27d5df3c34778defb1f4f3880265cc52c0c047682223be59fb68500a9a2',
8
- :alert => 'Red Alert, Numba One!'
8
+ :alert => 'Red Alert, Numba One!',
9
+ :sound => 'default'
9
10
  })
10
11
  end
11
12
 
12
- test "returns a properly formatted hex_token" do
13
+ test "Notification returns a valid hex_token" do
13
14
  expected = %|\376\025\242}]\363\303Gx\336\373\037O8\200&\\\305,\f\004v\202";\345\237\266\205\000\251\242|
14
15
  assert_equal @notification.hex_token, expected
15
16
  end
16
17
 
17
- test "returns a properly formatted byte string for Apple" do
18
+ test "Notification returns a valid byte string for Apple" do
18
19
  assert_equal @notification.to_bytes, @bytes
19
20
  end
20
21
 
21
- test "returns a Notification object when given valid byte string" do
22
+ test "Notification.parse returns a Notification when given a valid string" do
22
23
  notification = APND::Notification.parse(@bytes)
23
24
 
25
+ assert notification
26
+
24
27
  [:alert, :badge, :custom, :sound, :token, :hex_token, :to_bytes, :aps, :aps_json].each do |key|
25
28
  assert_equal @notification.send(key), notification.send(key)
26
29
  end
30
+
31
+ assert ! APND::Notification.parse("I'm not a packet!")
32
+ end
33
+
34
+ test "Notification multiple apns to be sent" do
35
+ notifications = [@bytes, @bytes, @bytes].join("\n")
36
+ notifications.each_line do |line|
37
+ assert APND::Notification.valid?(line)
38
+ end
27
39
  end
28
40
 
29
41
  end
@@ -7,6 +7,11 @@ $LOAD_PATH.unshift(dir)
7
7
 
8
8
  require 'apnd'
9
9
 
10
+ begin
11
+ require 'turn'
12
+ rescue LoadError
13
+ end
14
+
10
15
  ##
11
16
  # test/spec/mini 3
12
17
  # http://gist.github.com/25455
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 3
9
- version: 0.1.3
8
+ - 4
9
+ version: 0.1.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - Joshua Priddle
@@ -81,8 +81,7 @@ files:
81
81
  - lib/apnd/settings.rb
82
82
  - lib/apnd/version.rb
83
83
  - lib/apnd.rb
84
- - test/daemon_test.rb
85
- - test/notification_test.rb
84
+ - test/apnd_test.rb
86
85
  - test/test_helper.rb
87
86
  has_rdoc: true
88
87
  homepage: http://github.com/itspriddle/apnd
@@ -1,5 +0,0 @@
1
- require File.dirname(__FILE__) + '/test_helper.rb'
2
-
3
- # context "APND Daemon" do
4
- #
5
- # end