apns_simple 2.0.1 → 3.0.0

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: 083a2f6f357cf191171c1fd269dcbe0ddc2a0234
4
- data.tar.gz: 3ca55a10969b58b116b27639a1033ca1e0d7c8a8
3
+ metadata.gz: 8deda36c16dcb9ad3c41e424a1287ff60eb8a697
4
+ data.tar.gz: c97fb5afd36ac51258a296e92db15fe892f3ef95
5
5
  SHA512:
6
- metadata.gz: 39468ed65f788b1aad13646a3f0b957902c6d8fadea4df97f31327af86b744b95e00879c1b9716b684d0683ddff4edd95a05f681eb04981bf970c3c2754186e5
7
- data.tar.gz: a4311fcd01529137b516fd2007b36075afb17e1af1203a1031fcdafdcee0ee11aa805f2c1b1060a90a6c41c2f47ad13f28ad4fa8215c2c8d66e1a9f0c7631d8a
6
+ metadata.gz: 74e50f9fc9ec6318efba324e28cb91b516328afc705919fba338ccc53caf8bf87e9654ccf9e9fb9cbb8e13cc483412956646edced509ede5729ef465bb33dd54
7
+ data.tar.gz: 744fa284a241194ae723b5540088dfbdda41e385dd38fb23447141e1c6aee312e7a9b10aec47ff548234b9636264b242f0cf0bf495c35a01ce74eacfd7db0102
@@ -22,17 +22,37 @@ module ApnsSimple
22
22
  payload_hash[:aps]['content-available'] = 1 if content_available
23
23
  payload_hash.merge! custom_payload
24
24
 
25
- packed_token = [token.gsub(/[<\s>]/,'')].pack('H*')
26
- packed_message = payload_hash.to_json.gsub(/\\u([\da-fA-F]{4})/) {|m| [$1].pack("H*").unpack("n*").pack("U*")}
27
- payload_size = packed_message.bytesize
25
+ token_item = pack_token_item(token)
26
+ payload_item = pack_payload_item(payload_hash)
27
+ frame = compose_frame(token_item, payload_item)
28
+ @payload = pack_frame(frame)
29
+ end
30
+
31
+ private
28
32
 
29
- if payload_size > PAYLOAD_MAX_BYTESIZE
30
- self.error = true
31
- self.error_message = "Payload size is #{payload_size} bytes but maximum #{PAYLOAD_MAX_BYTESIZE} bytes allowed."
33
+ def pack_frame(frame)
34
+ [2, frame.bytesize, frame].pack('cNa*')
32
35
  end
33
36
 
34
- @payload = [0, 0, 32, packed_token, 0, payload_size, packed_message].pack("ccca*cca*")
35
- end
37
+ def compose_frame(*args)
38
+ args.compact.join
39
+ end
40
+
41
+ def pack_token_item(token)
42
+ [1, 32, token.gsub(/[<\s>]/, '')].pack('cnH64')
43
+ end
44
+
45
+ def pack_payload_item(hash)
46
+ json = hash.to_json.gsub(/\\u([\da-fA-F]{4})/) { |m| [$1].pack('H*').unpack('n*').pack('U*') }
47
+ size = json.bytesize
48
+
49
+ if size > PAYLOAD_MAX_BYTESIZE
50
+ self.error = true
51
+ self.error_message = "Payload size is #{size} bytes but maximum #{PAYLOAD_MAX_BYTESIZE} bytes allowed."
52
+ end
53
+
54
+ [2, size, json].pack('cna*')
55
+ end
36
56
 
37
57
  end
38
58
  end
@@ -1,3 +1,3 @@
1
1
  module ApnsSimple
2
- VERSION = '2.0.1'
2
+ VERSION = '3.0.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apns_simple
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrey Voronkov