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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 23d63ae64ab9ac9fab8229c7cf0b43b111e413bf
4
- data.tar.gz: 1cd480f8496f07d8914fe6d4e17736d61e27fd07
3
+ metadata.gz: 19acde83274fe69f0e14d40f818a4eb7bb87d412
4
+ data.tar.gz: ce53e972d6982339045099bbafc779dfe128b9de
5
5
  SHA512:
6
- metadata.gz: aae11c2f1ec38e1976fdc735b474f0c06e1b086af37ed50672505b5f629e0b106884eb6a6de0b16699b36922d9797811118a3160132f03fc97846a44629f6968
7
- data.tar.gz: 922eb4198e2cae3aaebbb61089a05ec40d4bb821bdfbcc6ea6f0ed7bc29f7903756fa7279394f23a6b1468f5449604f872a2ea4e742c25b82d5a5097a4bbd97a
6
+ metadata.gz: 5f9ce0b3ba64b2cca3f6cf28df9f82357089c0085e53417a208b68276dd3c5d1f89f40467311a8499d390f62cf7241ade70a11affab776920097417178bc85f6
7
+ data.tar.gz: d7023aef52e8f447241a9fdf2edc8749338987cd35da29e394fc837ddcb6cd4d0db94ae08eb9180419f1964a98f79ef4ec9b0596b7343816c816d672716096c1
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bmo (0.9.0)
4
+ bmo (0.10.0)
5
5
  equalizer (~> 0.0.0)
6
6
  faraday (> 0.8.0)
7
7
 
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 :truncable_field If the payload is too large
27
- # this field will be truncated, it must be in an aps hash
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, :truncable_field, :options
39
+ attr_reader :data, :truncable_alert, :custom_data, :options
40
40
 
41
41
  def initialize(data, options = {})
42
42
  @data = data
43
- @truncable_field = options[:truncable_field]
43
+ @truncable_alert = options[:truncable_alert]
44
44
  @options = options
45
45
  end
46
46
 
47
47
  def to_package
48
- truncate_field! if truncable_field && !valid?
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 truncate_field!
66
- return unless data[:aps] && data[:aps][truncable_field]
67
- string = data[:aps][truncable_field]
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][truncable_field] = Utils
71
- .bytesize_force_truncate(string, desirable_bytesize, options)
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
@@ -1,4 +1,4 @@
1
1
  # Main BMO module, version get right here
2
2
  module BMO
3
- VERSION = '0.10.0'.freeze
3
+ VERSION = '0.11.0'.freeze
4
4
  end
@@ -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 = { truncable_field: :message }
49
- payload = described_class.new({ aps: { message: 'a' * payload_max_size } }, options)
50
- expect(payload.to_package).to eq("{\"aps\":{\"message\":\"#{'a' * (payload_max_size - 26)}...\"}}")
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 = { truncable_field: :message }
55
- payload = described_class.new({ aps: { message: 'a' * payload_max_size } }, options)
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 = { truncable_field: :message }
63
- payload = described_class.new({ aps: { message: 'a' * payload_max_size } }, options)
64
- payload.truncate_field!
65
- expect(payload.data[:aps][:message]).to eq(('a' * (payload_max_size - 26)) + '...')
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: :message, omission: '[more]' }
70
- payload = described_class.new({ aps: { message: 'a' * payload_max_size } }, options)
71
- payload.truncate_field!
72
- expect(payload.data[:aps][:message]).to eq(('a' * (payload_max_size - 29)) + '[more]')
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: :message, separator: ' ' }
77
- payload = described_class.new({ aps: { message: 'test ' + ('a' * (payload_max_size - 1)) } }, options)
78
- payload.truncate_field!
79
- expect(payload.data[:aps][:message]).to eq('test...')
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bmo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0
4
+ version: 0.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Antoine Lyset