mercurius 0.1.9 → 0.2.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 +4 -4
- data/lib/mercurius/apns/notification.rb +21 -13
- data/lib/mercurius/version.rb +1 -1
- data/spec/lib/apns_notification_spec.rb +16 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 68382188ef199ed571c96140d38fbec9c6e83981
|
4
|
+
data.tar.gz: 9642812648df51e4312892f026ef67475a910e06
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
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
|
34
|
-
|
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(/[
|
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
|
43
|
-
|
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
|
data/lib/mercurius/version.rb
CHANGED
@@ -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.
|
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:
|
11
|
+
date: 2016-01-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|