apnotic 1.0.1 → 1.1.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: 82da596366fb53518eda9385937fcfb9e7fe476c
4
- data.tar.gz: fea67c61a31550b9dcac35b0ed4db95dc3352a3c
3
+ metadata.gz: 97653d26a662ae9a7faa8d9d4c2914de5f17b83e
4
+ data.tar.gz: a069da2ff88b6de95d2ad3f118a7eb4f22fb240b
5
5
  SHA512:
6
- metadata.gz: 7bf391d0311597c6c511fbac29c6918c83543edc977a6f05de8beac0e8633b3ae11ce7630c3859726dd0f8d677945a898119107564a41ba9967b22d5de1efa6a
7
- data.tar.gz: 6695fc6cebfc5608fc2c3def9eb7fa54f6ab1404af333b7e9647b0619dd41624c298417e0c039202b2d1c9b8cab26a82751957bad455f01f660f57058fceef68
6
+ metadata.gz: e86c4f893bcdee198dad0f6276d4f5d4c05b4999bf4ae5cdeccd91450f99bbecd05a9fd8a67abfa60e14f8c498bbfd9d14872b47a534c244809e7db8908275b4
7
+ data.tar.gz: 2e7820e5123299223fdf0e027c8a6bdb5500768d68a1a68afe59a3c88f5bc878c20a9fa8071e75fec6899b404e04cc7164fa4cd163b72de5011ded48fdb6a3c4
@@ -4,6 +4,8 @@ rvm:
4
4
  - 2.2
5
5
  - 2.3.0
6
6
  - 2.3.1
7
+ - 2.3.2
8
+ - 2.3.3
7
9
 
8
10
  branches:
9
11
  only:
data/README.md CHANGED
@@ -94,7 +94,7 @@ connection.close
94
94
 
95
95
 
96
96
  ### With Sidekiq / Rescue / ...
97
- > In case that errors are encountered, Apnotic will repair the underlying connection but will not retry the requests that have failed. For this reason, it is recommended to use a queue engine that will retry unsuccessful pushes.
97
+ > In case that errors are encountered, Apnotic will raise the error and repair the underlying connection, but it will not retry the requests that have failed. This is by design, so that the job manager (Sidekiq, Resque,...) can retry the job that failed. For this reason, it is recommended to use a queue engine that will retry unsuccessful pushes.
98
98
 
99
99
  A practical usage of a Sidekiq / Rescue worker probably has to:
100
100
 
@@ -151,11 +151,17 @@ Apnotic::Connection.new(options)
151
151
 
152
152
  | Option | Description
153
153
  |-----|-----
154
- | :cert_path | Required. The path to a valid APNS push certificate in .pem or .p12 format, or any object that responds to `:read`.
154
+ | :cert_path | Required. The path to a valid APNS push certificate in `.pem` or `.p12` format, or any object that responds to `:read`.
155
155
  | :cert_pass | Optional. The certificate's password.
156
156
  | :url | Optional. Defaults to https://api.push.apple.com:443.
157
157
  | :connect_timeout | Optional. Expressed in seconds, defaults to 30.
158
158
 
159
+ 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:
160
+
161
+ ```ruby
162
+ Apnotic::Connection.new(cert_path: StringIO.new("pem cert as string"))
163
+ ```
164
+
159
165
  It is also possible to create a connection that points to the Apple Development servers by calling instead:
160
166
 
161
167
  ```ruby
@@ -166,13 +172,23 @@ Apnotic::Connection.development(options)
166
172
 
167
173
  #### Methods
168
174
 
169
- * **url** → **`URL`**
175
+ * **cert_path** → **`string`**
170
176
 
171
- Returns the URL of the APNS endpoint.
177
+ Returns the path to the certificate.
172
178
 
173
- * **cert_path** → **`string`**
179
+ * **on(event, &block)**
180
+
181
+ Allows to set a callback for the connection. The only available event is `:error`, which allows to set a callback when an error is raised at socket level, hence in the underlying socket thread.
182
+
183
+ ```ruby
184
+ connection.on(:error) { |exception| puts "Exception has been raised: #{exception}" }
185
+ ```
174
186
 
175
- Returns the path to the certificate
187
+ > If the `:error` callback is not set, the underlying socket thread may raise an error in the main thread at unexpected execution times.
188
+
189
+ * **url** → **`URL`**
190
+
191
+ Returns the URL of the APNS endpoint.
176
192
 
177
193
  ##### Blocking calls
178
194
 
@@ -210,6 +226,13 @@ APNOTIC_POOL = Apnotic::ConnectionPool.new({
210
226
  }, size: 5)
211
227
  ```
