notifiable-mpns-nverinaud 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/notifiable/mpns/nverinaud/single_notifier.rb +8 -6
- data/lib/notifiable/mpns/nverinaud/version.rb +1 -1
- data/notifiable-mpns-nverinaud.gemspec +1 -1
- data/spec/single_notifier_spec.rb +27 -28
- data/spec/support/db/migrate/20131228225138_create_notifiable_apps.rb +10 -0
- data/spec/support/db/migrate/20131228225139_create_notifiable_device_tokens.rb +7 -1
- data/spec/support/db/migrate/20131228225140_create_notifiable_notifications.rb +15 -4
- data/spec/support/db/migrate/20131229104039_create_notifiable_statuses.rb +12 -0
- metadata +8 -6
- data/spec/support/db/migrate/20131229104039_create_notifiable_notification_statuses.rb +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3042ffd28bb2e60ba04659b082b4b9c433f1eb96
|
4
|
+
data.tar.gz: 3d258a3aebf8eb5ca2841eec6936896b1e210bb1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1433aa2100ef9d100a982302ce90af1661e3de3332e28d499748a8a85becfab4f112a5f550397a8dae8f3c8a2937579859c855a36837fbcbf0aab93c531c871b
|
7
|
+
data.tar.gz: 520f95e5e3aeafaa251cb9e0631cf6df1dc46336285fac5948e97f0d451e34ab5af021b366b7082c0cd829b38a31ba9bdec7acbf6fbc9996f7c5d21b5389d862
|
@@ -7,24 +7,26 @@ module Notifiable
|
|
7
7
|
class SingleNotifier < Notifiable::NotifierBase
|
8
8
|
|
9
9
|
protected
|
10
|
-
def enqueue(
|
10
|
+
def enqueue(device_token)
|
11
11
|
|
12
|
-
data = {title:
|
12
|
+
data = {title: notification.title, content: notification.message, params: notification.send_params}
|
13
13
|
|
14
|
-
response = MicrosoftPushNotificationService.send_notification
|
14
|
+
response = MicrosoftPushNotificationService.send_notification(device_token.token, :toast, data)
|
15
15
|
response_code = response.code.to_i
|
16
16
|
|
17
|
+
status_code = 0
|
17
18
|
case response_code
|
18
19
|
when 200
|
19
20
|
when 404
|
20
21
|
Rails.logger.info "De-registering device token: #{device_token.id}"
|
21
22
|
device_token.update_attribute('is_valid', false)
|
23
|
+
status_code = 1
|
22
24
|
else
|
23
|
-
Rails.logger.error "Error sending notification: #{response.code}"
|
25
|
+
Rails.logger.error "Error sending notification: #{response.code}"
|
26
|
+
status_code = 2
|
24
27
|
end
|
25
28
|
|
26
|
-
processed(
|
27
|
-
|
29
|
+
processed(device_token, status_code)
|
28
30
|
end
|
29
31
|
end
|
30
32
|
end
|
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.add_dependency "notifiable-rails", ">=0.
|
21
|
+
spec.add_dependency "notifiable-rails", ">=0.17.0"
|
22
22
|
spec.add_dependency "ruby-mpns", "~> 1.2.1"
|
23
23
|
|
24
24
|
spec.add_development_dependency "bundler", "~> 1.3"
|
@@ -2,65 +2,64 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Notifiable::Mpns::Nverinaud::SingleNotifier do
|
4
4
|
|
5
|
-
let(:
|
6
|
-
let(:
|
7
|
-
let(:
|
5
|
+
let(:a) { Notifiable::App.create }
|
6
|
+
let(:n1) { Notifiable::Notification.create(:title => "Test title", :app => a) }
|
7
|
+
let(:n1_with_message) { Notifiable::Notification.create(:message => "Test message", :app => a) }
|
8
|
+
let(:n1_with_params) { Notifiable::Notification.create(:message => "Test message", :app => a, :params => {:flag => true}) }
|
9
|
+
let(:d) { Notifiable::DeviceToken.create(:token => "http://db3.notify.live.net/throttledthirdparty/01.00/123456789123456798", :provider => :mpns, :app => a) }
|
8
10
|
|
9
11
|
it "sends a notification with a title" do
|
10
|
-
n = Notifiable::Notification.create(title: "A title")
|
11
|
-
|
12
12
|
stub_request(:post, d.token)
|
13
13
|
|
14
|
-
|
15
|
-
|
14
|
+
n1.batch do |n|
|
15
|
+
n.add_device_token(d)
|
16
|
+
end
|
16
17
|
|
17
18
|
Notifiable::NotificationStatus.count.should == 1
|
18
|
-
Notifiable::NotificationStatus.first.status.should ==
|
19
|
+
Notifiable::NotificationStatus.first.status.should == 0
|
19
20
|
|
20
21
|
a_request(:post, d.token)
|
21
|
-
.with(:body => "<?xml version=\"1.0\" encoding=\"UTF-8\"?><wp:Notification xmlns:wp=\"WPNotification\"><wp:Toast><wp:Text1>
|
22
|
+
.with(:body => "<?xml version=\"1.0\" encoding=\"UTF-8\"?><wp:Notification xmlns:wp=\"WPNotification\"><wp:Toast><wp:Text1>Test title</wp:Text1><wp:Text2></wp:Text2><wp:Param>?notification_id=#{n1.id}</wp:Param></wp:Toast></wp:Notification>")
|
22
23
|
.should have_been_made.once
|
23
24
|
end
|
24
25
|
|
25
|
-
it "sends a single mpns notification with
|
26
|
-
n = Notifiable::Notification.create(message: "A message")
|
26
|
+
it "sends a single mpns notification with a message" do
|
27
27
|
stub_request(:post, d.token)
|
28
28
|
|
29
|
-
|
30
|
-
|
29
|
+
n1_with_message.batch do |n|
|
30
|
+
n.add_device_token(d)
|
31
|
+
end
|
31
32
|
|
32
33
|
Notifiable::NotificationStatus.count.should == 1
|
33
|
-
Notifiable::NotificationStatus.first.status.should ==
|
34
|
+
Notifiable::NotificationStatus.first.status.should == 0
|
34
35
|
|
35
36
|
a_request(:post, d.token)
|
36
|
-
.with(:body => "<?xml version=\"1.0\" encoding=\"UTF-8\"?><wp:Notification xmlns:wp=\"WPNotification\"><wp:Toast><wp:Text1></wp:Text1><wp:Text2>
|
37
|
+
.with(:body => "<?xml version=\"1.0\" encoding=\"UTF-8\"?><wp:Notification xmlns:wp=\"WPNotification\"><wp:Toast><wp:Text1></wp:Text1><wp:Text2>Test message</wp:Text2><wp:Param>?notification_id=#{n1_with_message.id}</wp:Param></wp:Toast></wp:Notification>")
|
37
38
|
.should have_been_made.once
|
38
39
|
end
|
39
40
|
|
40
|
-
it "sends custom attributes" do
|
41
|
-
n = Notifiable::Notification.create(:params => {:an_object_id => 123456})
|
42
|
-
|
41
|
+
it "sends custom attributes" do
|
43
42
|
stub_request(:post, d.token)
|
44
43
|
|
45
|
-
|
46
|
-
|
44
|
+
n1_with_params.batch do |n|
|
45
|
+
n.add_device_token(d)
|
46
|
+
end
|
47
47
|
|
48
48
|
Notifiable::NotificationStatus.count.should == 1
|
49
49
|
a_request(:post, d.token)
|
50
|
-
.with(:body => "<?xml version=\"1.0\" encoding=\"UTF-8\"?><wp:Notification xmlns:wp=\"WPNotification\"><wp:Toast><wp:Text1></wp:Text1><wp:Text2
|
50
|
+
.with(:body => "<?xml version=\"1.0\" encoding=\"UTF-8\"?><wp:Notification xmlns:wp=\"WPNotification\"><wp:Toast><wp:Text1></wp:Text1><wp:Text2>Test message</wp:Text2><wp:Param>?flag=true&notification_id=#{n1_with_params.id}</wp:Param></wp:Toast></wp:Notification>")
|
51
51
|
.should have_been_made.once
|
52
52
|
end
|
53
53
|
|
54
|
-
it "de-registers a device on receiving a 404 status from MPNS" do
|
55
|
-
n = Notifiable::Notification.create(:message => "A message")
|
56
|
-
|
54
|
+
it "de-registers a device on receiving a 404 status from MPNS" do
|
57
55
|
stub_request(:post, d.token).to_return(:status => 404)
|
58
|
-
|
59
|
-
|
60
|
-
|
56
|
+
|
57
|
+
n1.batch do |n|
|
58
|
+
n.add_device_token(d)
|
59
|
+
end
|
61
60
|
|
62
61
|
Notifiable::NotificationStatus.count.should == 1
|
63
|
-
Notifiable::NotificationStatus.first.status.should ==
|
62
|
+
Notifiable::NotificationStatus.first.status.should == 1
|
64
63
|
Notifiable::DeviceToken.first.is_valid.should == false
|
65
64
|
end
|
66
65
|
|
@@ -3,12 +3,18 @@ class CreateNotifiableDeviceTokens < ActiveRecord::Migration
|
|
3
3
|
def change
|
4
4
|
create_table :notifiable_device_tokens do |t|
|
5
5
|
t.string :token
|
6
|
-
t.string :user_id
|
7
6
|
t.string :provider
|
7
|
+
t.string :device_id
|
8
8
|
t.boolean :is_valid, :default => true
|
9
|
+
t.integer :user_id
|
10
|
+
t.references :app
|
9
11
|
|
10
12
|
t.timestamps
|
11
13
|
end
|
14
|
+
|
15
|
+
add_index :notifiable_device_tokens, :device_id, :unique => true
|
16
|
+
add_index :notifiable_device_tokens, :token, :unique => true
|
17
|
+
add_index :notifiable_device_tokens, :user_id
|
12
18
|
end
|
13
19
|
|
14
20
|
end
|
@@ -2,12 +2,23 @@ class CreateNotifiableNotifications < ActiveRecord::Migration
|
|
2
2
|
|
3
3
|
def change
|
4
4
|
create_table :notifiable_notifications do |t|
|
5
|
-
t.text :title
|
6
5
|
t.text :message
|
7
6
|
t.text :params
|
8
|
-
t.
|
9
|
-
|
10
|
-
|
7
|
+
t.references :app
|
8
|
+
|
9
|
+
#stats
|
10
|
+
t.integer :sent_count, :default => 0
|
11
|
+
t.integer :gateway_accepted_count, :default => 0
|
12
|
+
t.integer :opened_count, :default => 0
|
13
|
+
|
14
|
+
# APNS - Optional
|
15
|
+
#t.integer :badge
|
16
|
+
#t.text :sound
|
17
|
+
#t.datetime :expiry
|
18
|
+
|
19
|
+
# MPNS - Optional
|
20
|
+
t.text :title
|
21
|
+
|
11
22
|
t.timestamps
|
12
23
|
end
|
13
24
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: notifiable-mpns-nverinaud
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Brooke-Smith
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-05-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: notifiable-rails
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '>='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.
|
19
|
+
version: 0.17.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.
|
26
|
+
version: 0.17.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: ruby-mpns
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -170,9 +170,10 @@ files:
|
|
170
170
|
- notifiable-mpns-nverinaud.gemspec
|
171
171
|
- spec/single_notifier_spec.rb
|
172
172
|
- spec/spec_helper.rb
|
173
|
+
- spec/support/db/migrate/20131228225138_create_notifiable_apps.rb
|
173
174
|
- spec/support/db/migrate/20131228225139_create_notifiable_device_tokens.rb
|
174
175
|
- spec/support/db/migrate/20131228225140_create_notifiable_notifications.rb
|
175
|
-
- spec/support/db/migrate/
|
176
|
+
- spec/support/db/migrate/20131229104039_create_notifiable_statuses.rb
|
176
177
|
homepage: http://www.futureworkshops.com
|
177
178
|
licenses:
|
178
179
|
- Apache 2.0
|
@@ -200,6 +201,7 @@ summary: Plugin to use MPNS with Notifiable-Rails
|
|
200
201
|
test_files:
|
201
202
|
- spec/single_notifier_spec.rb
|
202
203
|
- spec/spec_helper.rb
|
204
|
+
- spec/support/db/migrate/20131228225138_create_notifiable_apps.rb
|
203
205
|
- spec/support/db/migrate/20131228225139_create_notifiable_device_tokens.rb
|
204
206
|
- spec/support/db/migrate/20131228225140_create_notifiable_notifications.rb
|
205
|
-
- spec/support/db/migrate/
|
207
|
+
- spec/support/db/migrate/20131229104039_create_notifiable_statuses.rb
|