apnotic 1.3.1 → 1.6.1

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
- SHA1:
3
- metadata.gz: c18668add69f52308e07541356eddc8d80d5993a
4
- data.tar.gz: e8eac41fd48b7eb3a30d59d8fdabe35926c8b5d9
2
+ SHA256:
3
+ metadata.gz: fabb07ff303f54456a91694d9025ee9a6416012c99459316e973a61d9d4e23de
4
+ data.tar.gz: 50fb64db3f3dd88c6e4f32081745c47b41b01fbb89e10a62c3cfb57db6cb7c63
5
5
  SHA512:
6
- metadata.gz: 7b9af64072437d4f35922b8ebdce9dd9dd21ba1f72f1e4f74dc5cb5674f0ec9fb63acc7c84f59f59a0845470465dcc8de92bd01357af3c79b00099aa1c6ea29e
7
- data.tar.gz: 9803cafad31803a8983d6a88875c4d452d3cb8cb97345fb8ee5afd912b217cb203062db9d8f79ec3375452f10122c86572f98d4975c0f5518e015f6fab2e2943
6
+ metadata.gz: ecf745aea19457f69c661c44dcee4655693d9195db5eeeab36a6050781f6be6e2e04f24ccdd8c3233038dffc0e674ef9558a27e93c430c33d4076ef7e254ea96
7
+ data.tar.gz: eeb22010a7c06e12ba72239dff31fbedc353485b9b8380aadf6c654136a22b7fc09f5db0f0147915e7f2914e08a8178937937cc61ed2c022bd5ff476c1487c9b
@@ -0,0 +1 @@
1
+ ruby 2.7.1
@@ -1,11 +1,14 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.1
4
- - 2.2
5
3
  - 2.3
6
4
  - 2.4
7
5
  - 2.5
6
+ - 2.6
7
+ - 2.7
8
8
 
9
9
  branches:
10
10
  only:
11
11
  - master
12
+
13
+ before_install:
14
+ - gem install bundler
data/README.md CHANGED
@@ -86,7 +86,7 @@ end
86
86
  connection.push_async(push)
87
87
 
88
88
  # wait for all requests to be completed
89
- connection.join
89
+ connection.join(timeout: 5)
90
90
 
91
91
  # close the connection
92
92
  connection.close
@@ -166,7 +166,9 @@ class MyWorker
166
166
  APNOTIC_POOL = Apnotic::ConnectionPool.new({
167
167
  cert_path: Rails.root.join("config", "certs", "apns_certificate.pem"),
168
168
  cert_pass: "mypass"
169
- }, size: 5)
169
+ }, size: 5) do |connection|
170
+ connection.on(:error) { |exception| puts "Exception has been raised: #{exception}" }
171
+ end
170
172
 
171
173
  def perform(token)
172
174
  APNOTIC_POOL.with do |connection|
@@ -205,6 +207,10 @@ Apnotic::Connection.new(options)
205
207
  | :cert_pass | Optional. The certificate's password.
206
208
  | :url | Optional. Defaults to https://api.push.apple.com:443.
207
209
  | :connect_timeout | Optional. Expressed in seconds, defaults to 30.
210
+ | :proxy_addr | Optional. Proxy server. e.g. http://proxy.example.com
211
+ | :proxy_port | Optional. Proxy port. e.g. 8080
212
+ | :proxy_user | Optional. User name for proxy authentication. e.g. user_name
213
+ | :proxy_pass | Optional. Password for proxy authentication. e.g. pass_word
208
214
 
209
215
  Note that since `:cert_path` can be any object that responds to `:read`, it is possible to pass in a certificate string directly by wrapping it up in a `StringIO` object:
210
216
 
