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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0603e386bffe7f2ec29874223e43307dc6f17380
4
- data.tar.gz: a00a3a89015b8ce06a2d2d5d9bf904455390c996
3
+ metadata.gz: 3042ffd28bb2e60ba04659b082b4b9c433f1eb96
4
+ data.tar.gz: 3d258a3aebf8eb5ca2841eec6936896b1e210bb1
5
5
  SHA512:
6
- metadata.gz: 5306484e69d8450bcbac18ad82afacb6174ed1277aa1db9b1eb93024681b139902ae0145991761650704cf6cb57e579e04f2336153179c8d19d2cbca1ee7d335
7
- data.tar.gz: 47860a6cf6381af0ffa069f9f46f25b15c9ee5c7bfe04c205cc21fd94bf02fe1e538484c77f0cf304206f0d98ceba943246a13d2ff7255691a68feaa0e77c565
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(n, device_token)
10
+ def enqueue(device_token)
11
11
 
12
- data = {title: n.title, content: n.message, params: n.params}
12
+ data = {title: notification.title, content: notification.message, params: notification.send_params}
13
13
 
14
- response = MicrosoftPushNotificationService.send_notification device_token.token, :toast, data
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(n, device_token, response_code)
27
-
29
+ processed(device_token, status_code)
28
30
  end
29
31
  end
30
32
  end
@@ -1,7 +1,7 @@
1
1
  module Notifiable
2
2
  module Mpns
3
3
  module Nverinaud
4
- VERSION = "0.4.0"
4
+ VERSION = "0.5.0"
5
5
  end
6
6
  end
7
7
  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.6.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(:m) { Notifiable::Mpns::Nverinaud::SingleNotifier.new }
6
- let(:d) { Notifiable::DeviceToken.create(:token => "http://db3.notify.live.net/throttledthirdparty/01.00/123456789123456798", :provider => :mpns) }
7
- let(:u) { User.new(d) }
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
- m.send_notification(n, d)
15
- m.close
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 == 200
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>A title</wp:Text1><wp:Text2></wp:Text2><wp:Param></wp:Param></wp:Toast></wp:Notification>")
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 content" do
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
- m.send_notification(n, d)
30
- m.close
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 == 200
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>A message</wp:Text2><wp:Param></wp:Param></wp:Toast></wp:Notification>")
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
- m.send_notification(n, d)
46
- m.close
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></wp:Text2><wp:Param>?an_object_id=123456</wp:Param></wp:Toast></wp:Notification>")
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&amp;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
- m.send_notification(n, d)
60
- m.close
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 == 404
62
+ Notifiable::NotificationStatus.first.status.should == 1
64
63
  Notifiable::DeviceToken.first.is_valid.should == false
65
64
  end
66
65
 
@@ -0,0 +1,10 @@
1
+ class CreateNotifiableApps < ActiveRecord::Migration
2
+ def change
3
+ create_table :notifiable_apps do |t|
4
+ t.string :name
5
+ t.text :configuration
6
+
7
+ t.timestamps
8
+ end
9
+ end
10
+ end
@@ -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.integer :badge
9
- t.text :sound
10
- t.datetime :expiry
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
@@ -0,0 +1,12 @@
1
+ class CreateNotifiableStatuses < ActiveRecord::Migration
2
+
3
+ def change
4
+ create_table :notifiable_statuses do |t|
5
+ t.references :notification
6
+ t.references :device_token
7
+ t.integer :status
8
+ t.datetime :created_at
9
+ end
10
+ end
11
+
12
+ 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.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-02-14 00:00:00.000000000 Z
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.6.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.6.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/20131229104039_create_notifiable_notification_statuses.rb
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/20131229104039_create_notifiable_notification_statuses.rb
207
+ - spec/support/db/migrate/20131229104039_create_notifiable_statuses.rb
@@ -1,11 +0,0 @@
1
- class CreateNotifiableNotificationStatuses < ActiveRecord::Migration
2
-
3
- def change
4
- create_table :notifiable_notification_statuses do |t|
5
- t.references :notification
6
- t.references :device_token
7
- t.integer :status
8
- end
9
- end
10
-
11
- end