mercurius 0.1.9 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c407384556945caff8534e28bb17bc33eeb1e804
4
- data.tar.gz: fb500925edc12008a2cf11653699083f37995d18
3
+ metadata.gz: 68382188ef199ed571c96140d38fbec9c6e83981
4
+ data.tar.gz: 9642812648df51e4312892f026ef67475a910e06
5
5
  SHA512:
6
- metadata.gz: 060ef7919702f1ca15acbb7f501fcaee491da68f5d5a416ecc49e57c84eef62c07abeff7afebacd9d1479ed56e74d270261789622b7cc30ec9f6d36c4c045153
7
- data.tar.gz: dd66a90ef1b5a22689bebf352700b4303bbe24993c24119df9b3782af55f3a0acfba3d23e3d5832054237159fd854f2928a9e6b636b019c2e32df4d9d4b7c91b
6
+ metadata.gz: 091b2149bae4a550f06bfff6192fc6e349c03d15e3029b659f76579c0ad8116fe62808221ee21a25c48ce7441272e2aee79da7d5e2b84533ac740417a50622bd
7
+ data.tar.gz: e9c41c7b95fc140548ab2cf28176f2db9fb6b07f9f343f5067523cf2785c966dcfa433331a655416be722e4b3fa1c788c925a58a35b0c113a0635248e372a70e
@@ -7,6 +7,8 @@ module APNS
7
7
  attr_accessor :alert, :badge, :sound, :other, :content_available
8
8
  attr_reader :attributes
9
9
 
10
+ validate :payload_size_under_limit
11
+
10
12
  def initialize(attributes = {})
11
13
  @attributes = attributes
12
14
  super
@@ -18,31 +20,37 @@ module APNS
18
20
  'badge' => badge,
19
21
  'sound' => sound,
20
22
  'other' => other,
21
- 'content-available' => content_available,
23
+ 'content-available' => content_available
22
24
  }.compact
23
25
  end
24
26
 
25
27
  def pack(device_token)
26
- [0, 0, 32, package_device_token(device_token), 0, packaged_message.bytesize, packaged_message].pack("ccca*cca*")
27
- end
28
-
29
- def ==(that)
30
- attributes == that.attributes
28
+ data = [
29
+ package_device_token(device_token),
30
+ packaged_payload
31
+ ].compact.join
32
+ [2, data.bytes.count, data].pack 'cNa*'
31
33
  end
32
34
 
33
- def valid?
34
- packaged_message.bytesize <= MAX_PAYLOAD_BYTES
35
+ def ==(other)
36
+ attributes == other.attributes
35
37
  end
36
38
 
37
39
  private
38
40
  def package_device_token(device_token)
39
- [device_token.gsub(/[\s|<|>]/,'')].pack('H*')
41
+ [1, 32, device_token.gsub(/[<\s>]/, '')].pack('cnH64')
42
+ end
43
+
44
+ def packaged_payload
45
+ [2, payload_json.bytes.count, payload_json].pack('cna*')
46
+ end
47
+
48
+ def payload_json
49
+ payload.to_json
40
50
  end
41
51
 
42
- def packaged_message
43
- { aps: payload }.to_json.gsub(/\\u([\da-fA-F]{4})/) do |m|
44
- [$1].pack("H*").unpack("n*").pack("U*")
45
- end
52
+ def payload_size_under_limit
53
+ payload_json.bytesize <= MAX_PAYLOAD_BYTES
46
54
  end
47
55
  end
48
56
  end
@@ -1,3 +1,3 @@
1
1
  module Mercurius
2
- VERSION = '0.1.9'
2
+ VERSION = '0.2.0'
3
3
  end
@@ -1,4 +1,20 @@
1
1
  describe APNS::Notification do
2
+ describe 'validations' do
3
+ it 'is invalid if the payload JSON is too big' do
4
+ expect(subject).to receive(:payload) { 'X' * (APNS::Notification::MAX_PAYLOAD_BYTES + 1) }
5
+ expect(subject).to be_valid
6
+ end
7
+
8
+ it 'is valid if the payload JSON is not too big' do
9
+ expect(subject).to receive(:payload) { 'X' * (APNS::Notification::MAX_PAYLOAD_BYTES - 1) }
10
+ expect(subject).to be_valid
11
+ end
12
+
13
+ it 'is valid when the payload is just right' do
14
+ expect(subject).to receive(:payload) { 'X' * (APNS::Notification::MAX_PAYLOAD_BYTES) }
15
+ expect(subject).to be_valid
16
+ end
17
+ end
2
18
 
3
19
  describe '#==' do
4
20
  it 'doesnt care about object equality' do
@@ -16,5 +32,4 @@ describe APNS::Notification do
16
32
  end
17
33
  end
18
34
  end
19
-
20
35
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mercurius
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Beck
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-10 00:00:00.000000000 Z
11
+ date: 2016-01-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json