pushr-apns 1.0.0.pre.1 → 1.0.0.pre.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cc63a9d097c133a4caf7e2fe309d18c1d344440f
4
- data.tar.gz: 4da07aeccda83b5c40ee1c0833ad54a25ba6af74
3
+ metadata.gz: 5181efd03d6487fde7a093fa325893e2ea32a540
4
+ data.tar.gz: 6de48a3c06fa85bc2528929b68cf8da9edb53a13
5
5
  SHA512:
6
- metadata.gz: 9d21d622874f347b12241dc570c4f48506cd34570e4d8ccf68ee41e413f5a739fc865a07f47a7be1e389906a9f2112de3910078641aca96a212f3380f9980f83
7
- data.tar.gz: 743a1c257e31d7ec9236ce437f77bed12a17a87a6800728c0590032119298f125cd09c9d91554c53630c1f6a5073437a9d6b0c65ef37fab5f4386e3a6b465bd3
6
+ metadata.gz: 936533c37781f04415a8e4f63e49e79f9aea36f16db3b848df645b29681342e154190145bd79677bd2bee359df817069919da853c889d53a01f79c4eb9caffd8
7
+ data.tar.gz: 55296d2a67c8cacd82a38f9841231a73bb5bb06e243b667235b2e81ea935bf55312c7f6029943403295073e840bfb645871dc8af461ea060035f5931bf226ffb
@@ -4,7 +4,7 @@ module Pushr
4
4
  :sandbox, :feedback_poll, :skip_check_for_error
5
5
  validates :certificate, presence: true
6
6
  validates :sandbox, inclusion: { in: [true, false] }
7
- validates :feedback_poll, presence: true
7
+ validates :feedback_poll, numericality: true, presence: true
8
8
  validates :skip_check_for_error, inclusion: { in: [true, false] }, allow_blank: true
9
9
 
10
10
  def name
@@ -22,7 +22,7 @@ module Pushr
22
22
 
23
23
  def stop
24
24
  @stop = true
25
- @interruptible_sleep.interrupt_sleep
25
+ @interruptible_sleep.interrupt
26
26
  @thread.join if @thread
27
27
  end
28
28
 
@@ -2,44 +2,16 @@ module Pushr
2
2
  module Daemon
3
3
  module ApnsSupport
4
4
  class InterruptibleSleep
5
-
6
- def initialize
7
- @sleep_reader, @wake_writer = IO.pipe
8
- end
9
-
10
- # wait for the given timeout in seconds, or data was written to the pipe.
11
- # @return [boolean] true if the sleep was interrupted, or false
12
- def sleep(timeout)
13
- read_ports = [@sleep_reader]
14
- rs, = IO.select(read_ports, nil, nil, timeout) rescue nil
15
-
16
- # consume all data on the readable io's so that our next call will wait for more data
17
- perform_io(rs, @sleep_reader, :read_nonblock)
18
-
19
- !rs.nil? && rs.any?
5
+ def sleep(seconds)
6
+ @_sleep_check, @_sleep_interrupt = IO.pipe
7
+ IO.select([@_sleep_check], nil, nil, seconds)
8
+ @_sleep_check.close rescue IOError
9
+ @_sleep_interrupt.close rescue IOError
20
10
  end
21
11
 
22
- # writing to the pipe will wake the sleeping thread
23
- def interrupt_sleep
24
- @wake_writer.write('.')
25
- end
26
-
27
- def close
28
- @sleep_reader.close rescue nil
29
- @wake_writer.close rescue nil
30
- end
31
-
32
- private
33
-
34
- def perform_io(selected, io, meth)
35
- if selected && selected.include?(io)
36
- while true
37
- begin
38
- io.__send__(meth, 1)
39
- rescue Errno::EAGAIN, IO::WaitReadable
40
- break
41
- end
42
- end
12
+ def interrupt
13
+ if @_sleep_interrupt
14
+ @_sleep_interrupt.close rescue IOError
43
15
  end
44
16
  end
45
17
  end
@@ -2,11 +2,13 @@ module Pushr
2
2
  class MessageApns < Pushr::Message
3
3
  POSTFIX = 'apns'
4
4
 
5
- attr_accessor :type, :app, :device, :alert, :badge, :sound, :expiry, :attributes_for_device
5
+ attr_accessor :type, :app, :device, :alert, :badge, :sound, :expiry, :attributes_for_device, :content_available, :priority
6
6
 
7
7
  validates :badge, numericality: true, allow_nil: true
8
8
  validates :expiry, numericality: true, presence: true
9
9
  validates :device, format: { with: /\A[a-z0-9]{64}\z/ }
10
+ validates :priority, inclusion: { in: [5, 10] }
11
+ validates :content_available, inclusion: { in: [1] }, allow_nil: true
10
12
  validate :max_payload_size
11
13
 
12
14
  def alert=(alert)
@@ -24,10 +26,18 @@ module Pushr
24
26
  return string_or_json
25
27
  end
26
28
 
27
- # This method conforms to the enhanced binary format.
28
- # http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CommunicatingWIthAPS/CommunicatingWIthAPS.html#//apple_ref/doc/uid/TP40008194-CH101-SW4
29
+ def id
30
+ @id ||= OpenSSL::Random.random_bytes(4)
31
+ end
32
+
29
33
  def to_message
