bmo 0.10.0 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/bmo.rb +2 -2
- data/lib/bmo/apns/notification.rb +9 -8
- data/lib/bmo/version.rb +1 -1
- data/spec/bmo/apns/notification_spec.rb +26 -18
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 19acde83274fe69f0e14d40f818a4eb7bb87d412
|
4
|
+
data.tar.gz: ce53e972d6982339045099bbafc779dfe128b9de
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5f9ce0b3ba64b2cca3f6cf28df9f82357089c0085e53417a208b68276dd3c5d1f89f40467311a8499d390f62cf7241ade70a11affab776920097417178bc85f6
|
7
|
+
data.tar.gz: d7023aef52e8f447241a9fdf2edc8749338987cd35da29e394fc837ddcb6cd4d0db94ae08eb9180419f1964a98f79ef4ec9b0596b7343816c816d672716096c1
|
data/Gemfile.lock
CHANGED
data/lib/bmo.rb
CHANGED
@@ -23,8 +23,8 @@ module BMO
|
|
23
23
|
#
|
24
24
|
# @param device_token [String]
|
25
25
|
# @param data [Hash] The data you want to send
|
26
|
-
# @option options :
|
27
|
-
# this field will be truncated
|
26
|
+
# @option options :truncable_alert If the payload is too large
|
27
|
+
# this alert field will be truncated
|
28
28
|
# @option options :omission ('...') The omission in truncate
|
29
29
|
# @option options :separator The separator use in truncation
|
30
30
|
#
|
@@ -36,16 +36,16 @@ module BMO
|
|
36
36
|
# Define ==
|
37
37
|
include Equalizer.new(:data)
|
38
38
|
|
39
|
-
attr_reader :data, :
|
39
|
+
attr_reader :data, :truncable_alert, :custom_data, :options
|
40
40
|
|
41
41
|
def initialize(data, options = {})
|
42
42
|
@data = data
|
43
|
-
@
|
43
|
+
@truncable_alert = options[:truncable_alert]
|
44
44
|
@options = options
|
45
45
|
end
|
46
46
|
|
47
47
|
def to_package
|
48
|
-
|
48
|
+
truncate_alert! if truncable_alert && !valid?
|
49
49
|
validate!
|
50
50
|
package
|
51
51
|
end
|
@@ -62,13 +62,14 @@ module BMO
|
|
62
62
|
[2, json.bytes.count, json].pack('cna*')
|
63
63
|
end
|
64
64
|
|
65
|
-
def
|
66
|
-
return unless data[:aps] && data[:aps][
|
67
|
-
string = data[:aps][
|
65
|
+
def truncate_alert!
|
66
|
+
return unless data[:aps] && data[:aps][:alert]
|
67
|
+
string = data[:aps][:alert]
|
68
68
|
diff_bytesize = package.bytesize - MAX_BYTE_SIZE
|
69
69
|
desirable_bytesize = (string.bytesize - diff_bytesize) - 1
|
70
|
-
data[:aps][
|
71
|
-
|
70
|
+
data[:aps][:alert] = Utils.bytesize_force_truncate(string,
|
71
|
+
desirable_bytesize,
|
72
|
+
options)
|
72
73
|
end
|
73
74
|
|
74
75
|
def valid?
|
data/lib/bmo/version.rb
CHANGED
@@ -23,7 +23,7 @@ describe BMO::APNS::Notification::DeviceToken do
|
|
23
23
|
describe '#to_package' do
|
24
24
|
it 'returns the packaged token' do
|
25
25
|
device_token = described_class.new('0' * 64)
|
26
|
-
expect(device_token.to_package).to eq("\x00" * 32)
|
26
|
+
expect(device_token.to_package).to eq("\x01\x00 " + "\x00" * 32)
|
27
27
|
end
|
28
28
|
end
|
29
29
|
end
|
@@ -31,6 +31,13 @@ end
|
|
31
31
|
describe BMO::APNS::Notification::Payload do
|
32
32
|
let(:payload_max_size) { BMO::APNS::Notification::Payload::MAX_BYTE_SIZE }
|
33
33
|
|
34
|
+
describe 'custom_data field' do
|
35
|
+
it 'truncates if there is a truncable field and this is not valid' do
|
36
|
+
payload = described_class.new(aps: { alert: 'a' }, custom_data: { hello: 'world' })
|
37
|
+
expect(payload.to_package).to eq("\x02\x005{\"aps\":{\"alert\":\"a\"},\"custom_data\":{\"hello\":\"world\"}}")
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
34
41
|
describe '#validate!' do
|
35
42
|
it 'returns true if the payload is valid' do
|
36
43
|
payload = described_class.new(aps: 'a' * 200)
|
@@ -45,38 +52,39 @@ describe BMO::APNS::Notification::Payload do
|
|
45
52
|
|
46
53
|
describe '#to_package' do
|
47
54
|
it 'truncates if there is a truncable field and this is not valid' do
|
48
|
-
options = {
|
49
|
-
payload = described_class.new({ aps: {
|
50
|
-
|
55
|
+
options = { truncable_alert: true }
|
56
|
+
payload = described_class.new({ aps: { alert: 'a' * payload_max_size } }, options)
|
57
|
+
# I'm not able to write the hex literal for the beginning
|
58
|
+
expect(payload.to_package).to end_with("{\"aps\":{\"alert\":\"#{'a' * (payload_max_size - 27)}...\"}}")
|
51
59
|
end
|
52
60
|
|
53
61
|
it 'truncates to respect the MAX_BYTE_SIZE' do
|
54
|
-
options = {
|
55
|
-
payload = described_class.new({ aps: {
|
62
|
+
options = { truncable_alert: true }
|
63
|
+
payload = described_class.new({ aps: { alert: 'a' * payload_max_size } }, options)
|
56
64
|
expect(payload.to_package.bytesize).to be < BMO::APNS::Notification::Payload::MAX_BYTE_SIZE
|
57
65
|
end
|
58
66
|
end
|
59
67
|
|
60
68
|
describe '#truncable_field!' do
|
61
69
|
it 'truncates the corresponding field in aps' do
|
62
|
-
options = {
|
63
|
-
payload = described_class.new({ aps: {
|
64
|
-
payload.
|
65
|
-
expect(payload.data[:aps][:
|
70
|
+
options = { truncable_alert: true }
|
71
|
+
payload = described_class.new({ aps: { alert: 'a' * payload_max_size } }, options)
|
72
|
+
payload.truncate_alert!
|
73
|
+
expect(payload.data[:aps][:alert]).to eq(('a' * (payload_max_size - 27)) + '...')
|
66
74
|
end
|
67
75
|
|
68
76
|
it 'truncates with omission' do
|
69
|
-
options = { truncable_field: :
|
70
|
-
payload = described_class.new({ aps: {
|
71
|
-
payload.
|
72
|
-
expect(payload.data[:aps][:
|
77
|
+
options = { truncable_field: :true, omission: '[more]' }
|
78
|
+
payload = described_class.new({ aps: { alert: 'a' * payload_max_size } }, options)
|
79
|
+
payload.truncate_alert!
|
80
|
+
expect(payload.data[:aps][:alert]).to eq(('a' * (payload_max_size - 30)) + '[more]')
|
73
81
|
end
|
74
82
|
|
75
83
|
it 'truncates with separator' do
|
76
|
-
options = { truncable_field:
|
77
|
-
payload = described_class.new({ aps: {
|
78
|
-
payload.
|
79
|
-
expect(payload.data[:aps][:
|
84
|
+
options = { truncable_field: true, separator: ' ' }
|
85
|
+
payload = described_class.new({ aps: { alert: 'test ' + ('a' * (payload_max_size - 1)) } }, options)
|
86
|
+
payload.truncate_alert!
|
87
|
+
expect(payload.data[:aps][:alert]).to eq('test...')
|
80
88
|
end
|
81
89
|
end
|
82
90
|
end
|