ruby-push-notifications 0.1.0 → 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.
@@ -0,0 +1,43 @@
1
+
2
+ module RubyPushNotifications
3
+ module MPNS
4
+ describe MPNSNotification do
5
+
6
+ let(:device_urls) { %w(a b c) }
7
+ let(:raw_notification) { build :mpns_notification }
8
+ let(:toast_data) { { title: 'Title', message: 'Hello MPNS World!', type: :toast } }
9
+ let(:toast_notification) { build :mpns_notification, device_urls: device_urls, data: toast_data }
10
+ let(:tile_data) { { count: 1, title: 'Hello MPNS World!', type: :tile } }
11
+ let(:tile_notification) { build :mpns_notification, device_urls: device_urls, data: tile_data }
12
+
13
+ it 'builds the right mpns raw xml' do
14
+ xml = '<?xml version="1.0" encoding="UTF-8"?>'
15
+ xml << '<root><value1>hello</value1></root>'
16
+ expect(raw_notification.as_mpns_xml).to eq xml
17
+ end
18
+
19
+ it 'builds the right mpns toast xml' do
20
+ xml = '<?xml version="1.0" encoding="UTF-8"?>'
21
+ xml << '<wp:Notification xmlns:wp="WPNotification"><wp:Toast>'
22
+ xml << '<wp:Text1>Title</wp:Text1>'
23
+ xml << '<wp:Text2>Hello MPNS World!</wp:Text2>'
24
+ xml << '</wp:Toast></wp:Notification>'
25
+ expect(toast_notification.as_mpns_xml).to eq xml
26
+ end
27
+
28
+ it 'builds the right mpns tile xml' do
29
+ xml = '<?xml version="1.0" encoding="UTF-8"?>'
30
+ xml << '<wp:Notification xmlns:wp="WPNotification"><wp:Tile>'
31
+ xml << '<wp:Count>1</wp:Count>'
32
+ xml << '<wp:Title>Hello MPNS World!</wp:Title>'
33
+ xml << '</wp:Tile></wp:Notification>'
34
+ expect(tile_notification.as_mpns_xml).to eq xml
35
+ end
36
+
37
+ it 'validates the mpns format'
38
+
39
+ it 'validates the data'
40
+
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,59 @@
1
+
2
+ module RubyPushNotifications
3
+ module MPNS
4
+ describe MPNSPusher do
5
+
6
+ let(:pusher) { MPNSPusher.new }
7
+
8
+ describe '#push' do
9
+
10
+ let(:device_urls) { [generate(:mpns_device_url)] }
11
+ let(:notif1) { build :mpns_notification, device_urls: ['http://s.notify.live.net/1'], data: { message: { value1: 'hello' } } }
12
+ let(:notif2) { build :mpns_notification, device_urls: ['http://s.notify.live.net/1'], data: { message: { value1: 'hello' } } }
13
+ let(:raw_notification) { build :mpns_notification }
14
+ let(:toast_data) { { title: 'Title', message: 'Hello MPNS World!', type: :toast } }
15
+ let(:toast_notification) { build :mpns_notification, device_urls: device_urls, data: toast_data }
16
+ let(:tile_data) { { count: 1, title: 'Hello MPNS World!', type: :tile } }
17
+ let(:tile_notification) { build :mpns_notification, device_urls: device_urls, data: tile_data }
18
+ let(:headers) {
19
+ {
20
+ 'x-notificationstatus' => 'Received',
21
+ 'x-deviceconnectionstatus' => 'Connected',
22
+ 'x-subscriptionstatus' => 'Active'
23
+ }
24
+ }
25
+ let(:response) { [ { device_url: 'http://s.notify.live.net/1', headers: headers, code: 200 } ]}
26
+
27
+ before do
28
+ stub_request(:post, %r{s.notify.live.net}).
29
+ to_return status: [200, 'OK'], headers: headers
30
+ end
31
+
32
+ it 'submits every notification' do
33
+ pusher.push [raw_notification, toast_notification, tile_notification]
34
+ expect(WebMock).
35
+ to have_requested(:post, raw_notification.device_urls[0]).
36
+ with(body: raw_notification.as_mpns_xml, headers: { 'Content-Type' => 'text/xml', 'X-NotificationClass' => '3'}).
37
+ once
38
+
39
+ expect(WebMock).
40
+ to have_requested(:post, toast_notification.device_urls[0]).
41
+ with(body: toast_notification.as_mpns_xml, headers: { 'Content-Type' => 'text/xml', 'X-NotificationClass' => '2', 'X-WindowsPhone-Target' => :toast}).
42
+ once
43
+
44
+ expect(WebMock).
45
+ to have_requested(:post, tile_notification.device_urls[0]).
46
+ with(body: tile_notification.as_mpns_xml, headers: { 'Content-Type' => 'text/xml', 'X-NotificationClass' => '1', 'X-WindowsPhone-Target' => 'token'}).
47
+ once
48
+ end
49
+
50
+ it 'sets results to notifications' do
51
+ expect do
52
+ pusher.push [notif1, notif2]
53
+ end.to change { [notif1, notif2].map &:results }.from([nil, nil]).to [MPNSResponse.new(response)]*2
54
+ end
55
+
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,64 @@
1
+
2
+ module RubyPushNotifications
3
+ module MPNS
4
+ describe MPNSResponse do
5
+
6
+ describe 'success' do
7
+
8
+ let(:successful_messages) { 2 }
9
+ let(:failed_messages) { 6 }
10
+ let(:headers) {
11
+ {
12
+ 'x-notificationstatus' => 'Received',
13
+ 'x-deviceconnectionstatus' => 'Connected',
14
+ 'x-subscriptionstatus' => 'Active'
15
+ }
16
+ }
17
+
18
+ let(:responses) {
19
+ [
20
+ { device_url: '1', headers: headers, code: 200 },
21
+ { device_url: '2', headers: headers, code: 200 },
22
+ { device_url: '3', code: 400 },
23
+ { device_url: '4', code: 401 },
24
+ { device_url: '5', headers: headers, code: 404 },
25
+ { device_url: '6', headers: headers, code: 406 },
26
+ { device_url: '7', headers: headers, code: 412 },
27
+ { device_url: '8', code: 503 }
28
+ ]
29
+ }
30
+
31
+ let(:response) { MPNSResponse.new responses }
32
+ let(:result) { MPNSResultOK.new '1', headers }
33
+
34
+ it 'parses the number of successfully processed notifications' do
35
+ expect(response.success).to eq successful_messages
36
+ end
37
+
38
+ it 'parses the number of failed messages' do
39
+ expect(response.failed).to eq failed_messages
40
+ end
41
+
42
+ it 'parses the results' do
43
+ expect(response.results).to eq [
44
+ MPNSResultOK.new('1', headers),
45
+ MPNSResultOK.new('2', headers),
46
+ MalformedMPNSResultError.new('3'),
47
+ MPNSAuthError.new('4'),
48
+ MPNSInvalidError.new('5', headers),
49
+ MPNSLimitError.new('6', headers),
50
+ MPNSPreConditionError.new('7', headers),
51
+ MPNSInternalError.new('8')
52
+ ]
53
+ end
54
+
55
+ it 'parses headers to result attributes' do
56
+ expect(result.notification_status).to eq 'Received'
57
+ expect(result.device_connection_status).to eq 'Connected'
58
+ expect(result.subscription_status).to eq 'Active'
59
+ end
60
+
61
+ end
62
+ end
63
+ end
64
+ end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-push-notifications
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carlos Alonso
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-30 00:00:00.000000000 Z
11
+ date: 2015-04-15 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: builder
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.2'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: bundler
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -88,7 +102,9 @@ extensions: []
88
102
  extra_rdoc_files: []