30
- [1, 0, expiry, 0, 32, device, payload_size, payload].pack('cNNccH*na*')
34
+ data = ''
35
+ data << [1, [device].pack('H*').bytesize, [device].pack('H*')].pack('CnA*')
36
+ data << [2, payload.bytesize, payload].pack('CnA*')
37
+ data << [3, id.bytesize, id].pack('CnA*')
38
+ data << [4, 4, expiry].pack('CnN')
39
+ data << [5, 1, priority].pack('CnC')
40
+ ([2, data.bytesize].pack('CN') + data)
31
41
  end
32
42
 
33
43
  def payload
@@ -40,7 +50,8 @@ module Pushr
40
50
 
41
51
  def to_json
42
52
  hsh = { type: self.class.to_s, app: app, device: device, alert: alert, badge: badge,
43
- sound: sound, expiry: expiry, attributes_for_device: attributes_for_device }
53
+ sound: sound, expiry: expiry, attributes_for_device: attributes_for_device,
54
+ content_available: content_available, priority: priority }
44
55
  MultiJson.dump(hsh)
45
56
  end
46
57
 
@@ -52,6 +63,7 @@ module Pushr
52
63
  json['aps']['alert'] = alert if alert
53
64
  json['aps']['badge'] = badge if badge
54
65
  json['aps']['sound'] = sound if sound
66
+ json['aps']['content-available'] = content_available if content_available
55
67
  attributes_for_device.each { |k, v| json[k.to_s] = v.to_s } if attributes_for_device
56
68
  json
57
69
  end
@@ -1,3 +1,3 @@
1
1
  module PushrApns
2
- VERSION = '1.0.0.pre.1'
2
+ VERSION = '1.0.0.pre.2'
3
3
  end
@@ -30,8 +30,8 @@ describe Pushr::Daemon::ApnsSupport::ConnectionApns do
30
30
  Pushr::ConfigurationApns.new(app: 'app_name', connections: 2, enabled: true, certificate: certificate)
31
31
  end
32
32
  let(:message) do
33
- hsh = { app: 'app_name', device: 'a' * 64, alert: 'message',
34
- badge: 1, sound: '1.aiff', expiry: 24 * 60 * 60, attributes_for_device: { key: 'test' } }
33
+ hsh = { app: 'app_name', device: 'a' * 64, alert: 'message', badge: 1, sound: '1.aiff', expiry: 24 * 60 * 60,
34
+ attributes_for_device: { key: 'test' }, priority: 10 }
35
35
  Pushr::MessageApns.new(hsh)
36
36
  end
37
37
  let(:connection) { Pushr::Daemon::ApnsSupport::ConnectionApns.new(config, 1) }
@@ -11,7 +11,8 @@ describe Pushr::Daemon::ApnsSupport::InterruptibleSleep do
11
11
 
12
12
  it 'creates a new pipe' do
13
13
  expect(IO).to receive(:pipe).and_return([rd, wr])
14
- subject
14
+ allow(IO).to receive(:select).with([rd], nil, nil, 1)
15
+ subject.sleep(1)
15
16
  end
16
17
 
17
18
  it 'selects on the reader' do
@@ -22,17 +23,9 @@ describe Pushr::Daemon::ApnsSupport::InterruptibleSleep do
22
23
 
23
24
  it 'closes the writer' do
24
25
  allow(IO).to receive(:pipe).and_return([rd, wr])
25
- expect(rd).to receive(:close)
26
+ allow(IO).to receive(:select).with([rd], nil, nil, 1)
26
27
  expect(wr).to receive(:close)
27
- subject.close
28
- end
29
-
30
- it 'returns false when timeout occurs' do
31
- expect(subject.sleep(0.01)).to eql false
32
- end
33
-
34
- it 'returns true when sleep does not timeout' do
35
- subject.interrupt_sleep
36
- expect(subject.sleep(0.01)).to eql true
28
+ subject.sleep(1)
29
+ subject.interrupt
37
30
  end
38
31
  end
@@ -17,8 +17,8 @@ describe Pushr::MessageApns do
17
17
 
18
18
  describe 'save' do
19
19
  let(:message) do
20
- hsh = { app: 'app_name', device: 'a' * 64, alert: 'message',
21
- badge: 1, sound: '1.aiff', expiry: 24 * 60 * 60, attributes_for_device: { key: 'test' } }
20
+ hsh = { app: 'app_name', device: 'a' * 64, alert: 'message', badge: 1, sound: '1.aiff',
21
+ expiry: 24 * 60 * 60, attributes_for_device: { key: 'test' }, priority: 10 }
22
22
  Pushr::MessageApns.new(hsh)
23
23
  end
24
24
 
@@ -32,7 +32,5 @@ describe Pushr::MessageApns do
32
32
  it 'should respond to to_message' do
33
33
  expect(message.to_message).to be_kind_of(String)
34
34
  end
35
-
36
- # TODO: add more tests
37
35
  end
38
36
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pushr-apns
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.pre.1
4
+ version: 1.0.0.pre.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Pesman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-09 00:00:00.000000000 Z
11
+ date: 2014-05-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multi_json
@@ -195,7 +195,8 @@ files:
195
195
  - spec/support/cert_with_password.pem
196
196
  - spec/support/cert_without_password.pem
197
197
  homepage: https://github.com/tompesman/pushr-apns
198
- licenses: []
198
+ licenses:
199
+ - MIT
199
200
  metadata: {}
200
201
  post_install_message:
201
202
  rdoc_options: []
@@ -205,7 +206,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
205
206
  requirements:
206
207
  - - ">="
207
208
  - !ruby/object:Gem::Version
208
- version: '0'
209
+ version: 1.9.3
209
210
  required_rubygems_version: !ruby/object:Gem::Requirement
210
211
  requirements:
211
212
  - - ">"