@@ -265,7 +271,9 @@ connection.on(:error) { |exception| puts "Exception has been raised: #{exception
265
271
  For your convenience, a wrapper around the [Connection Pool](https://github.com/mperham/connection_pool) gem is here for you. To create a new connection pool:
266
272
 
267
273
  ```ruby
268
- Apnotic::ConnectionPool.new(connection_options, connection_pool_options)
274
+ Apnotic::ConnectionPool.new(connection_options, connection_pool_options) do |connection|
275
+ connection.on(:error) { |exception| puts "Exception has been raised: #{exception}" }
276
+ end
269
277
  ```
270
278
 
271
279
  For example:
@@ -273,15 +281,20 @@ For example:
273
281
  ```ruby
274
282
  APNOTIC_POOL = Apnotic::ConnectionPool.new({
275
283
  cert_path: "apns_certificate.pem"
276
- }, size: 5)
284
+ }, size: 5) do |connection|
285
+ connection.on(:error) { |exception| puts "Exception has been raised: #{exception}" }
286
+ end
277
287
  ```
278
288
 
279
289
  It is also possible to create a connection pool that points to the Apple Development servers by calling instead:
280
290
 
281
291
  ```ruby
282
- Apnotic::ConnectionPool.development(connection_options, connection_pool_options)
292
+ Apnotic::ConnectionPool.development(connection_options, connection_pool_options) do |connection|
293
+ connection.on(:error) { |exception| puts "Exception has been raised: #{exception}" }
294
+ end
283
295
  ```
284
296
 
297
+ > Since `1.4.0.` you are required to pass in a block when defining an `Apnotic::ConnectionPool`. This is to enforce a proper implementation of the library. You can read more [here](https://github.com/ostinelli/apnotic/issues/69).
285
298
 
286
299
  ### `Apnotic::Notification`
287
300
  To create a notification for a specific device token:
@@ -18,10 +18,10 @@ Gem::Specification.new do |spec|
18
18
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_dependency "net-http2", ">= 0.17", "< 2"
22
- spec.add_dependency "connection_pool", "~> 2.0"
21
+ spec.add_dependency "net-http2", ">= 0.18.3", "< 2"
22
+ spec.add_dependency "connection_pool", "~> 2"
23
23
 
24
- spec.add_development_dependency "bundler", "~> 1.3"
25
- spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "bundler"
25
+ spec.add_development_dependency "rake", ">= 12.3.3"
26
26
  spec.add_development_dependency "rspec", "~> 3.0"
27
27
  end
@@ -26,6 +26,10 @@ module Apnotic
26
26
  authorization ? "bearer #{authorization}" : nil
27
27
  end
28
28
 
29
+ def background_notification?
30
+ false
31
+ end
32
+
29
33
  private
30
34
 
31
35
  def to_hash
@@ -3,8 +3,9 @@ require 'openssl'
3
3
 
4
4
  module Apnotic
5
5
 
6
- APPLE_DEVELOPMENT_SERVER_URL = "https://api.development.push.apple.com:443"
6
+ APPLE_DEVELOPMENT_SERVER_URL = "https://api.sandbox.push.apple.com:443"
7
7
  APPLE_PRODUCTION_SERVER_URL = "https://api.push.apple.com:443"
8
+ PROXY_SETTINGS_KEYS = [:proxy_addr, :proxy_port, :proxy_user, :proxy_pass]
8
9
 
9
10
  class Connection
10
11
  attr_reader :url, :cert_path
@@ -28,7 +29,15 @@ module Apnotic
28
29
 
29
30
  raise "Cert file not found: #{@cert_path}" unless @cert_path && (@cert_path.respond_to?(:read) || File.exist?(@cert_path))
30
31
 
31
- @client = NetHttp2::Client.new(@url, ssl_context: ssl_context, connect_timeout: @connect_timeout)
32
+ http2_options = {
33
+ ssl_context: ssl_context,
34
+ connect_timeout: @connect_timeout
35
+ }
36
+ PROXY_SETTINGS_KEYS.each do |key|
37
+ http2_options[key] = options[key] if options[key]
38
+ end
39
+
40
+ @client = NetHttp2::Client.new(@url, http2_options)
32
41
  end
33
42
 
34
43
  def push(notification, options={})
@@ -63,8 +72,8 @@ module Apnotic
63
72
  @client.close
64
73
  end
65
74
 
66
- def join
67
- @client.join
75
+ def join(timeout: nil)
76
+ @client.join(timeout: timeout)
68
77
  end
69
78
 
70
79
  def on(event, &block)
@@ -92,7 +101,7 @@ module Apnotic
92
101
  def remote_max_concurrent_streams
93
102
  # 0x7fffffff is the default value from http-2 gem (2^31)
94
103
  if @client.remote_settings[:settings_max_concurrent_streams] == 0x7fffffff
95
- 0
104
+ 1
96
105
  else
97
106
  @client.remote_settings[:settings_max_concurrent_streams]
98
107
  end
@@ -6,14 +6,22 @@ module Apnotic
6
6
 
7
7
  class << self
8
8
  def new(options={}, pool_options={})
9
+ raise(LocalJumpError, "a block is needed when initializing an Apnotic::ConnectionPool") unless block_given?
10
+
9
11
  ::ConnectionPool.new(pool_options) do
10
- Apnotic::Connection.new(options)
12
+ connection = Apnotic::Connection.new(options)
13
+ yield(connection)
14
+ connection
11
15
  end
12
16
  end
13
17
 
14
18
  def development(options={}, pool_options={})
19
+ raise(LocalJumpError, "a block is needed when initializing an Apnotic::ConnectionPool") unless block_given?
20
+
15
21
  ::ConnectionPool.new(pool_options) do
16
- Apnotic::Connection.development(options)
22
+ connection = Apnotic::Connection.development(options)
23
+ yield(connection)
24
+ connection
17
25
  end
18
26
  end
19
27
  end
@@ -5,6 +5,10 @@ module Apnotic
5
5
  class Notification < AbstractNotification
6
6
  attr_accessor :alert, :badge, :sound, :content_available, :category, :custom_payload, :url_args, :mutable_content, :thread_id
7
7
 
8
+ def background_notification?
9
+ aps.count == 1 && aps.key?('content-available') && aps['content-available'] == 1
10
+ end
11
+
8
12
  private
9
13
 
10
14
  def aps
@@ -16,6 +16,7 @@ module Apnotic
16
16
  h.merge!('apns-id' => notification.apns_id) if notification.apns_id
17
17
  h.merge!('apns-expiration' => notification.expiration) if notification.expiration
18
18
  h.merge!('apns-priority' => notification.priority) if notification.priority
19
+ h.merge!('apns-push-type' => notification.background_notification? ? 'background' : 'alert' )
19
20
  h.merge!('apns-topic' => notification.topic) if notification.topic
20
21
  h.merge!('apns-collapse-id' => notification.apns_collapse_id) if notification.apns_collapse_id
21
22
  h.merge!('authorization' => notification.authorization_header) if notification.authorization_header
@@ -1,3 +1,3 @@
1
1
  module Apnotic
2
- VERSION = '1.3.1'.freeze
2
+ VERSION = '1.6.1'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apnotic
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
4
+ version: 1.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roberto Ostinelli
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-04-10 00:00:00.000000000 Z
11
+ date: 2020-10-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: net-http2
@@ -16,7 +16,7 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '0.17'
19
+ version: 0.18.3
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
22
  version: '2'
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: '0.17'
29
+ version: 0.18.3
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
32
  version: '2'
@@ -36,42 +36,42 @@ dependencies:
36
36
  requirements:
37
37
  - - "~>"
38
38
  - !ruby/object:Gem::Version
39
- version: '2.0'
39
+ version: '2'
40
40
  type: :runtime
41
41
  prerelease: false
42
42
  version_requirements: !ruby/object:Gem::Requirement
43
43
  requirements:
44
44
  - - "~>"
45
45
  - !ruby/object:Gem::Version
46
- version: '2.0'
46
+ version: '2'
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: bundler
49
49
  requirement: !ruby/object:Gem::Requirement
50
50
  requirements:
51
- - - "~>"
51
+ - - ">="
52
52
  - !ruby/object:Gem::Version
53
- version: '1.3'
53
+ version: '0'
54
54
  type: :development
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  requirements:
58
- - - "~>"
58
+ - - ">="
59
59
  - !ruby/object:Gem::Version
60
- version: '1.3'
60
+ version: '0'
61
61
  - !ruby/object:Gem::Dependency
62
62
  name: rake
63
63
  requirement: !ruby/object:Gem::Requirement
64
64
  requirements:
65
- - - "~>"
65
+ - - ">="
66
66
  - !ruby/object:Gem::Version
67
- version: '10.0'
67
+ version: 12.3.3
68
68
  type: :development
69
69
  prerelease: false
70
70
  version_requirements: !ruby/object:Gem::Requirement
71
71
  requirements:
72
- - - "~>"
72
+ - - ">="
73
73
  - !ruby/object:Gem::Version
74
- version: '10.0'
74
+ version: 12.3.3
75
75
  - !ruby/object:Gem::Dependency
76
76
  name: rspec
77
77
  requirement: !ruby/object:Gem::Requirement
@@ -86,7 +86,7 @@ dependencies:
86
86
  - - "~>"
87
87
  - !ruby/object:Gem::Version
88
88
  version: '3.0'
89
- description:
89
+ description:
90
90
  email:
91
91
  - roberto@ostinelli.net
92
92
  executables: []
@@ -95,8 +95,7 @@ extra_rdoc_files: []
95
95
  files:
96
96
  - ".gitignore"
97
97
  - ".rspec"
98
- - ".ruby-gemset"
99
- - ".ruby-version"
98
+ - ".tool-versions"
100
99
  - ".travis.yml"
101
100
  - Gemfile
102
101
  - LICENSE.md
@@ -121,7 +120,7 @@ homepage: http://github.com/ostinelli/apnotic
121
120
  licenses:
122
121
  - MIT
123
122
  metadata: {}
124
- post_install_message:
123
+ post_install_message:
125
124
  rdoc_options: []
126
125
  require_paths:
127
126
  - lib
@@ -136,9 +135,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
136
135
  - !ruby/object:Gem::Version
137
136
  version: '0'
138
137
  requirements: []
139
- rubyforge_project:
140
- rubygems_version: 2.5.1
141
- signing_key:
138
+ rubygems_version: 3.1.2
139
+ signing_key:
142
140
  specification_version: 4
143
141
  summary: Apnotic is an Apple Push Notification gem able to provide instant feedback.
144
142
  test_files: []
@@ -1 +0,0 @@
1
- apnotic
@@ -1 +0,0 @@
1
- ruby-2.3.1