push-apns 0.0.1.pre2 → 0.0.1.pre3

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/README.md CHANGED
@@ -1,3 +1,3 @@
1
- = PushApns
1
+ # PushApns
2
2
 
3
- This project rocks and uses MIT-LICENSE.
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
@@ -1,6 +1,6 @@
1
1
  module Push
2
2
  class MessageApns < Push::Message
3
- SELECT_TIMEOUT = 0.5
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
- # def attributes_for_device=(attrs)
25
- # raise ArgumentError, "attributes_for_device must be a Hash" if !attrs.is_a?(Hash)
26
- # write_attribute(:attributes_for_device, MultiJson.encode(attrs))
27
- # end
28
- #
29
- # def attributes_for_device
30
- # MultiJson.decode(read_attribute(:attributes_for_device)) if read_attribute(:attributes_for_device)
31
- # end
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
- #write_attribute(:alert, MultiJson.encode(alert))
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 = read_attribute(:alert)
45
- MultiJson.decode(string_or_json) rescue string_or_json
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, 0, payload_size, payload].pack("cNNccH*cca*")
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.encode(as_json)
59
+ MultiJson.dump(as_json)
61
60
  end
62
61
 
63
62
  def payload_size
@@ -1,3 +1,3 @@
1
1
  module PushApns
2
- VERSION = "0.0.1.pre2"
2
+ VERSION = "0.0.1.pre3"
3
3
  end
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.pre2
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-06-15 00:00:00.000000000 Z
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: &70242282760980 !ruby/object:Gem::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: *70242282760980
24
+ version_requirements: *70130311065320
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: push-core
27
- requirement: &70242282760440 !ruby/object:Gem::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.pre
32
+ version: 0.0.1.pre2
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70242282760440
35
+ version_requirements: *70130311063400
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: sqlite3
38
- requirement: &70242282760000 !ruby/object:Gem::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: *70242282760000
46
+ version_requirements: *70130311061660
47
47
  description: Plugin with APNS specific push information.
48
48
  email:
49
49
  - tom@tnux.net