apnserver 0.1.10 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,10 @@
1
+ require 'apnserver/protocol'
2
+
3
+ class TestServer
4
+ attr_accessor :queue
5
+ include ApnServer::Protocol
6
+
7
+ def address
8
+ [12345, '127.0.0.1']
9
+ end
10
+ end
metadata CHANGED
@@ -1,7 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apnserver
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.10
4
+ hash: 21
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 2
9
+ - 1
10
+ version: 0.2.1
5
11
  platform: ruby
6
12
  authors:
7
13
  - Ben Poweski
@@ -9,68 +15,85 @@ autorequire:
9
15
  bindir: bin
10
16
  cert_chain: []
11
17
 
12
- date: 2009-11-21 00:00:00 -06:00
18
+ date: 2011-01-01 00:00:00 -06:00
13
19
  default_executable:
14
20
  dependencies:
15
21
  - !ruby/object:Gem::Dependency
16
- name: eventmachine
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
22
+ name: activesupport
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
20
26
  requirements:
21
- - - ">="
27
+ - - ~>
22
28
  - !ruby/object:Gem::Version
23
- version: "0"
24
- version:
25
- - !ruby/object:Gem::Dependency
26
- name: daemons
29
+ hash: 7
30
+ segments:
31
+ - 3
32
+ - 0
33
+ - 0
34
+ version: 3.0.0
27
35
  type: :runtime
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: bundler
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
30
42
  requirements:
31
- - - ">="
43
+ - - ~>
32
44
  - !ruby/object:Gem::Version
33
- version: "0"
34
- version:
45
+ hash: 23
46
+ segments:
47
+ - 1
48
+ - 0
49
+ - 0
50
+ version: 1.0.0
51
+ type: :development
52
+ version_requirements: *id002
35
53
  - !ruby/object:Gem::Dependency
36
- name: json
37
- type: :runtime
38
- version_requirement:
39
- version_requirements: !ruby/object:Gem::Requirement
54
+ name: eventmachine
55
+ prerelease: false
56
+ requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
40
58
  requirements:
41
59
  - - ">="
42
60
  - !ruby/object:Gem::Version
43
- version: "0"
44
- version:
61
+ hash: 63
62
+ segments:
63
+ - 0
64
+ - 12
65
+ - 8
66
+ version: 0.12.8
67
+ type: :development
68
+ version_requirements: *id003
45
69
  description: A toolkit for proxying and sending Apple Push Notifications
46
70
  email: bpoweski@3factors.com
47
71
  executables:
48
72
  - apnsend
49
73
  - apnserverd
50
- - apnserverd.fedora.init
51
74
  extensions: []
52
75
 
53
76
  extra_rdoc_files:
54
77
  - README.textile
55
78
  files:
56
- - README.textile
57
- - Rakefile
58
- - VERSION
59
79
  - bin/apnsend
60
80
  - bin/apnserverd
61
81
  - bin/apnserverd.fedora.init
62
- - lib/apnserver.rb
82
+ - bin/apnserverd.ubuntu.init
63
83
  - lib/apnserver/client.rb
64
84
  - lib/apnserver/notification.rb
65
85
  - lib/apnserver/payload.rb
66
86
  - lib/apnserver/protocol.rb
67
87
  - lib/apnserver/server.rb
68
88
  - lib/apnserver/server_connection.rb
69
- - test/test_client.rb
70
- - test/test_helper.rb
71
- - test/test_notification.rb
72
- - test/test_payload.rb
73
- - test/test_protocol.rb
89
+ - lib/apnserver.rb
90
+ - README.textile
91
+ - spec/models/client_spec.rb
92
+ - spec/models/notification_spec.rb
93
+ - spec/models/payload_spec.rb
94
+ - spec/models/protocol_spec.rb
95
+ - spec/spec_helper.rb
96
+ - spec/support/test_server.rb
74
97
  has_rdoc: true
75
98
  homepage: http://github.com/bpoweski/apnserver
76
99
  licenses: []
@@ -81,27 +104,36 @@ rdoc_options:
81
104
  require_paths:
82
105
  - lib
83
106
  required_ruby_version: !ruby/object:Gem::Requirement
107
+ none: false
84
108
  requirements:
85
109
  - - ">="
86
110
  - !ruby/object:Gem::Version
111
+ hash: 3
112
+ segments:
113
+ - 0
87
114
  version: "0"
88
- version:
89
115
  required_rubygems_version: !ruby/object:Gem::Requirement
116
+ none: false
90
117
  requirements:
91
118
  - - ">="
92
119
  - !ruby/object:Gem::Version
93
- version: "0"
94
- version:
120
+ hash: 23
121
+ segments:
122
+ - 1
123
+ - 3
124
+ - 6
125
+ version: 1.3.6
95
126
  requirements: []
96
127
 
97
128
  rubyforge_project: apnserver
