apn_client 0.0.1 → 0.0.2
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.
- data/.rvmrc +1 -1
- data/README.md +9 -23
- data/lib/apn_client/delivery.rb +7 -4
- data/lib/apn_client/version.rb +1 -1
- data/spec/delivery_spec.rb +4 -4
- metadata +10 -10
data/.rvmrc
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
# development environment upon cd'ing into the directory
|
5
5
|
|
6
6
|
# First we specify our desired <ruby>[@<gemset>], the @gemset name is optional.
|
7
|
-
environment_id="ruby-1.9.2-
|
7
|
+
environment_id="ruby-1.9.2-p290@apn_client"
|
8
8
|
|
9
9
|
#
|
10
10
|
# Uncomment following line if you want options to be set only for given project.
|
data/README.md
CHANGED
@@ -10,27 +10,7 @@ This is a RubyGem that allows sending of Apple Push Notifications to iOS devices
|
|
10
10
|
|
11
11
|
## Usage
|
12
12
|
|
13
|
-
###
|
14
|
-
|
15
|
-
```
|
16
|
-
|
17
|
-
ApnClient::Delivery.connection_config = {
|
18
|
-
:host => 'gateway.push.apple.com', # For sandbox, use: gateway.sandbox.push.apple.com
|
19
|
-
:port => 2195,
|
20
|
-
:certificate => IO.read("my_apn_certificate.pem"),
|
21
|
-
:certificate_passphrase => '',
|
22
|
-
}
|
23
|
-
|
24
|
-
ApnClient::Feedback.connection_config = {
|
25
|
-
:host => 'feedback.push.apple.com', # For sandbox, use: feedback.sandbox.push.apple.com
|
26
|
-
:port => 2196,
|
27
|
-
:certificate => IO.read("my_apn_certificate.pem"),
|
28
|
-
:certificate_passphrase => '',
|
29
|
-
}
|
30
|
-
|
31
|
-
```
|
32
|
-
|
33
|
-
### 2. Deliver Your Message
|
13
|
+
### Delivering Your Messages
|
34
14
|
|
35
15
|
```
|
36
16
|
message1 = ApnClient::Message.new(1,
|
@@ -51,7 +31,13 @@ delivery = ApnClient::Delivery.new([message1, message2],
|
|
51
31
|
:on_error => lambda { |d, message_id, error_code| puts "Received error code #{error_code} from Apple for message #{message_id}" }
|
52
32
|
},
|
53
33
|
:consecutive_failure_limit => 10, # If more than 10 devices in a row fail, we abort the whole delivery
|
54
|
-
:exception_limit => 3 # If a device raises an exception three times in a row we fail/skip the device and move on
|
34
|
+
:exception_limit => 3, # If a device raises an exception three times in a row we fail/skip the device and move on
|
35
|
+
:connection => {
|
36
|
+
:host => 'gateway.push.apple.com', # For sandbox, use: gateway.sandbox.push.apple.com
|
37
|
+
:port => 2195,
|
38
|
+
:certificate => IO.read("my_apn_certificate.pem"),
|
39
|
+
:certificate_passphrase => ''
|
40
|
+
}
|
55
41
|
)
|
56
42
|
delivery.process!
|
57
43
|
puts "Delivered successfully to #{delivery.success_count} out of #{delivery.total_count} devices in #{delivery.elapsed} seconds"
|
@@ -61,7 +47,7 @@ One potential gotcha to watch out for is that the device token for a message is
|
|
61
47
|
that different apps on the same device will have different tokens. The Apple documentation uses phone numbers as an analogy
|
62
48
|
to explain what a device token is.
|
63
49
|
|
64
|
-
###
|
50
|
+
### Checking for Feedback
|
65
51
|
|
66
52
|
TODO
|
67
53
|
|
data/lib/apn_client/delivery.rb
CHANGED
@@ -4,7 +4,7 @@ require 'apn_client/connection'
|
|
4
4
|
|
5
5
|
module ApnClient
|
6
6
|
class Delivery
|
7
|
-
attr_accessor :messages, :callbacks, :consecutive_failure_limit, :exception_limit, :sleep_on_exception,
|
7
|
+
attr_accessor :messages, :callbacks, :consecutive_failure_limit, :exception_limit, :sleep_on_exception, :connection_config,
|
8
8
|
:exception_count, :success_count, :failure_count, :consecutive_failure_count,
|
9
9
|
:started_at, :finished_at
|
10
10
|
|
@@ -44,12 +44,15 @@ module ApnClient
|
|
44
44
|
private
|
45
45
|
|
46
46
|
def initialize_options(options)
|
47
|
-
NamedArgs.assert_valid!(options,
|
47
|
+
NamedArgs.assert_valid!(options,
|
48
|
+
:optional => [:callbacks, :consecutive_failure_limit, :exception_limit, :sleep_on_exception],
|
49
|
+
:required => [:connection])
|
48
50
|
NamedArgs.assert_valid!(options[:callbacks], :optional => [:on_write, :on_error, :on_nil_select, :on_read_exception, :on_exception, :on_failure])
|
49
51
|
self.callbacks = options[:callbacks]
|
50
52
|
self.consecutive_failure_limit = options[:consecutive_failure_limit] || 10
|
51
53
|
self.exception_limit = options[:exception_limit] || 3
|
52
|
-
self.sleep_on_exception = options[:sleep_on_exception] || 1
|
54
|
+
self.sleep_on_exception = options[:sleep_on_exception] || 1
|
55
|
+
self.connection_config = options[:connection]
|
53
56
|
end
|
54
57
|
|
55
58
|
def current_message
|
@@ -75,7 +78,7 @@ module ApnClient
|
|
75
78
|
end
|
76
79
|
|
77
80
|
def connection
|
78
|
-
@connection ||= Connection.new(
|
81
|
+
@connection ||= Connection.new(connection_config)
|
79
82
|
end
|
80
83
|
|
81
84
|
def close_connection
|
data/lib/apn_client/version.rb
CHANGED
data/spec/delivery_spec.rb
CHANGED
@@ -18,7 +18,7 @@ describe ApnClient::Delivery do
|
|
18
18
|
|
19
19
|
describe "#initialize" do
|
20
20
|
it "initializes counts and other attributes" do
|
21
|
-
delivery = create_delivery([@message1, @message2])
|
21
|
+
delivery = create_delivery([@message1, @message2], :connection => {})
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
@@ -31,7 +31,7 @@ describe ApnClient::Delivery do
|
|
31
31
|
:on_write => lambda { |d, m| written_messages << m },
|
32
32
|
:on_nil_select => lambda { |d| nil_selects += 1 }
|
33
33
|
}
|
34
|
-
delivery = create_delivery(messages.dup, :callbacks => callbacks)
|
34
|
+
delivery = create_delivery(messages.dup, :callbacks => callbacks, :connection => {})
|
35
35
|
|
36
36
|
connection = mock('connection')
|
37
37
|
connection.expects(:write).with(@message1)
|
@@ -60,7 +60,7 @@ describe ApnClient::Delivery do
|
|
60
60
|
:on_failure => lambda { |d, m| failures << m },
|
61
61
|
:on_read_exception => lambda { |d, e| read_exceptions << e }
|
62
62
|
}
|
63
|
-
delivery = create_delivery(messages.dup, :callbacks => callbacks)
|
63
|
+
delivery = create_delivery(messages.dup, :callbacks => callbacks, :connection => {})
|
64
64
|
|
65
65
|
connection = mock('connection')
|
66
66
|
connection.expects(:write).with(@message1).times(3).raises(RuntimeError)
|
@@ -94,7 +94,7 @@ describe ApnClient::Delivery do
|
|
94
94
|
:on_read_exception => lambda { |d, e| read_exceptions << e },
|
95
95
|
:on_error => lambda { |d, message_id, error_code| errors << [message_id, error_code] }
|
96
96
|
}
|
97
|
-
delivery = create_delivery(messages.dup, :callbacks => callbacks)
|
97
|
+
delivery = create_delivery(messages.dup, :callbacks => callbacks, :connection => {})
|
98
98
|
|
99
99
|
connection = mock('connection')
|
100
100
|
connection.expects(:write).with(@message1)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: apn_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-12-
|
12
|
+
date: 2011-12-05 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json
|
16
|
-
requirement: &
|
16
|
+
requirement: &70265276321200 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70265276321200
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rspec
|
27
|
-
requirement: &
|
27
|
+
requirement: &70265276320780 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70265276320780
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: mocha
|
38
|
-
requirement: &
|
38
|
+
requirement: &70265276320360 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70265276320360
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: yard
|
49
|
-
requirement: &
|
49
|
+
requirement: &70265276319940 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,7 +54,7 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70265276319940
|
58
58
|
description: Uses the "enhanced format" Apple protocol and deals with errors and failures
|
59
59
|
when broadcasting to many devices. Includes support for talking to the Apple Push
|
60
60
|
Notification Feedback service for dealing with uninstalled apps.
|