212
228
 
229
+ It is also possible to create a connection pool that points to the Apple Development servers by calling instead:
230
+
231
+ ```ruby
232
+ Apnotic::ConnectionPool.development(connection_options, connection_pool_options)
233
+ ```
234
+
235
+
213
236
  ### `Apnotic::Notification`
214
237
  To create a notification for a specific device token:
215
238
 
@@ -222,13 +245,13 @@ These are all Accessor attributes.
222
245
 
223
246
  | Method | Documentation
224
247
  |-----|-----
225
- | `alert` | Refer to the official Apple documentation of [The Notification Payload](https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/TheNotificationPayload.html) for details.
248
+ | `alert` | Refer to the official Apple documentation of [The Payload Key Reference](https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/PayloadKeyReference.html) for details.
226
249
  | `badge` | "
227
250
  | `sound` | "
228
251
  | `content_available` | "
229
252
  | `category` | "
230
253
  | `custom_payload` | "
231
- | `apns_id` | Refer to the [APNs Provider API](https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/APNsProviderAPI.html) for details.
254
+ | `apns_id` | Refer to [Communicating with APNs](https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CommunicatingwithAPNs.html) for details.
232
255
  | `expiration` | "
233
256
  | `priority` | "
234
257
  | `topic` | "
@@ -259,26 +282,27 @@ notification.alert = {
259
282
  notification.url_args = ["boarding", "A998"]
260
283
  ```
261
284
 
285
+
262
286
  ### `Apnotic::Response`
263
287
  The response to a call to `connection.push`.
264
288
 
265
289
  #### Methods
266
290
 
267
- * **ok?** → **`boolean`**
268
-
269
- Returns if the push was successful.
291
+ * **body** → **`hash` or `string`**
270
292
 
271
- * **headers** **`hash`**
293
+ Returns the body of the response in Hash format if a valid JSON was returned, otherwise just the RAW body.
294
+
295
+ * **headers** → **`hash`**
272
296
 
273
297
  Returns a Hash containing the Headers of the response.
298
+
299
+ * **ok?** → **`boolean`**
274
300
 
275
- * **status** **`string`**
276
-
277
- Returns the status code.
301
+ Returns if the push was successful.
278
302
 
279
- * **body** → **`hash` or `string`**
303
+ * **status** → **`string`**
280
304
 
281
- Returns the body of the response in Hash format if a valid JSON was returned, otherwise just the RAW body.
305
+ Returns the status code.
282
306
 
283
307
 
284
308
  ### `Apnotic::Push`
@@ -286,6 +310,10 @@ The push object to be sent in an async call.
286
310
 
287
311
  #### Methods
288
312
 
313
+ * **http2_request** → **`NetHttp2::Request`**
314
+
315
+ Returns the HTTP/2 request of the push.
316
+
289
317
  * **on(event, &block)**
290
318
 
291
319
  Allows to set a callback for the request. Available events are:
@@ -298,12 +326,6 @@ The push object to be sent in an async call.
298
326
  push.on(:response) { |response| p response.headers }
299
327
  ```
300
328
 
301
- * **http2_request** → **`NetHttp2::Request`**
302
-
303
- Returns the HTTP/2 request of the push.
304
-
305
-
306
-
307
329
  ## Getting Your APNs Certificate
308
330
 
309
331
  > These instructions come from another great gem, [apn_on_rails](https://github.com/PRX/apn_on_rails).
@@ -319,6 +341,14 @@ Optionally, you may covert the p12 file to a pem file (this step is optional bec
319
341
  $ openssl pkcs12 -in cert.p12 -out apple_push_notification_production.pem -nodes -clcerts
320
342
  ```
321
343
 
344
+
345
+ ## Thread-Safety
346
+ Apnotic is thread-safe. However, some caution is imperative:
347
+
348
+ * The async callbacks will be executed in a different thread, so ensure that your code in the callbacks is thread-safe.
349
+ * Errors in the underlying socket loop thread will be raised in the main thread at unexpected execution times, unless you specify the `:error` callback on the Connection. If you're using Apnotic with a job manager you should be fine by not specifying this callback.
350
+
351
+
322
352
  ## Contributing
323
353
  So you want to contribute? That's great! Please follow the guidelines below. It will make it easier to get merged in.
324
354
 
@@ -326,7 +356,7 @@ Before implementing a new feature, please submit a ticket to discuss what you in
326
356
 
327
357
  Do not commit to master in your fork. Provide a clean branch without merge commits. Every pull request should have its own topic branch. In this way, every additional adjustments to the original pull request might be done easily, and squashed with `git rebase -i`. The updated branch will be visible in the same pull request, so there will be no need to open new pull requests when there are changes to be applied.
328
358
 
329
- Ensure to include proper testing. To run tests you simply have to be in the project's root directory and run:
359
+ Ensure that proper testing is included. To run tests you simply have to be in the project's root directory and run:
330
360
 
331
361
  ```bash
332
362
  $ rake
@@ -18,7 +18,7 @@ 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.14", "< 2"
21
+ spec.add_dependency "net-http2", ">= 0.15", "< 2"
22
22
  spec.add_dependency "connection_pool", "~> 2.0"
23
23
 
24
24
  spec.add_development_dependency "bundler", "~> 1.3"
@@ -58,6 +58,10 @@ module Apnotic
58
58
  @client.join
59
59
  end
60
60
 
61
+ def on(event, &block)
62
+ @client.on(event, &block)
63
+ end
64
+
61
65
  private
62
66
 
63
67
  def ssl_context
@@ -4,9 +4,17 @@ module Apnotic
4
4
 
5
5
  class ConnectionPool
6
6
 
7
- def self.new(options={}, pool_options={})
8
- ::ConnectionPool.new(pool_options) do
9
- Apnotic::Connection.new(options)
7
+ class << self
8
+ def new(options={}, pool_options={})
9
+ ::ConnectionPool.new(pool_options) do
10
+ Apnotic::Connection.new(options)
11
+ end
12
+ end
13
+
14
+ def development(options={}, pool_options={})
15
+ ::ConnectionPool.new(pool_options) do
16
+ Apnotic::Connection.development(options)
17
+ end
10
18
  end
11
19
  end
12
20
  end
@@ -14,8 +14,8 @@ module Apnotic
14
14
  def build_headers_for(notification)
15
15
  h = {}
16
16
  h.merge!('apns-id' => notification.apns_id) if notification.apns_id
17
- h.merge!('apns-expiration' => notification.expiration.to_s) if notification.expiration
18
- h.merge!('apns-priority' => notification.priority.to_s) if notification.priority
17
+ h.merge!('apns-expiration' => notification.expiration) if notification.expiration
18
+ h.merge!('apns-priority' => notification.priority) if notification.priority
19
19
  h.merge!('apns-topic' => notification.topic) if notification.topic
20
20
  h.merge!('apns-collapse-id' => notification.apns_collapse_id) if notification.apns_collapse_id
21
21
  h
@@ -1,3 +1,3 @@
1
1
  module Apnotic
2
- VERSION = "1.0.1"
2
+ VERSION = '1.1.0'.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.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roberto Ostinelli
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-09-30 00:00:00.000000000 Z
11
+ date: 2017-03-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.14'
19
+ version: '0.15'
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.14'
29
+ version: '0.15'
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
32
  version: '2'