expo-server-sdk 0.1.4 → 0.1.6

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: 88fbd428de8ccf50c783cd846f236d259560fc6dc4eeed67f6bced8e1851dc8f
4
- data.tar.gz: 6f720c4b67e2d19d75a72cce990deae055f55fecdac6d0e04fc10a3cfe6175b5
3
+ metadata.gz: 925465e0c26cba7d42eb9ae21e3e6b406ea364bdabaeec0d9337e650b045a512
4
+ data.tar.gz: 38b0df830bb02bc55b167717bd7fd7122018f6e0df1f036f403f93591c70d59b
5
5
  SHA512:
6
- metadata.gz: a7bfc9795ac626e819cccc0dcb023cef728fa3d4e7721a6e4f2af67c79c7bd41d5744794f1eb29571cd957ea8eaa951692db0f6b18e3c70e2f8fb456d68d6375
7
- data.tar.gz: 113707ebc856f9488cde8ac359cb0e02f329a12c238c8e0bab0b89eef83a43e51339e53d4be5a02f5b6db33006f31a924845465139677f2117184abbfffbbd93
6
+ metadata.gz: 1403beda4c6f998efde04ade431d75fbf85e650217032a016dd1c5ba65a806ad6dfc7051f348271f951b28239552a0078bba961afb08571ee255095a4f201865
7
+ data.tar.gz: 5717904965e62d883ca26a8a23b7fe948092faab9780c345c60d53d617bf5fbe5eca0db2cb949132b02051809c554d3a20a84b45740e87a8497fa38755651503
data/.gitattributes CHANGED
@@ -1 +1 @@
1
- * text=auto eol=lf
1
+ * text=auto eol=lf
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.1.6
4
+
5
+ - Fix authentication for authenticated pushes [#6](https://github.com/SleeplessByte/expo-server-sdk-ruby/pull/6) by [@pvign](https://github.com/pvign)
6
+
7
+ ## 0.1.5
8
+
9
+ - Remove unnecessary logging [#4](https://github.com/SleeplessByte/expo-server-sdk-ruby/pull/4) by [@stefanahman](https://github.com/stefanahman)
10
+
3
11
  ## 0.1.4
4
12
 
5
13
  - Change `ruby` version requirement to major only (2.6+)
data/Gemfile.lock CHANGED
@@ -1,29 +1,29 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- expo-server-sdk (0.1.4)
4
+ expo-server-sdk (0.1.6)
5
5
  connection_pool (~> 2.2)
6
6
  http (>= 4.0, < 6.0)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- addressable (2.8.0)
12
- public_suffix (>= 2.0.2, < 5.0)
11
+ addressable (2.8.4)
12
+ public_suffix (>= 2.0.2, < 6.0)
13
13
  ast (2.4.2)
14
- connection_pool (2.2.5)
14
+ connection_pool (2.4.1)
15
15
  domain_name (0.5.20190701)
16
16
  unf (>= 0.0.5, < 1.0.0)
17
- ffi (1.15.4-x64-mingw32)
17
+ ffi (1.15.5-x64-mingw32)
18
18
  ffi-compiler (1.0.1)
19
19
  ffi (>= 1.0.0)
20
20
  rake
21
- http (5.0.4)
21
+ http (5.1.1)
22
22
  addressable (~> 2.8)
23
23
  http-cookie (~> 1.0)
24
24
  http-form_data (~> 2.2)
25
25
  llhttp-ffi (~> 0.4.0)
26
- http-cookie (1.0.4)
26
+ http-cookie (1.0.5)
27
27
  domain_name (~> 0.5)
28
28
  http-form_data (2.3.0)
29
29
  llhttp-ffi (0.4.0)
@@ -33,7 +33,7 @@ GEM
33
33
  parallel (1.21.0)
34
34
  parser (3.0.2.0)
35
35
  ast (~> 2.4.1)
36
- public_suffix (4.0.6)
36
+ public_suffix (5.0.1)
37
37
  rainbow (3.0.0)
38
38
  rake (13.0.6)
39
39
  regexp_parser (2.1.1)
@@ -52,7 +52,7 @@ GEM
52
52
  ruby-progressbar (1.11.0)
53
53
  unf (0.1.4)
54
54
  unf_ext
55
- unf_ext (0.0.8-x64-mingw32)
55
+ unf_ext (0.0.8.2-x64-mingw32)
56
56
  unicode-display_width (2.1.0)
57
57
 
58
58
  PLATFORMS
data/README.md CHANGED
@@ -29,11 +29,15 @@ gem install expo-server-sdk
29
29
  ## Usage
30
30
 
31
31
  ```ruby
32
- require 'expo-server-sdk'
32
+ # Not necessary in Rails. Zeitwerk will require this correctly for you.
33
+ require 'expo/server/sdk'
33
34
 
34
35
  # Create a new Expo SDK client optionally providing an access token if you
35
36
  # have enabled push security
36
- client = Expo::Push::Client.new(accessToken: '<access-token>');
37
+ client = Expo::Push::Client.new(access_token: '<access-token>');
38
+
39
+ # If you do not have an access token, you can call it like this:
40
+ # client = Expo::Push::Client.new
37
41
 
38
42
  # Create the messages that you want to send to clients
39
43
  messages = [];
@@ -111,7 +115,7 @@ tickets.each_error do |error|
111
115
  else
112
116
  puts error.message
113
117
  # => "This indicates the entire request had an error"
114
- else
118
+ end
115
119
  end
116
120
 
117
121
  # Later, after the Expo push notification service has delivered the
@@ -231,6 +235,105 @@ client = Expo::Push::Client.new(
231
235
  )
232
236
  ```
233
237
 
238
+ ### Example of error handling
239
+
240
+ Here is an example of error handling when using Rails, given a Rails model called `PushNotificationToken`.
241
+
242
+ The most important thing is that you remove push tokens that are invalid, you fix push tokens that don't have the right experience ID and you stop sending push notifications if you're not allowed (e.g. the device is no longer registered).
243
+
244
+ ```ruby
245
+ # Remove invalid push notification tokens, and remove tokens that failed
246
+ # and contain a token (DeviceNotRegistered)
247
+ tickets.each_error do |error|
248
+
249
+ if error.is_a?(Expo::Push::PushTokenInvalid)
250
+ # Destroy the tokens that match because they are not valid
251
+ PushNotificationToken.where(push_token: error.token).destroy_all
252
+
253
+ elsif error.is_a?(Expo::Push::TicketsWithErrors)
254
+ retryable = true
255
+
256
+ error.errors.each do |error_data|
257
+
258
+ # This block tries to fix the token experiences, and then reschedules
259
+ # the job. When it fixes tokens, it notifies bugsnag, so we know that
260
+ # this happened. If it keeps happening, there is a bug in the query
261
+ # or registration code.
262
+ if error_data['code'] == "PUSH_TOO_MANY_EXPERIENCE_IDS"
263
+
264
+ # Go through all the details
265
+ error_data['details'].each do |correct_experience, tokens|
266
+
267
+ # Find the incorrect instances
268
+ instances = PushNotificationToken
269
+ .where.not(experience_id: correct_experience)
270
+ .where(push_token: tokens)
271
+
272
+ next if instances.blank?
273
+ next unless instances.update_all(experience_id: correct_experience)
274
+
275
+ instances.each do |instance|
276
+ Bugsnag.notify(
277
+ StandardError.new(
278
+ format(
279
+ 'When trying to push, a push token (token: %s) had the wrong experience id (old: %s). ' \
280
+ 'It has been updated (%s).',
281
+ instance.push_token,
282
+ instance.experience_id_was,
283
+ instance.experience_id
284
+ )
285
+ )
286
+ )
287
+ end
288
+ end
289
+
290
+ # If there is a different error, report to our error tracker
291
+ else
292
+ retryable = false
293
+ # Otherwise, notify as actual error.
294
+ Bugsnag.notify(error_data)
295
+ end
296
+ end
297
+
298
+ if retries > 10
299
+ return Bugsnag.notify(
300
+ StandardError.new(
301
+ 'Not sending push notification because it was retried > 10 times.'
302
+ )
303
+ )
304
+ end
305
+
306
+ # If the error is not a fatal one, the push can be retried. This helps
307
+ # with making sure you always send the push notification(s) even when
308
+ # the service intermittendly fails.
309
+ if retryable
310
+ ScheduledPushNotificationJob
311
+ .set(wait: 1.minute * (retries + 1))
312
+ .perform_later(
313
+ notification: notification,
314
+ event: event,
315
+ updated_at: updated_at,
316
+ retries: retries + 1
317
+ )
318
+ end
319
+
320
+ # Otherwise it's an explanable error
321
+ elsif error.respond_to?(:explain)
322
+
323
+ # If the error contains a token it always needs to be removed
324
+ original_token = error.original_push_token
325
+ next unless original_token
326
+
327
+ PushNotificationToken.where(push_token: original_token).destroy_all
328
+ else
329
+
330
+ # Notify us of any other type of error
331
+ Bugsnag.notify(error)
332
+ end
333
+ end
334
+
335
+ ```
336
+
234
337
  ## Development
235
338
 
236
339
  After checking out the repo, run `bin/setup` to install dependencies.
@@ -3,7 +3,7 @@
3
3
  module Expo
4
4
  module Server
5
5
  module SDK
6
- VERSION = '0.1.4'
6
+ VERSION = '0.1.6'
7
7
  end
8
8
  end
9
9
 
data/lib/push/client.rb CHANGED
@@ -256,7 +256,7 @@ module Expo
256
256
  'User-Agent': format('expo-server-sdk-ruby/%<version>s', version: VERSION)
257
257
  )
258
258
 
259
- http = http.headers('Authorization', "Bearer #{access_token}") if access_token
259
+ http = http.auth("Bearer #{access_token}") if access_token
260
260
 
261
261
  # All requests are allowed to automatically gzip
262
262
  http = http.use(:auto_inflate)
@@ -330,8 +330,6 @@ module Expo
330
330
  end
331
331
 
332
332
  def as_json
333
- puts _params
334
-
335
333
  { to: recipients }.merge(_params.compact)
336
334
  end
337
335
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: expo-server-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Derk-Jan Karrenbeld
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-11-09 00:00:00.000000000 Z
11
+ date: 2023-07-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: connection_pool