98
- rubygems_version: 1.3.5
129
+ rubygems_version: 1.3.7
99
130
  signing_key:
100
131
  specification_version: 3
101
- summary: Apple Push Notification Server
132
+ summary: Apple Push Notification Toolkit
102
133
  test_files:
103
- - test/test_client.rb
104
- - test/test_helper.rb
105
- - test/test_notification.rb
106
- - test/test_payload.rb
107
- - test/test_protocol.rb
134
+ - spec/models/client_spec.rb
135
+ - spec/models/notification_spec.rb
136
+ - spec/models/payload_spec.rb
137
+ - spec/models/protocol_spec.rb
138
+ - spec/spec_helper.rb
139
+ - spec/support/test_server.rb
data/Rakefile DELETED
@@ -1,41 +0,0 @@
1
- require 'rubygems'
2
- require 'rake/testtask'
3
- require 'rake/rdoctask'
4
-
5
- begin
6
- require 'jeweler'
7
- Jeweler::Tasks.new do |gemspec|
8
- gemspec.name = "apnserver"
9
- gemspec.summary = "Apple Push Notification Server"
10
- gemspec.description = "A toolkit for proxying and sending Apple Push Notifications"
11
- gemspec.email = "bpoweski@3factors.com"
12
- gemspec.homepage = "http://github.com/bpoweski/apnserver"
13
- gemspec.authors = ["Ben Poweski"]
14
- gemspec.add_dependency 'eventmachine'
15
- gemspec.add_dependency 'daemons'
16
- gemspec.add_dependency 'json'
17
- gemspec.rubyforge_project = 'apnserver'
18
- gemspec.files = FileList['lib/**/*.rb', 'bin/*', '[A-Z]*', 'test/**/*'].to_a
19
- end
20
- rescue LoadError
21
- puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
22
- end
23
-
24
- Rake::TestTask.new(:test) do |test|
25
- test.test_files = FileList.new('test/**/test_*.rb') do |list|
26
- list.exclude 'test/test_helper.rb'
27
- end
28
- test.libs << 'test'
29
- test.verbose = true
30
- end
31
-
32
- Jeweler::RubyforgeTasks.new do |rubyforge|
33
- end
34
-
35
- Rake::RDocTask.new do |rd|
36
- rd.main = "README.textile"
37
- rd.rdoc_dir = 'rdoc'
38
- rd.rdoc_files.include("README.textile", "lib/**/*.rb")
39
- end
40
-
41
- task :default => [:test]
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.1.10
data/test/test_client.rb DELETED
@@ -1,11 +0,0 @@
1
- require File.dirname(__FILE__) + '/test_helper'
2
-
3
- class TestClient < Test::Unit::TestCase
4
-
5
- def test_creates_client
6
- client = ApnServer::Client.new('cert.pem', 'gateway.sandbox.push.apple.com', 2196)
7
- assert_equal 'cert.pem', client.pem
8
- assert_equal 'gateway.sandbox.push.apple.com', client.host
9
- assert_equal 2196, client.port
10
- end
11
- end
data/test/test_helper.rb DELETED
@@ -1,4 +0,0 @@
1
- require 'stringio'
2
- require 'test/unit'
3
- require 'rubygems'
4
- require File.dirname(__FILE__) + '/../lib/apnserver'
@@ -1,79 +0,0 @@
1
- require File.dirname(__FILE__) + '/test_helper.rb'
2
- require 'base64'
3
-
4
- class NotificationTest < Test::Unit::TestCase
5
- include ApnServer
6
-
7
- def setup
8
- @notification = Notification.new
9
- end
10
-
11
- def test_should_generate_byte_array
12
- payload = '{"aps":{"alert":"You have not mail!"}}'
13
- device_token = "12345678123456781234567812345678"
14
- @notification.device_token = device_token
15
- @notification.alert = "You have not mail!"
16
- expected = [0, 0, device_token.size, device_token, 0, payload.size, payload]
17
- assert_equal expected.pack("ccca*CCa*"), @notification.to_bytes
18
- end
19
-
20
- def test_should_create_payload_with_badge_attribute
21
- expected = { :aps => { :badge => 1 }}
22
- @notification.badge = 1
23
- assert_equal expected, @notification.payload
24
- end
25
-
26
- def test_should_create_payload_with_alert_attribute
27
- expected = { :aps => { :alert => 'Hi' }}
28
- @notification.alert = 'Hi'
29
- assert_equal expected, @notification.payload
30
- end
31
-
32
- def test_should_create_json_payload
33
- expected = '{"aps":{"alert":"Hi"}}'
34
- @notification.alert = 'Hi'
35
- assert_equal expected, @notification.json_payload
36
- end
37
-
38
- def test_should_not_allow_for_payloads_larger_than_256_chars
39
- assert_raise Payload::PayloadInvalid do
40
- alert = []
41
- 256.times { alert << 'Hi' }
42
- @notification.alert = alert.join
43
- @notification.json_payload
44
- end
45
- end
46
-
47
- def test_should_recognize_valid_request
48
- device_token = '12345678123456781234567812345678'
49
- payload = '{"aps":{"alert":"You have not mail!"}}'
50
- request = [0, 0, device_token.size, device_token, 0, payload.size, payload].pack("CCCa*CCa*")
51
- assert Notification.valid?(request)
52
- notification = Notification.parse(request)
53
- assert_equal device_token, notification.device_token
54
- assert_equal "You have not mail!", notification.alert
55
- end
56
-
57
- def test_should_not_recognize_invalid_request
58
- device_token = '123456781234567812345678'
59
- payload = '{"aps":{"alert":"You have not mail!"}}'
60
- request = [0, 0, 32, device_token, 0, payload.size, payload].pack("CCCa*CCa*")
61
- assert !Notification.valid?(request), request
62
- end
63
-
64
- def test_should_pack_and_unpack_json
65
- device_token = '12345678123456781234567812345678'
66
- notification = Notification.new
67
- notification.device_token = device_token
68
- notification.badge = 10
69
- notification.alert = 'Hi'
70
- notification.sound = 'default'
71
- notification.custom = { 'acme1' => "bar", 'acme2' => 42}
72
-
73
- parsed = Notification.parse(notification.to_bytes)
74
- [:device_token, :badge, :alert, :sound, :custom].each do |k|
75
- expected = notification.send(k)
76
- assert_equal expected, parsed.send(k), "Expected #{k} to be #{expected}"
77
- end
78
- end
79
- end
data/test/test_payload.rb DELETED
@@ -1,59 +0,0 @@
1
- require File.dirname(__FILE__) + '/test_helper.rb'
2
-
3
- class NotificationTest < Test::Unit::TestCase
4
- include ApnServer::Payload
5
-
6
- def test_should_create_payload_with_simple_string
7
- expected = { :aps => { :alert => 'Hi' }}
8
- assert_equal expected, create_payload('Hi')
9
- end
10
-
11
- def test_should_create_payload_with_alert_key
12
- expected = { :aps => { :alert => 'Hi' }}
13
- assert_equal expected, create_payload(:alert => 'Hi')
14
- end
15
-
16
- def test_should_create_payload_with_badge_and_alert
17
- expected = { :aps => { :alert => 'Hi', :badge => 1 }}
18
- assert_equal expected, create_payload(:alert => 'Hi', :badge => 1)
19
- end
20
-
21
- # example 1
22
- def test_should_create_payload_with_custom_payload
23
- alert = 'Message received from Bob'
24
- expected = {
25
- :aps => { :alert => alert },
26
- :acme2 => [ "bang", "whiz" ]
27
- }
28
- assert_equal expected, create_payload(:alert => alert, :custom => { :acme2 => ['bang', 'whiz']})
29
- end
30
-
31
- # example 3
32
- def test_should_create_payload_with_sound_and_multiple_custom
33
- expected = {
34
- :aps => {
35
- :alert => "You got your emails.",
36
- :badge => 9,
37
- :sound => "bingbong.aiff"
38
- },
39
- :acme1 => "bar",
40
- :acme2 => 42
41
- }
42
- assert_equal expected, create_payload({
43
- :alert => "You got your emails.",
44
- :badge => 9,
45
- :sound => "bingbong.aiff",
46
- :custom => { :acme1 => "bar", :acme2 => 42}
47
- })
48
- end
49
-
50
- # example 5
51
- def test_should_create_payload_with_empty_aps
52
- expected = {
53
- :aps => {},
54
- :acme2 => [ 5, 8 ]
55
- }
56
- assert_equal expected, create_payload(:custom => { :acme2 => [ 5, 8 ] })
57
- end
58
-
59
- end
@@ -1,29 +0,0 @@
1
- require File.dirname(__FILE__) + '/test_helper.rb'
2
-
3
- class TestServer
4
- attr_accessor :queue
5
- include ApnServer::Protocol
6
-
7
- def address
8
- [12345, '127.0.0.1']
9
- end
10
- end
11
-
12
- class TestProtocol < Test::Unit::TestCase
13
-
14
- def setup
15
- @server = TestServer.new
16
- @server.queue = Array.new # fake out EM::Queue
17
- end
18
-
19
- def test_adds_notification_to_queue
20
- token = "12345678123456781234567812345678"
21
- @server.receive_data("\0\0 #{token}\0#{22.chr}{\"aps\":{\"alert\":\"Hi\"}}")
22
- assert_equal 1, @server.queue.size
23
- end
24
-
25
- def test_does_not_add_invalid_notification
26
- @server.receive_data('fakedata')
27
- assert @server.queue.empty?
28
- end
29
- end