expo-server-sdk 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: '0870d677aad54e5517e91013161aedada958f24ad0437e9acda0b315b7746e80'
4
+ data.tar.gz: cc9ef8fd683e4e386b028dd966b108ec5f242ed8985721858103b01f53974703
5
+ SHA512:
6
+ metadata.gz: a160681a4b6f96cc776d657a732ef104138da93f77bf9f3d4c6faf773b69deb5231d263202a04b4ddb858436ac1c62a8672de3afabff038714493bcda7f22bfc
7
+ data.tar.gz: b0b47c52921e099ef1b0cf0f434e1c1454f2398b551d85c46058c35bd06269046d3591e9df1503f3e58bc4e12c241234d0468445707c9e7763b7936a6bb323e9
data/.gitattributes ADDED
@@ -0,0 +1 @@
1
+ * text=auto eol=lf
@@ -0,0 +1,18 @@
1
+ name: Ruby
2
+
3
+ on: [push,pull_request]
4
+
5
+ jobs:
6
+ build:
7
+ runs-on: ubuntu-latest
8
+ steps:
9
+ - uses: actions/checkout@v2
10
+ - name: Set up Ruby
11
+ uses: ruby/setup-ruby@v1
12
+ with:
13
+ ruby-version: 2.7.4
14
+ - name: Run the default task
15
+ run: |
16
+ gem install bundler -v 2.2.7
17
+ bundle install
18
+ bundle exec rake
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/.rubocop.yml ADDED
@@ -0,0 +1,18 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.6
3
+ NewCops: enable
4
+
5
+ Style/StringLiterals:
6
+ Enabled: true
7
+ EnforcedStyle: single_quotes
8
+
9
+ Style/StringLiteralsInInterpolation:
10
+ Enabled: true
11
+ EnforcedStyle: single_quotes
12
+
13
+ Layout/EndOfLine:
14
+ Enabled: true
15
+ EnforcedStyle: lf
16
+
17
+ Layout/LineLength:
18
+ Max: 120
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at derk-jan+github@karrenbeld.info. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in expo-server-sdk.gemspec
6
+ gemspec
7
+
8
+ gem 'minitest', '~> 5.0'
9
+ gem 'rake', '~> 13.0'
10
+ gem 'rubocop', '~> 1.7'
data/Gemfile.lock ADDED
@@ -0,0 +1,68 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ expo-server-sdk (0.1.0)
5
+ connection_pool (~> 2.2)
6
+ http (~> 5.0)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ addressable (2.8.0)
12
+ public_suffix (>= 2.0.2, < 5.0)
13
+ ast (2.4.2)
14
+ connection_pool (2.2.5)
15
+ domain_name (0.5.20190701)
16
+ unf (>= 0.0.5, < 1.0.0)
17
+ ffi (1.15.0-x64-mingw32)
18
+ ffi-compiler (1.0.1)
19
+ ffi (>= 1.0.0)
20
+ rake
21
+ http (5.0.4)
22
+ addressable (~> 2.8)
23
+ http-cookie (~> 1.0)
24
+ http-form_data (~> 2.2)
25
+ llhttp-ffi (~> 0.4.0)
26
+ http-cookie (1.0.3)
27
+ domain_name (~> 0.5)
28
+ http-form_data (2.3.0)
29
+ llhttp-ffi (0.4.0)
30
+ ffi-compiler (~> 1.0)
31
+ rake (~> 13.0)
32
+ minitest (5.14.4)
33
+ parallel (1.20.1)
34
+ parser (3.0.1.1)
35
+ ast (~> 2.4.1)
36
+ public_suffix (4.0.6)
37
+ rainbow (3.0.0)
38
+ rake (13.0.3)
39
+ regexp_parser (1.8.2)
40
+ rexml (3.2.5)
41
+ rubocop (1.9.1)
42
+ parallel (~> 1.10)
43
+ parser (>= 3.0.0.0)
44
+ rainbow (>= 2.2.2, < 4.0)
45
+ regexp_parser (>= 1.8, < 3.0)
46
+ rexml
47
+ rubocop-ast (>= 1.2.0, < 2.0)
48
+ ruby-progressbar (~> 1.7)
49
+ unicode-display_width (>= 1.4.0, < 3.0)
50
+ rubocop-ast (1.5.0)
51
+ parser (>= 3.0.1.1)
52
+ ruby-progressbar (1.11.0)
53
+ unf (0.1.4)
54
+ unf_ext
55
+ unf_ext (0.0.7.7-x64-mingw32)
56
+ unicode-display_width (2.0.0)
57
+
58
+ PLATFORMS
59
+ x64-mingw32
60
+
61
+ DEPENDENCIES
62
+ expo-server-sdk!
63
+ minitest (~> 5.0)
64
+ rake (~> 13.0)
65
+ rubocop (~> 1.7)
66
+
67
+ BUNDLED WITH
68
+ 2.2.7
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Derk-Jan Karrenbeld
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,252 @@
1
+ # Expo::Server::SDK
2
+
3
+ This gem was written because of the relatively little attention and improvement [expo-server-sdk-ruby](https://github.com/expo-community/expo-server-sdk-ruby) receives.
4
+
5
+ It does **not** work in the same way, so you'll want to read the documentation carefully if you intend to migrate.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'expo-server-sdk'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install expo-server-sdk
22
+
23
+ ## Usage
24
+
25
+ ```ruby
26
+ require 'expo-server-sdk'
27
+
28
+ # Create a new Expo SDK client optionally providing an access token if you
29
+ # have enabled push security
30
+ client = Expo::Push::Client.new(accessToken: '<access-token>');
31
+
32
+ # Create the messages that you want to send to clients
33
+ messages = [];
34
+
35
+ some_push_tokens.each do |push_token|
36
+ # Each push token looks like ExponentPushToken[xxxxxxxxxxxxxxxxxxxxxx]
37
+
38
+ # Check that all your push tokens appear to be valid Expo push tokens.
39
+ # If you don't do this, this library will raise an error when trying to
40
+ # create the notification.
41
+ #
42
+ unless Expo::Push.expo_push_token?(push_token)
43
+ puts "Push token #{pushToken} is not a valid Expo push token"
44
+ next
45
+ end
46
+
47
+ # Construct a message (see https://docs.expo.io/push-notifications/sending-notifications/)
48
+ #
49
+ # Use client.notification, Expo::Push::Notification.new,
50
+ # or Expo::Push::Notification.to, then follow it with one or more chainable
51
+ # API calls, including, but not limited to:
52
+ #
53
+ # - #to: add recipient (or #add_recipient),
54
+ # add recipients (or #add_recipients)
55
+ # - #title
56
+ # - #subtitle
57
+ # - #body (or #content)
58
+ # - #data
59
+ # - #priority
60
+ # - #sound
61
+ # - #channel_id
62
+ # - #category_id
63
+ #
64
+ messages << client.notification
65
+ .to(pushToken)
66
+ .sound('default')
67
+ .body('This is a test notification')
68
+ .data({ withSome: 'data' })
69
+ end
70
+
71
+ # The Expo push notification service accepts batches of notifications so that
72
+ # you don't need to send 1000 requests to send 1000 notifications. We
73
+ # recommend you batch your notifications to reduce the number of requests and
74
+ # to compress them (notifications with similar content will get compressed).
75
+ #
76
+ # Using #send or #send! will automatically batch your messages.
77
+ #
78
+ # When using #send, the result is an array of tickets per batched chunk, or may
79
+ # be an error, such as a TicketsWithErrors error. It's up to you to inspect and
80
+ # handle those errors.
81
+ #
82
+ # When using #send!, all batches will first execute, and then the first error
83
+ # received is raised.
84
+ #
85
+ tickets = client.send!(messages)
86
+
87
+ # You can #explain(error) to attempt to explain nested errors. For example, say
88
+ # a batch contains failed errors, or completely failed pages:
89
+ #
90
+ tickets.each_error do |error|
91
+ if error.is_a?(Error)
92
+ puts error.message
93
+ # => "This indicates the entire request had an error"
94
+ else
95
+ puts error.explain
96
+ # => "The device cannot receive push notifications anymore and you should
97
+ # stop sending messages to the corresponding Expo push token."
98
+
99
+ puts error.message
100
+ # => ""ExpoPushToken[xxxxxxxxxxxxxxxxxxxxxx]" is not a registered push
101
+ # notification recipient"
102
+ #
103
+ # In the case of an DeviceNotRegistered, you can attempt to extract the
104
+ # faulty push token:
105
+
106
+ error.original_push_token
107
+ # => ExpoPushToken[xxxxxxxxxxxxxxxxxxxxxx]
108
+ end
109
+ end
110
+
111
+ # Later, after the Expo push notification service has delivered the
112
+ # notifications to Apple or Google (usually quickly, but allow the the service
113
+ # up to 30 minutes when under load), a "receipt" for each notification is
114
+ # created. The receipts will be available for at least a day; stale receipts
115
+ # are deleted.
116
+ #
117
+ # The ID of each receipt is sent back in the response "ticket" for each
118
+ # notification. In summary, sending a notification produces a ticket, which
119
+ # contains a receipt ID you later use to get the receipt.
120
+ #
121
+ # The receipts may contain error codes to which you must respond. In
122
+ # particular, Apple or Google may block apps that continue to send
123
+ # notifications to devices that have blocked notifications or have uninstalled
124
+ # your app. Expo does not control this policy and sends back the feedback from
125
+ # Apple and Google so you can handle it appropriately.
126
+ #
127
+ # Note: this will silently skip over any errors encountered. Use #each_error
128
+ # to attempt to handle them yourself.
129
+ receipt_ids = tickets.ids
130
+
131
+ # You may want to be doing this in some job context, so this gem doesn't batch
132
+ # and call the endpoint manually, but you can generate the batches, and send
133
+ # then individually:
134
+ batches = tickets.batch_ids
135
+
136
+ # Now you can schedule your jobs, thread, or run this inline. All would work.
137
+ batches.each do |receipt_ids|
138
+ # << schedule a job with this batch of ids >>
139
+ # ...
140
+ # inside the job or inline
141
+ receipts = client.receipts(receipt_ids)
142
+
143
+ # You can #explain(error) to attempt to explain receipts that have an
144
+ # error status.
145
+ #
146
+ receipts.each_error do |receipt|
147
+ puts error.explain
148
+ # => "The device cannot receive push notifications anymore and you should
149
+ # stop sending messages to the corresponding Expo push token."
150
+
151
+ puts error.message
152
+ # => ""ExpoPushToken[xxxxxxxxxxxxxxxxxxxxxx]" is not a registered push
153
+ # notification recipient"
154
+ #
155
+ # In the case of an DeviceNotRegistered, you can attempt to extract the
156
+ # faulty push token:
157
+
158
+ error.original_push_token
159
+ # => ExpoPushToken[xxxxxxxxxxxxxxxxxxxxxx]
160
+ end
161
+
162
+ # Because not all receipts may be returned, it is imported to schedule, or
163
+ # retry the unresolved receipts at a later point in time:
164
+ unresolved_ids = receipts.unresolved_ids
165
+
166
+ # ...
167
+ receipts = client.receipts(unresolved_ids) if unresolved_ids.length > 0
168
+ end
169
+ ```
170
+
171
+ ### Logging
172
+
173
+ It is very likely that you'll want to develop with logging turned on.
174
+ This can be accomplished by passing in a logger instance:
175
+
176
+ ```ruby
177
+ require 'logger'
178
+
179
+ logger = Logger.new(STDOUT);
180
+ client = Expo::Push::Client.new(logger: logger)
181
+
182
+ # Now when doing requests like so:
183
+ client.send(notification)
184
+
185
+ # ...it will log
186
+ #
187
+ # I, [2021-10-25T02:16:11.284901 #16448] INFO -- : > POST https://exp.host/--/api/v2/push/send
188
+ # D, [2021-10-25T02:16:11.285601 #16448] DEBUG -- : Accept: application/json
189
+ # Accept-Encoding: gzip
190
+ # User-Agent: expo-server-sdk-ruby/0.1.0
191
+ # Connection: Keep-Alive
192
+ # Content-Type: application/json; charset=UTF-8
193
+ # Host: exp.host
194
+ #
195
+ # [{"to":["ExpoPushToken[xxxxxxxxxxxxxxxxxxxxxx]"]}]
196
+ ```
197
+
198
+ For more advanced logging, or instrumentation in general, use the Instrumentation feature.
199
+ It expects an `ActiveSupport::Notifications`-compatible instrumenter.
200
+
201
+ These are available in most Rails projects by default.
202
+
203
+ ```ruby
204
+ ActiveSupport::Notifications.subscribe('start_request.http') do |name, start, finish, id, payload|
205
+ pp :name => name, :start => start.to_f, :finish => finish.to_f, :id => id, :payload => payload
206
+ end
207
+
208
+ client = Expo::Push::Client.new(instrumentation: true)
209
+
210
+ # Now when doing requests like so:
211
+ client.send(notification)
212
+
213
+ # ...it will instrument
214
+ # => {name: .., start: .., finish: .., id: .., payload: ..}
215
+ ```
216
+
217
+ You can configure the namespace (and instrumentation):
218
+
219
+ ```ruby
220
+ client = Expo::Push::Client.new(
221
+ instrumentation: {
222
+ instrumenter: ActiveSupport::Notifications.instrumenter,
223
+ namespace: "my_http"
224
+ }
225
+ )
226
+ ```
227
+
228
+ ## Development
229
+
230
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
231
+
232
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
233
+
234
+ ## Contributing
235
+
236
+ Bug reports and pull requests are welcome on GitHub at https://github.com/SleeplessByte/expo-server-sdk. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/SleeplessByte/expo-server-sdk/blob/master/CODE_OF_CONDUCT.md).
237
+
238
+ ## License
239
+
240
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
241
+
242
+ ## Code of Conduct
243
+
244
+ Everyone interacting in the `Expo::Server::SDK` project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/SleeplessByte/expo-server-sdk/blob/master/CODE_OF_CONDUCT.md).
245
+
246
+ ```
247
+
248
+ ```
249
+
250
+ ```
251
+
252
+ ```
data/Rakefile ADDED
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rake/testtask'
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << 'test'
8
+ t.libs << 'lib'
9
+ t.test_files = FileList['test/**/*_test.rb']
10
+ end
11
+
12
+ require 'rubocop/rake_task'
13
+
14
+ RuboCop::RakeTask.new
15
+
16
+ task default: %i[test rubocop]
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'expo/server/sdk'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/expo/server/sdk/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'expo-server-sdk'
7
+ spec.version = Expo::Server::SDK::VERSION
8
+ spec.authors = ['Derk-Jan Karrenbeld']
9
+ spec.email = ['derk-jan+github@karrenbeld.info']
10
+
11
+ spec.summary = 'Modern replacement for exponent-server-sdk'
12
+ spec.description = 'This gem has been written to fix shortcomings with the current community provided gem, which ' \
13
+ 'has many outstanding issues and open pull requests.'
14
+ spec.homepage = 'https://github.com/sleeplessbyte/expo-server-sdk-ruby'
15
+ spec.license = 'MIT'
16
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.6.8')
17
+
18
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
19
+
20
+ spec.metadata['homepage_uri'] = spec.homepage
21
+ spec.metadata['source_code_uri'] = spec.homepage
22
+ spec.metadata['bug_tracker_uri'] = "#{spec.homepage}/issues"
23
+ spec.metadata['changelog_uri'] = "#{spec.homepage}/blob/main/CHANGELOG.md"
24
+
25
+ # Specify which files should be added to the gem when it is released.
26
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
27
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
28
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
29
+ end
30
+ spec.bindir = 'exe'
31
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
32
+ spec.require_paths = ['lib']
33
+
34
+ # Uncomment to register a new dependency of your gem
35
+ # spec.add_dependency "example-gem", "~> 1.0"
36
+ spec.add_dependency 'connection_pool', '~> 2.2'
37
+ spec.add_dependency 'http', '~> 5.0'
38
+
39
+ # For more information and examples about making a new gem, checkout our
40
+ # guide at: https://bundler.io/guides/creating_gem.html
41
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Expo
4
+ module Server
5
+ module SDK
6
+ VERSION = '0.1.0'
7
+ end
8
+ end
9
+
10
+ module Push
11
+ class Client
12
+ VERSION = Expo::Server::SDK::VERSION
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'sdk/version'
4
+ require_relative '../../push/client'
5
+
6
+ module Expo
7
+ module Server
8
+ module SDK # rubocop:disable Style/Documentation
9
+ def self.push
10
+ Expo::Push::Client
11
+ end
12
+ end
13
+ end
14
+ end
data/lib/push/chunk.rb ADDED
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Expo
4
+ module Push
5
+ class Chunk # rubocop:disable Style/Documentation
6
+ def self.for(notifications) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
7
+ Array(notifications).each_with_object([]) do |notification, chunks|
8
+ # There can be at most n notifications in a chunk. This finds the last chunk,
9
+ # checks how much space is left, and generates a new chunk if necessary.
10
+ chunk = chunks.last || Chunk.new.tap { |c| chunks << c }
11
+
12
+ targets = notification.recipients.dup
13
+
14
+ while targets.length.positive?
15
+ chunk = Chunk.new.tap { |c| chunks << c } if chunk.remaining <= 0
16
+
17
+ # Take at most <remaining> destinations for this notificiation.
18
+ count = [targets.length, chunk.remaining].min
19
+ chunk_targets = targets.slice(0, count)
20
+
21
+ # Prepare the notification
22
+ chunk << notification.prepare(chunk_targets)
23
+
24
+ # Remove targets from the targets list
25
+ targets = targets.drop(count)
26
+ end
27
+ end
28
+ end
29
+
30
+ attr_reader :remaining
31
+
32
+ def initialize
33
+ self.notifications = []
34
+ self.remaining = PUSH_NOTIFICATION_CHUNK_LIMIT
35
+ end
36
+
37
+ def <<(notification)
38
+ self.remaining -= notification.count
39
+ notifications << notification
40
+
41
+ self
42
+ end
43
+
44
+ def count
45
+ notifications.sum(&:count)
46
+ end
47
+
48
+ def as_json
49
+ notifications.map(&:as_json)
50
+ end
51
+
52
+ private
53
+
54
+ attr_accessor :notifications
55
+ attr_writer :remaining
56
+ end
57
+ end
58
+ end