pntfr 0.5.3 → 0.6.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 693c8a96d8ba9566c1dcabf08581f5aa52297368
4
- data.tar.gz: 663dfc03af01428078af0881658a08ac89cdff24
3
+ metadata.gz: 1ea2c676227f8cb47624247e7b17c1b23ca4f807
4
+ data.tar.gz: b959760dd664b66b8e7fac4cc2047fd0d160964e
5
5
  SHA512:
6
- metadata.gz: ea273a1aab3b8dae07502577d848e112605be360c7f57c10054efbd61ad1685f2c17f801a9e23cd3e293262385e2c79f5f9acb54a23b24f42cd472afcbaa0d1e
7
- data.tar.gz: e1f4b171c3933cb6348f01566f923619786720c2ec74f7c9306ef9a43ec85f54ab6cac204c2b6b4c14a65721074ec2b076435683055e57c86231e673260f4a7a
6
+ metadata.gz: 8be443994f430f303904e47b2b10b537923470b59b1a0a4be8b9c877c7afa7646c8b9b5406397f9bacb1ecca94f95d680cb45348609c2ee9f248504982849dca
7
+ data.tar.gz: 4a0fbc47b6eed0cdb7c6f14092e2008da382a8301f65e757fed60a6ec80d3e5e59545adf5a88491a4ea2bf24e8a08d499ed3134e851b1a45c235356d1749596a
@@ -1,23 +1,23 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pntfr (0.2.0)
5
- apns (~> 1.0, >= 1.0.0)
4
+ pntfr (0.5.3)
5
+ apns2 (~> 0.0, >= 0.0.1)
6
6
  gcm (~> 0.0, >= 0.0.9)
7
7
  json (~> 1.8, >= 1.8.1)
8
8
 
9
9
  GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
- apns (1.0.0)
12
+ apns2 (0.0.1)
13
13
  gcm (0.1.0)
14
14
  httparty
15
15
  json
16
- httparty (0.13.4)
16
+ httparty (0.13.7)
17
17
  json (~> 1.8)
18
18
  multi_xml (>= 0.5.2)
19
- json (1.8.2)
20
- minitest (5.7.0)
19
+ json (1.8.3)
20
+ minitest (5.8.3)
21
21
  multi_xml (0.5.5)
22
22
  rake (10.4.2)
23
23
 
@@ -26,6 +26,6 @@ PLATFORMS
26
26
 
27
27
  DEPENDENCIES
28
28
  bundler (~> 1.6)
29
- minitest (~> 5.7.0)
29
+ minitest (~> 5.8, >= 5.8.3)
30
30
  pntfr!
31
31
  rake
data/README.md CHANGED
@@ -116,7 +116,7 @@ msg[:custom]= {
116
116
  :'last-extra' => {lastkey: 'last value'}
117
117
  }
118
118
 
119
- # SETTING ANPS AND GCN CREDENTIALS ON EACH NOTIFICATION
119
+ # SETTING ANPS AND GCM CREDENTIALS ON EACH NOTIFICATION
120
120
  # using different configuration on each call
