notifiable-apns-apnotic 0.2.3 → 0.3.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
  SHA256:
3
- metadata.gz: 30ee127117cadea3bf299a7172c9e919ce97fbc17141d689b36c3b9e974ba08e
4
- data.tar.gz: b3d161b342c17fb0a766ca265ebe746d69aa38ea881f0a144c138337ca1bd347
3
+ metadata.gz: e26c3a1d49df1de6ee0534598ff3344ed6596f2e85aa1b344df434bc92fe83d1
4
+ data.tar.gz: 4bc8a6378ea65ca13f095f07a769a48fae92f4ad75e8a696de5d95385271b8ca
5
5
  SHA512:
6
- metadata.gz: '0888843fb164aded146ab56ab1512014be3012f184d2f0117acf34e3186fe2bbed0cda64bad542ff3a2c100adc69e9b5fd0eb0f2ff18a031827a87e85c2ee5fc'
7
- data.tar.gz: 6efb82c65c040ca97d7f9f6e6ba705670123131a2ec5061bd30fd3000f4a7afde797faee7ee1f528798eae5bb6c211d64a8d8a56109ec66ff302ae51c1c05359
6
+ metadata.gz: bffcbbf3039e4cb2e1dc135d27faded97f7170a9d696c4f9dc393f22255142cd057e9ee4a6f9ac3e297df6800db15b1138ecb41b2a78e958f50bfa865d0b9180
7
+ data.tar.gz: 1f3a9867919bb88a975f30c1521832e4a7d390ef4a23295bf288223475de5d32f79532853dbda70f1889c33536aae5da23835e0673f0a3a4a1f2a3c6f9ce389c
data/Gemfile.lock CHANGED
@@ -1,8 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- notifiable-apns-apnotic (0.2.3)
4
+ notifiable-apns-apnotic (0.3.0)
5
5
  apnotic (~> 1.4.1)
6
+ grocer (~> 0.7.1)
6
7
  notifiable-core (>= 0.1.3)
7
8
 
8
9
  GEM
@@ -32,13 +33,14 @@ GEM
32
33
  diff-lcs (1.3)
33
34
  factory_bot (4.11.0)
34
35
  activesupport (>= 3.0.0)
36
+ grocer (0.7.1)
35
37
  http-2 (0.9.0)
36
38
  i18n (1.1.0)
37
39
  concurrent-ruby (~> 1.0)
38
40
  minitest (5.11.3)
39
41
  net-http2 (0.18.0)
40
42
  http-2 (= 0.9.0)
41
- notifiable-core (0.1.4)
43
+ notifiable-core (0.2.0)
42
44
  activerecord
43
45
  activerecord-import
44
46
  pg (1.1.0)
@@ -1,5 +1,6 @@
1
1
  require 'notifiable'
2
2
  require 'apnotic'
3
+ require 'grocer'
3
4
 
4
5
  module Notifiable
5
6
  module Apns
@@ -46,6 +47,11 @@ module Notifiable
46
47
  connection.join
47
48
  connection.close
48
49
  @connection = nil
50
+ process_feedback if feedback_app_ids.split(',').include?(notification.app.id.to_s)
51
+ end
52
+
53
+ def feedback_app_ids
54
+ ENV['APNS_APNOTIC_PROCESS_FEEDBACK_APP_IDS'] || ''
49
55
  end
50
56
 
51
57
  def connection
@@ -71,6 +77,35 @@ module Notifiable
71
77
 
72
78
  payload
73
79
  end
80
+
81
+ def grocer_feedback
82
+ @grocer_feedback ||= ::Grocer.feedback(feedback_config)
83
+ end
84
+
85
+ def feedback_host
86
+ self.sandbox? ? "feedback.sandbox.push.apple.com" : "feedback.push.apple.com"
87
+ end
88
+
89
+ def feedback_config
90
+ {
91
+ certificate: certificate,
92
+ passphrase: passphrase,
93
+ gateway: feedback_host,
94
+ port: 2196,
95
+ retries: 3
96
+ }
97
+ end
98
+
99
+ def process_feedback
100
+ grocer_feedback.each do |attempt|
101
+ token = attempt.device_token
102
+ device_token = DeviceToken.find_by_token(token)
103
+ if device_token
104
+ device_token.destroy if device_token.updated_at < attempt.timestamp
105
+ logger.info("Device #{token} removed at #{attempt.timestamp}")
106
+ end
107
+ end
108
+ end
74
109
  end
75
110
  end
76
111
  end
@@ -0,0 +1,15 @@
1
+ module Grocer
2
+ class SSLConnection
3
+ def connect
4
+ context = OpenSSL::SSL::SSLContext.new
5
+ context.key = OpenSSL::PKey::RSA.new(certificate, passphrase)
6
+ context.cert = OpenSSL::X509::Certificate.new(certificate)
7
+
8
+ @sock = TCPSocket.new(gateway, port)
9
+ @sock.setsockopt Socket::SOL_SOCKET, Socket::SO_KEEPALIVE, true
10
+ @ssl = OpenSSL::SSL::SSLSocket.new(@sock, context)
11
+ @ssl.sync = true
12
+ @ssl.connect
13
+ end
14
+ end
15
+ end
@@ -1,7 +1,7 @@
1
1
  module Notifiable
2
2
  module Apns
3
3
  module Apnotic
4
- VERSION = "0.2.3"
4
+ VERSION = "0.3.0"
5
5
  end
6
6
  end
7
7
  end
@@ -22,6 +22,7 @@ Gem::Specification.new do |spec|
22
22
 
23
23
  spec.add_dependency "notifiable-core", ">= 0.1.3"
24
24
  spec.add_dependency 'apnotic', '~> 1.4.1'
25
+ spec.add_dependency 'grocer', '~> 0.7.1'
25
26
 
26
27
  spec.add_development_dependency "bundler", "~> 1.16"
27
28
  spec.add_development_dependency "rake", "~> 10.0"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: notifiable-apns-apnotic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Brooke-Smith
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-08-28 00:00:00.000000000 Z
11
+ date: 2018-09-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: notifiable-core
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: 1.4.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: grocer
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.7.1
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.7.1
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: bundler
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -170,6 +184,7 @@ files:
170
184
  - db/development.sqlite3
171
185
  - lib/notifiable/apns/apnotic.rb
172
186
  - lib/notifiable/apns/apnotic/async.rb
187
+ - lib/notifiable/apns/apnotic/grocer_ssl_connection.rb
173
188
  - lib/notifiable/apns/apnotic/version.rb
174
189
  - notifiable-apns-apnotic.gemspec
175
190
  homepage: https://github.com/FutureWorkshops/notifiable-apns-apnotic