89
103
  files:
90
104
  - ".gitignore"
105
+ - ".hound.yml"
91
106
  - ".rspec"
107
+ - ".ruby-style.yml"
92
108
  - ".travis.yml"
93
109
  - Gemfile
94
110
  - Gemfile.lock
@@ -97,6 +113,7 @@ files:
97
113
  - Rakefile
98
114
  - examples/apns.rb
99
115
  - examples/gcm.rb
116
+ - examples/mpns.rb
100
117
  - lib/ruby-push-notifications.rb
101
118
  - lib/ruby-push-notifications/apns.rb
102
119
  - lib/ruby-push-notifications/apns/apns_connection.rb
@@ -109,6 +126,12 @@ files:
109
126
  - lib/ruby-push-notifications/gcm/gcm_pusher.rb
110
127
  - lib/ruby-push-notifications/gcm/gcm_response.rb
111
128
  - lib/ruby-push-notifications/gcm/gcm_result.rb
129
+ - lib/ruby-push-notifications/mpns.rb
130
+ - lib/ruby-push-notifications/mpns/mpns_connection.rb
131
+ - lib/ruby-push-notifications/mpns/mpns_notification.rb
132
+ - lib/ruby-push-notifications/mpns/mpns_pusher.rb
133
+ - lib/ruby-push-notifications/mpns/mpns_response.rb
134
+ - lib/ruby-push-notifications/mpns/mpns_result.rb
112
135
  - lib/ruby-push-notifications/version.rb
113
136
  - ruby-push-notifications.gemspec
114
137
  - spec/factories.rb
@@ -120,6 +143,10 @@ files:
120
143
  - spec/ruby-push-notifications/gcm/gcm_notification_spec.rb
121
144
  - spec/ruby-push-notifications/gcm/gcm_pusher_spec.rb
122
145
  - spec/ruby-push-notifications/gcm/gcm_response_spec.rb
146
+ - spec/ruby-push-notifications/mpns/mpns_connection_spec.rb
147
+ - spec/ruby-push-notifications/mpns/mpns_notification_spec.rb
148
+ - spec/ruby-push-notifications/mpns/mpns_pusher_spec.rb
149
+ - spec/ruby-push-notifications/mpns/mpns_response_spec.rb
123
150
  - spec/spec_helper.rb
124
151
  - spec/support/dummy.pem
125
152
  - spec/support/factory_girl.rb
@@ -157,6 +184,10 @@ test_files:
157
184
  - spec/ruby-push-notifications/gcm/gcm_notification_spec.rb
158
185
  - spec/ruby-push-notifications/gcm/gcm_pusher_spec.rb
159
186
  - spec/ruby-push-notifications/gcm/gcm_response_spec.rb
187
+ - spec/ruby-push-notifications/mpns/mpns_connection_spec.rb
188
+ - spec/ruby-push-notifications/mpns/mpns_notification_spec.rb
189
+ - spec/ruby-push-notifications/mpns/mpns_pusher_spec.rb
190
+ - spec/ruby-push-notifications/mpns/mpns_response_spec.rb
160
191
  - spec/spec_helper.rb
161
192
  - spec/support/dummy.pem
162
193
  - spec/support/factory_girl.rb