push-apns 0.0.1.pre2 → 0.0.1.pre3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +2 -2
- data/lib/push/daemon/apns_support/connection_apns.rb +19 -0
- data/lib/push/message_apns.rb +15 -16
- data/lib/push-apns/version.rb +1 -1
- metadata +9 -9
data/README.md
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
|
1
|
+
# PushApns
|
2
2
|
|
3
|
-
|
3
|
+
Please see [push-core](https://github.com/tompesman/push-core) for more information.
|
@@ -3,6 +3,8 @@ module Push
|
|
3
3
|
module ApnsSupport
|
4
4
|
class ConnectionApns
|
5
5
|
attr_reader :name, :provider
|
6
|
+
attr_accessor :last_write
|
7
|
+
IDLE_PERIOD = 30.minutes
|
6
8
|
|
7
9
|
def initialize(provider, i=nil)
|
8
10
|
@provider = provider
|
@@ -16,6 +18,7 @@ module Push
|
|
16
18
|
@host = "feedback.#{provider.configuration[:sandbox] ? 'sandbox.' : ''}push.apple.com"
|
17
19
|
@port = 2196
|
18
20
|
end
|
21
|
+
written
|
19
22
|
end
|
20
23
|
|
21
24
|
def connect
|
@@ -40,6 +43,8 @@ module Push
|
|
40
43
|
end
|
41
44
|
|
42
45
|
def write(data)
|
46
|
+
reconnect_idle if idle_period_exceeded?
|
47
|
+
|
43
48
|
retry_count = 0
|
44
49
|
|
45
50
|
begin
|
@@ -68,9 +73,23 @@ module Push
|
|
68
73
|
|
69
74
|
protected
|
70
75
|
|
76
|
+
def reconnect_idle
|
77
|
+
Push::Daemon.logger.info("[#{@name}] Idle period exceeded, reconnecting...")
|
78
|
+
reconnect
|
79
|
+
end
|
80
|
+
|
81
|
+
def idle_period_exceeded?
|
82
|
+
Time.now - last_write > IDLE_PERIOD
|
83
|
+
end
|
84
|
+
|
71
85
|
def write_data(data)
|
72
86
|
@ssl_socket.write(data)
|
73
87
|
@ssl_socket.flush
|
88
|
+
written
|
89
|
+
end
|
90
|
+
|
91
|
+
def written
|
92
|
+
self.last_write = Time.now
|
74
93
|
end
|
75
94
|
|
76
95
|
def setup_ssl_context
|
data/lib/push/message_apns.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Push
|
2
2
|
class MessageApns < Push::Message
|
3
|
-
SELECT_TIMEOUT = 0.
|
3
|
+
SELECT_TIMEOUT = 0.2
|
4
4
|
ERROR_TUPLE_BYTES = 6
|
5
5
|
APN_ERRORS = {
|
6
6
|
1 => "Processing error",
|
@@ -15,41 +15,40 @@ module Push
|
|
15
15
|
}
|
16
16
|
|
17
17
|
store :properties, accessors: [:alert, :badge, :sound, :expiry, :attributes_for_device]
|
18
|
+
attr_accessible :device, :alert, :badge, :sound, :expiry, :attributes_for_device
|
18
19
|
|
19
20
|
validates :badge, :numericality => true, :allow_nil => true
|
20
21
|
validates :expiry, :numericality => true, :presence => true
|
21
22
|
validates :device, :format => { :with => /\A[a-z0-9]{64}\z/ }
|
22
23
|
validates_with Push::Apns::BinaryNotificationValidator
|
23
24
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
25
|
+
def attributes_for_device=(attrs)
|
26
|
+
raise ArgumentError, "attributes_for_device must be a Hash" if !attrs.is_a?(Hash)
|
27
|
+
properties[:attributes_for_device] = MultiJson.dump(attrs)
|
28
|
+
end
|
29
|
+
|
30
|
+
def attributes_for_device
|
31
|
+
MultiJson.load(properties[:attributes_for_device]) if properties[:attributes_for_device]
|
32
|
+
end
|
32
33
|
|
33
34
|
def alert=(alert)
|
34
35
|
if alert.is_a?(Hash)
|
35
|
-
|
36
|
-
properties[:alert] = MultiJson.encode(alert)
|
36
|
+
properties[:alert] = MultiJson.dump(alert)
|
37
37
|
else
|
38
|
-
#write_attribute(:alert, alert)
|
39
38
|
properties[:alert] = alert
|
40
39
|
end
|
41
40
|
end
|
42
41
|
|
43
42
|
def alert
|
44
|
-
string_or_json =
|
45
|
-
MultiJson.
|
43
|
+
string_or_json = properties[:alert]
|
44
|
+
MultiJson.load(string_or_json) rescue string_or_json
|
46
45
|
end
|
47
46
|
|
48
47
|
# This method conforms to the enhanced binary format.
|
49
48
|
# http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CommunicatingWIthAPS/CommunicatingWIthAPS.html#//apple_ref/doc/uid/TP40008194-CH101-SW4
|
50
49
|
def to_message(options = {})
|
51
50
|
id_for_pack = options[:for_validation] ? 0 : id
|
52
|
-
[1, id_for_pack, expiry, 0, 32, device,
|
51
|
+
[1, id_for_pack, expiry, 0, 32, device, payload_size, payload].pack("cNNccH*na*")
|
53
52
|
end
|
54
53
|
|
55
54
|
def use_connection
|
@@ -57,7 +56,7 @@ module Push
|
|
57
56
|
end
|
58
57
|
|
59
58
|
def payload
|
60
|
-
MultiJson.
|
59
|
+
MultiJson.dump(as_json)
|
61
60
|
end
|
62
61
|
|
63
62
|
def payload_size
|
data/lib/push-apns/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: push-apns
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.1.
|
4
|
+
version: 0.0.1.pre3
|
5
5
|
prerelease: 6
|
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: 2012-
|
12
|
+
date: 2012-07-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: multi_json
|
16
|
-
requirement: &
|
16
|
+
requirement: &70130311065320 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,21 +21,21 @@ dependencies:
|
|
21
21
|
version: '1.0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70130311065320
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: push-core
|
27
|
-
requirement: &
|
27
|
+
requirement: &70130311063400 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - =
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: 0.0.1.
|
32
|
+
version: 0.0.1.pre2
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70130311063400
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: sqlite3
|
38
|
-
requirement: &
|
38
|
+
requirement: &70130311061660 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70130311061660
|
47
47
|
description: Plugin with APNS specific push information.
|
48
48
|
email:
|
49
49
|
- tom@tnux.net
|