121
121
  credentials= {
122
122
  # for ios you select what you override, in this case host and port will be
@@ -132,6 +132,30 @@ notifier= Pntfr::Notifier.new( credentials )
132
132
  notifier.update_devices(device).msg({:title => 'Title', :description => 'Description'}).notify
133
133
  # of course the device's push_id and credentials should belong to the same application.
134
134
  ```
135
+ ## Apns Feedback
136
+ This is specific of the Apple Push Notification Service.
137
+ To clean the database from bad devices that will slow down batch notification sendings,
138
+ one must check which devices caused error on the past and remove them from the database.
139
+
140
+ The process is easy, simply ask the Apns service for the list of bad devices,
141
+ and then do the cleaning.
142
+
143
+ ```ruby
144
+ feedback= Pntfr::Feedback.new
145
+ bad_devices= feedback.bad_devices
146
+
147
+ # do the cleaning of your database, for example
148
+ bad_devices.each do |bad_device|
149
+ d= Device.find_by_platform_and_push_id(Pntfr::Platforms.IOS, bad_device.push_id)
150
+ d.destroy
151
+ end
152
+ ```
153
+
154
+ +bad_devices+ is an Array of Pntfr::BadDevice objects with the two attributes returned
155
+ by the apns feedback service: timestamp and push_id.
156
+
157
+ It is recommended to do a feedback cleaning once a day.
158
+
135
159
  # Testing
136
160
  For testing, one can check the messages sent to each device the same way
137
161
  that Rails ActiveMailer works: messages are stacked into `Pntfr.deliveries[push_id]`,
@@ -141,7 +165,6 @@ notifications are not sent, only stored in the stack.
141
165
 
142
166
  # Further development (roadmap)
143
167
  - Update cannonical push id when required for gcm.
144
- - Retrieve feedback on sent messages for apns.
145
168
 
146
169
  # Resources
147
170
  - Depends on APNS gem: https://rubygems.org/gems/apns
@@ -1,6 +1,7 @@
1
1
  require 'pntfr/version'
2
2
  require 'pntfr/platforms'
3
3
  require 'pntfr/notifier'
4
+ require 'pntfr/feedback'
4
5
 
5
6
  module Pntfr
6
7
  def self.test_env?
@@ -0,0 +1,15 @@
1
+ module Pntfr
2
+ module ApnsConfigurator
3
+ def configure_apns config_override
4
+ config= Pntfr.config.apns
5
+ unless config_override.nil?
6
+ config= config.clone.merge(config_override)
7
+ end
8
+ APNS.host = config[:host]
9
+ APNS.pem = config[:pem]
10
+ APNS.port = config[:port]
11
+ APNS.pass = config[:pass]
12
+ @apns= APNS
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,28 @@
1
+ module Pntfr
2
+ class BaseService
3
+ def initialize credentials
4
+ validate_credentials(credentials)
5
+ @credentials= credentials || {}
6
+ end
7
+
8
+ #--------------------------------------------
9
+ private
10
+ #--------------------------------------------
11
+ def andr_session
12
+ @andr_session||= Pntfr::Session::Android.new(@credentials[:andr])
13
+ end
14
+ def ios_session
15
+ @ios_session||= Pntfr::Session::Ios.new(@credentials[:ios])
16
+ end
17
+ def validate_credentials(credentials)
18
+ return if credentials.nil?
19
+ if !credentials.is_a?(Hash)
20
+ raise ArgumentError.new('Credentials should be a Hash with either :andr or :ios keys!')
21
+ end
22
+ if !(credentials.has_key?(:andr) or credentials.has_key?(:ios))
23
+ raise ArgumentError.new('Either :andr or :ios service credentials should have been provided!')
24
+ end
25
+ end
26
+
27
+ end
28
+ end
@@ -0,0 +1,32 @@
1
+ require File.dirname(__FILE__) + '/base_service'
2
+ require 'apns'
3
+ require 'pntfr/apns_configurator'
4
+
5
+ module Pntfr
6
+ class Feedback < BaseService
7
+ include Pntfr::ApnsConfigurator
8
+
9
+ def initialize credentials=nil
10
+ super
11
+ configure_apns(credentials[:ios])
12
+ end
13
+
14
+ def bad_devices
15
+ feedback= ::APNS.feedback
16
+ feedback.collect do |rs|
17
+ bd= BadDevice.new(rs.last)
18
+ bd.timestamp= rs.first
19
+ bd
20
+ end
21
+ end
22
+
23
+ end
24
+
25
+ class BadDevice
26
+ attr_accessor :timestamp
27
+ attr_accessor :push_id
28
+ def initialize(push_id)
29
+ @push_id= push_id
30
+ end
31
+ end
32
+ end
@@ -1,9 +1,10 @@
1
+ require File.dirname(__FILE__) + '/base_service'
1
2
  require File.dirname(__FILE__) + '/session/base'
2
3
  require File.dirname(__FILE__) + '/notification'
3
4
 
4
5
  module Pntfr
5
6
 
6
- class Notifier
7
+ class Notifier < BaseService
7
8
  def self.to devices, credentials=nil
8
9
  notif= Notifier.new(credentials)
9
10
  notif.update_devices(devices)
@@ -25,8 +26,7 @@ module Pntfr
25
26
  # }
26
27
  #
27
28
  def initialize credentials=nil
28
- validate_credentials(credentials)
29
- @credentials= credentials || {}
29
+ super
30
30
 
31
31
  @andr_responses=[]
32
32
  @ios_responses= []
@@ -79,15 +79,6 @@ module Pntfr
79
79
  def ios_session
80
80
  @ios_session||= Pntfr::Session::Ios.new(@credentials[:ios])
81
81
  end
82
- def validate_credentials(credentials)
83
- return if credentials.nil?
84
- if !credentials.is_a?(Hash)
85
- raise ArgumentError.new('Credentials should be a Hash with either :andr or :ios keys!')
86
- end
87
- if !(credentials.has_key?(:andr) or credentials.has_key?(:ios))
88
- raise ArgumentError.new('Either :andr or :ios service credentials should have been provided!')
89
- end
90
- end
91
82
 
92
83
  end
93
84
 
@@ -2,9 +2,12 @@
2
2
  # Session implementation for iOS
3
3
  #
4
4
  require 'apns'
5
+ require 'pntfr/apns_configurator'
6
+
5
7
  module Pntfr
6
8
  module Session
7
9
  class Ios < Pntfr::Session::Base
10
+ include Pntfr::ApnsConfigurator
8
11
 
9
12
  attr_reader :apns
10
13
 
@@ -47,17 +50,6 @@ module Pntfr
47
50
  device.methods.include?(:num_notifs)
48
51
  end
49
52
 
50
- def configure_apns config_override
51
- config= Pntfr.config.apns
52
- unless config_override.nil?
53
- config= config.clone.merge(config_override)
54
- end
55
- APNS.host = config[:host]
56
- APNS.pem = config[:pem]
57
- APNS.port = config[:port]
58
- APNS.pass = config[:pass]
59
- @apns= APNS
60
- end
61
53
  end
62
54
  end
63
55
  end
@@ -2,6 +2,10 @@
2
2
  # Let's follow Semantic Versioning: http://semver.org/
3
3
  #
4
4
  module Pntfr
5
+ #
6
+ # PATCH v0.6.0
7
+ # - [FEATURE] Retrieve feedback on bad devices for apns.
8
+ # - Depend on minitest for development.
5
9
  #
6
10
  # PATCH v0.5.3
7
11
  # - [FIX] Depend on apns2 gem to be connection failure tolerant during big batches.
@@ -28,5 +32,5 @@ module Pntfr
28
32
  # - Allow overriding general configuration credentials when instantiating each
29
33
  # Notifier (on both platforms).
30
34
  # - Internal refactoring.
31
- VERSION = '0.5.3'
35
+ VERSION = '0.6.0'
32
36
  end
@@ -23,4 +23,5 @@ Gem::Specification.new do |spec|
23
23
  spec.add_runtime_dependency 'json', '~> 1.8', '>= 1.8.1'
24
24
  spec.add_development_dependency 'bundler', '~> 1.6'
25
25
  spec.add_development_dependency 'rake'
26
+ spec.add_development_dependency 'minitest', '~> 5.8', '>= 5.8.3'
26
27
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pntfr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.3
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - oliver
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-06 00:00:00.000000000 Z
11
+ date: 2015-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: apns2
@@ -98,6 +98,26 @@ dependencies:
98
98
  - - ">="
99
99
  - !ruby/object:Gem::Version
100
100
  version: '0'
101
+ - !ruby/object:Gem::Dependency
102
+ name: minitest
103
+ requirement: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - "~>"
106
+ - !ruby/object:Gem::Version
107
+ version: '5.8'
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: 5.8.3
111
+ type: :development
112
+ prerelease: false
113
+ version_requirements: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '5.8'
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: 5.8.3
101
121
  description: One single API to send push notifications to Android and iOS devices.
102
122
  email:
103
123
  - oliver.hv@coditramuntana.com
@@ -113,6 +133,9 @@ files:
113
133
  - README.md
114
134
  - Rakefile
115
135
  - lib/pntfr.rb
136
+ - lib/pntfr/apns_configurator.rb
137
+ - lib/pntfr/base_service.rb
138
+ - lib/pntfr/feedback.rb
116
139
  - lib/pntfr/notification.rb
117
140
  - lib/pntfr/notifier.rb
118
141
  - lib/pntfr/platforms.rb