grocer 0.3.3 → 0.3.4

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.
data/CHANGELOG.md CHANGED
@@ -1,8 +1,16 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.3.4
4
+
5
+ * Add `Grocer::MobileDeviceManagementNotification` to send PushMagic tokens.
6
+ ([Osis](https://github.com/Osis))
7
+ * Fix `Grocer::NewsstandNotification` payload
8
+ ([khelll](https://github.com/khelll))
9
+
3
10
  ## 0.3.3
4
11
 
5
- * Notifications that only include a custom payload are now valid. ([overlycommonname](https://github.com/overlycommonname))
12
+ * Notifications that only include a custom payload are now valid.
13
+ ([overlycommonname](https://github.com/overlycommonname))
6
14
 
7
15
  ## 0.3.2
8
16
 
@@ -0,0 +1,25 @@
1
+ require 'grocer/notification'
2
+
3
+ module Grocer
4
+ # Public: A specialized form of a Grocer::Notification which only requires a
5
+ # `push_magic` and `device_token` to be present in the payload.
6
+ #
7
+ # Examples
8
+ #
9
+ # Grocer::MobileDeviceManagementNotification.new(device_token: '...', push_magic: '...')
10
+ class MobileDeviceManagementNotification < Notification
11
+ attr_accessor :push_magic
12
+
13
+ private
14
+
15
+ def payload_hash
16
+ { mdm: push_magic }
17
+ end
18
+
19
+ def validate_payload
20
+ fail NoPayloadError unless push_magic
21
+ fail InvalidFormatError if alert || badge || custom
22
+ fail PayloadTooLargeError if payload_too_large?
23
+ end
24
+ end
25
+ end
@@ -8,6 +8,7 @@ module Grocer
8
8
  # Examples
9
9
  #
10
10
  # Grocer::NewsstandNotification.new(device_token: '...')
11
+ # #=> { aps: { 'content-available' => 1 } }
11
12
  class NewsstandNotification < Notification
12
13
 
13
14
  private
@@ -15,9 +16,9 @@ module Grocer
15
16
  def validate_payload
16
17
  true
17
18
  end
18
-
19
+
19
20
  def payload_hash
20
- { "content-available" => 1 }
21
+ { aps: {'content-available' => 1} }
21
22
  end
22
23
 
23
24
  end
@@ -1,3 +1,3 @@
1
1
  module Grocer
2
- VERSION = '0.3.3'
2
+ VERSION = '0.3.4'
3
3
  end
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+ require 'grocer/mobile_device_management_notification'
3
+ require 'grocer/shared_examples_for_notifications'
4
+
5
+ describe Grocer::MobileDeviceManagementNotification do
6
+ let(:payload_from_bytes) { notification.to_bytes[45..-1] }
7
+ let(:payload_dictionary_from_bytes) { JSON.parse(payload_from_bytes, symbolize_names: true) }
8
+
9
+ describe 'binary format' do
10
+ let(:payload_options) { Hash[:push_magic, "00000000-1111-3333-4444-555555555555"] }
11
+
12
+ include_examples 'a notification'
13
+
14
+ it 'should have a single key in the payload' do
15
+ expect(payload_dictionary_from_bytes.length).to eq(1)
16
+ end
17
+
18
+ it 'does require a mdm payload' do
19
+ expect(payload_dictionary_from_bytes[:'mdm']).to_not be_nil
20
+ end
21
+ end
22
+
23
+ describe 'no push magic specified' do
24
+ let(:notification) { Grocer::MobileDeviceManagementNotification.new(device_token: "token", alert: "Moo") }
25
+
26
+ it 'should raise a payload error' do
27
+ -> { notification.to_bytes }.should raise_error(Grocer::NoPayloadError)
28
+ end
29
+ end
30
+
31
+ describe 'aps object is included in the payload' do
32
+ let(:notification) { Grocer::MobileDeviceManagementNotification.new(device_token: "token", push_magic: "00000000-1111-3333-4444-555555555555", alert: "test") }
33
+
34
+ it 'should raise a format error' do
35
+ -> { payload_dictionary_from_bytes }.should raise_error(Grocer::InvalidFormatError)
36
+ end
37
+ end
38
+ end
@@ -5,18 +5,16 @@ require 'grocer/shared_examples_for_notifications'
5
5
  describe Grocer::NewsstandNotification do
6
6
  describe 'binary format' do
7
7
  let(:payload_options) { Hash.new }
8
- let(:payload_from_bytes) { notification.to_bytes[45..-1] }
9
- let(:payload_dictionary_from_bytes) { JSON.parse(payload_from_bytes, symbolize_names: true) }
8
+ let(:payload) { payload_hash(notification) }
10
9
 
11
10
  include_examples 'a notification'
12
11
 
13
- it 'does require a payload' do
14
- expect(payload_dictionary_from_bytes[:'content-available']).to_not be_nil
12
+ it 'requires a payload' do
13
+ expect(payload[:aps]).to_not be_empty
15
14
  end
16
15
 
17
- it 'has a content-available hash' do
18
- expect(payload_dictionary_from_bytes[:'content-available']).to eq(1)
16
+ it 'encodes content-available as part of the payload' do
17
+ expect(payload[:aps][:'content-available']).to eq(1)
19
18
  end
20
-
21
19
  end
22
20
  end
@@ -6,44 +6,43 @@ require 'grocer/shared_examples_for_notifications'
6
6
  describe Grocer::Notification do
7
7
  describe 'binary format' do
8
8
  let(:payload_options) { { alert: 'hi', badge: 2, sound: 'siren.aiff' } }
9
- let(:payload_dictionary_from_bytes) { JSON.parse(payload_from_bytes, symbolize_names: true) }
10
- let(:payload_from_bytes) { notification.to_bytes[45..-1] }
9
+ let(:payload) { payload_hash(notification) }
11
10
 
12
11
  include_examples 'a notification'
13
12
 
14
13
  it 'encodes alert as part of the payload' do
15
14
  notification.alert = 'Hello World!'
16
- expect(payload_dictionary_from_bytes[:aps][:alert]).to eq('Hello World!')
15
+ expect(payload[:aps][:alert]).to eq('Hello World!')
17
16
  end
18
17
 
19
18
  it 'encodes badge as part of the payload' do
20
19
  notification.badge = 42
21
- expect(payload_dictionary_from_bytes[:aps][:badge]).to eq(42)
20
+ expect(payload[:aps][:badge]).to eq(42)
22
21
  end
23
22
 
24
23
  it 'encodes sound as part of the payload' do
25
24
  notification.sound = 'siren.aiff'
26
- expect(payload_dictionary_from_bytes[:aps][:sound]).to eq('siren.aiff')
25
+ expect(payload[:aps][:sound]).to eq('siren.aiff')
27
26
  end
28
27
 
29
28
  it 'encodes custom payload attributes' do
30
29
  notification.custom = { :foo => 'bar' }
31
- expect(payload_dictionary_from_bytes[:foo]).to eq('bar')
30
+ expect(payload[:foo]).to eq('bar')
32
31
  end
33
32
 
34
33
  it 'encodes UTF-8 characters' do
35
34
  notification.alert = '私'
36
- expect(payload_dictionary_from_bytes[:aps][:alert].force_encoding("UTF-8")).to eq('私')
35
+ expect(payload[:aps][:alert].force_encoding("UTF-8")).to eq('私')
37
36
  end
38
37
 
39
38
  it 'encodes the payload length' do
40
39
  notification.alert = 'Hello World!'
41
- expect(bytes[43...45]).to eq([payload_from_bytes.bytesize].pack('n'))
40
+ expect(bytes[43...45]).to eq([payload_bytes(notification).bytesize].pack('n'))
42
41
  end
43
42
 
44
43
  it 'encodes the payload length correctly for multibyte UTF-8 strings' do
45
44
  notification.alert = '私'
46
- expect(bytes[43...45]).to eq([payload_from_bytes.bytesize].pack('n'))
45
+ expect(bytes[43...45]).to eq([payload_bytes(notification).bytesize].pack('n'))
47
46
  end
48
47
 
49
48
  context 'missing payload' do
@@ -5,13 +5,11 @@ require 'grocer/shared_examples_for_notifications'
5
5
  describe Grocer::PassbookNotification do
6
6
  describe 'binary format' do
7
7
  let(:payload_options) { Hash.new }
8
- let(:payload_dictionary_from_bytes) { JSON.parse(payload_from_bytes, symbolize_names: true) }
9
- let(:payload_from_bytes) { notification.to_bytes[45..-1] }
10
8
 
11
9
  include_examples 'a notification'
12
10
 
13
11
  it 'does not require a payload' do
14
- expect(payload_dictionary_from_bytes[:aps]).to be_empty
12
+ expect(payload_hash(notification)[:aps]).to be_empty
15
13
  end
16
14
 
17
15
  it 'encodes the payload length' do
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  ENV['RACK_ENV'] = 'test'
2
2
  require 'mocha/api'
3
3
  require 'bourne'
4
+ require 'support/notification_helpers'
4
5
 
5
6
  RSpec.configure do |config|
6
7
  config.treat_symbols_as_metadata_keys_with_true_values = true
@@ -8,4 +9,6 @@ RSpec.configure do |config|
8
9
  config.filter_run :focus
9
10
 
10
11
  config.mock_with :mocha
12
+
13
+ config.include NotificationHelpers
11
14
  end
@@ -0,0 +1,9 @@
1
+ module NotificationHelpers
2
+ def payload_hash(notification)
3
+ JSON.parse(payload_bytes(notification), symbolize_names: true)
4
+ end
5
+
6
+ def payload_bytes(notification)
7
+ notification.to_bytes[45..-1]
8
+ end
9
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grocer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2013-03-12 00:00:00.000000000 Z
14
+ date: 2013-03-15 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rspec
@@ -122,6 +122,7 @@ files:
122
122
  - lib/grocer/failed_delivery_attempt.rb
123
123
  - lib/grocer/feedback.rb
124
124
  - lib/grocer/feedback_connection.rb
125
+ - lib/grocer/mobile_device_management_notification.rb
125
126
  - lib/grocer/newsstand_notification.rb
126
127
  - lib/grocer/notification.rb
127
128
  - lib/grocer/notification_reader.rb
@@ -143,6 +144,7 @@ files:
143
144
  - spec/grocer/failed_delivery_attempt_spec.rb
144
145
  - spec/grocer/feedback_connection_spec.rb
145
146
  - spec/grocer/feedback_spec.rb
147
+ - spec/grocer/mobile_device_management_notification_spec.rb
146
148
  - spec/grocer/newsstand_notification_spec.rb
147
149
  - spec/grocer/notification_reader_spec.rb
148
150
  - spec/grocer/notification_spec.rb
@@ -155,6 +157,7 @@ files:
155
157
  - spec/grocer/ssl_server_spec.rb
156
158
  - spec/grocer_spec.rb
157
159
  - spec/spec_helper.rb
160
+ - spec/support/notification_helpers.rb
158
161
  homepage: https://github.com/grocer/grocer
159
162
  licenses:
160
163
  - MIT
@@ -170,7 +173,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
170
173
  version: '0'
171
174
  segments:
172
175
  - 0
173
- hash: 215139925189749573
176
+ hash: -4490716643818473019
174
177
  required_rubygems_version: !ruby/object:Gem::Requirement
175
178
  none: false
176
179
  requirements:
@@ -179,7 +182,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
179
182
  version: '0'
180
183
  segments:
181
184
  - 0
182
- hash: 215139925189749573
185
+ hash: -4490716643818473019
183
186
  requirements: []
184
187
  rubyforge_project:
185
188
  rubygems_version: 1.8.23
@@ -195,6 +198,7 @@ test_files:
195
198
  - spec/grocer/failed_delivery_attempt_spec.rb
196
199
  - spec/grocer/feedback_connection_spec.rb
197
200
  - spec/grocer/feedback_spec.rb
201
+ - spec/grocer/mobile_device_management_notification_spec.rb
198
202
  - spec/grocer/newsstand_notification_spec.rb
199
203
  - spec/grocer/notification_reader_spec.rb
200
204
  - spec/grocer/notification_spec.rb
@@ -207,3 +211,4 @@ test_files:
207
211
  - spec/grocer/ssl_server_spec.rb
208
212
  - spec/grocer_spec.rb
209
213
  - spec/spec_helper.rb
214
+ - spec/support/notification_helpers.rb