fcm 0.0.2 → 1.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 54f66db484403cdfb990353ebf8c52553de4beb9
4
- data.tar.gz: 77bdb6784ce6688ee0f3cc468ecf3ab1e7ccd2b4
2
+ SHA256:
3
+ metadata.gz: 16615f79f5432e2a352dc3c26e42d48efed7727a86f04f2b9d2bf93cca47aae6
4
+ data.tar.gz: d2fe30204d7ef51288014fbcc2df5f211ea8d8b4dbbc28cb9af0d9fadc54d6c7
5
5
  SHA512:
6
- metadata.gz: a97f8d1a9d24f436a928f288b302828022bb542529435a155d4758cd014ff19bfd5ce295e746597717d2b45e3e8d6523a97a1336e87555e734c492d31b6252bf
7
- data.tar.gz: dc3ea1cf7d433759648a27e579000616f1fd322bf0d477dd5d67fc39ca7483dc2d12d870856585161d809df3d641c3482f0380af0168b69d1003312a71a30e83
6
+ metadata.gz: 06c32340bae1ab25e1d66c06d63fa5d7276214604902218a1a9f5cf06774a60a08ab4bc700616f63ed5563a8b106227ef073168fcbfa29798348fadec2480767
7
+ data.tar.gz: ffa28e382feba7728e496318ea546237c9c5070ccc175d71a2dc83e9adf0a58efa932336a729549599978b6a2406ec01e80bd060997f779631d3a53122660b59
@@ -0,0 +1,30 @@
1
+ name: Tests
2
+
3
+ on:
4
+ pull_request:
5
+ branches:
6
+ - '*'
7
+ push:
8
+ branches:
9
+ - master
10
+
11
+ jobs:
12
+ tests:
13
+ runs-on: ubuntu-latest
14
+ strategy:
15
+ matrix:
16
+ ruby: ['2.7', '3.0', '3.1']
17
+
18
+ steps:
19
+ - uses: actions/checkout@master
20
+
21
+ - name: Set up Ruby
22
+ uses: ruby/setup-ruby@v1
23
+ with:
24
+ ruby-version: ${{ matrix.ruby }}
25
+ bundler: default
26
+ bundler-cache: true
27
+
28
+ - name: Run tests
29
+ run: |
30
+ bundle exec rspec
data/.gitignore CHANGED
@@ -48,3 +48,4 @@ specifications
48
48
  Gemfile.lock
49
49
  .rvmrc
50
50
  spec/reports
51
+ *.gem
data/Gemfile CHANGED
@@ -5,3 +5,4 @@ gem 'rake'
5
5
  gem 'rspec'
6
6
  gem 'webmock'
7
7
  gem 'ci_reporter_rspec'
8
+ gem 'googleauth'
data/README.md CHANGED
@@ -1,10 +1,11 @@
1
1
  # Firebase Cloud Messaging (FCM) for Android and iOS
2
- [![Gem Version](https://badge.fury.io/rb/fcm.svg)](http://badge.fury.io/rb/fcm) [![Build Status](https://secure.travis-ci.org/spacialdb/fcm.png?branch=master)](http://travis-ci.org/spacialdb/fcm)
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/fcm.svg)](http://badge.fury.io/rb/fcm) [![Build Status](https://github.com/decision-labs/fcm/workflows/Tests/badge.svg)](https://github.com/decision-labs/fcm/actions)
3
4
 
4
5
  The FCM gem lets your ruby backend send notifications to Android and iOS devices via [
5
6
  Firebase Cloud Messaging](https://firebase.google.com/docs/cloud-messaging/).
6
7
 
7
- ##Installation
8
+ ## Installation
8
9
 
9
10
  $ gem install fcm
10
11
 
@@ -14,53 +15,99 @@ or in your `Gemfile` just include it:
14
15
  gem 'fcm'
15
16
  ```
16
17
 
17
- ##Requirements
18
+ ## Requirements
18
19
 
19
20
  For Android you will need a device running 2.3 (or newer) that also have the Google Play Store app installed, or an emulator running Android 2.3 with Google APIs. iOS devices are also supported.
20
21
 
21
- One of the following, tested Ruby versions:
22
+ A version of supported Ruby, currently:
23
+ `ruby >= 2.4`
24
+
25
+ ## Usage
26
+
27
+ ## HTTP v1 API
28
+
29
+ To migrate to HTTP v1 see: https://firebase.google.com/docs/cloud-messaging/migrate-v1
30
+
31
+ ```ruby
32
+ fcm = FCM.new(
33
+ API_TOKEN,
34
+ GOOGLE_APPLICATION_CREDENTIALS_PATH,
35
+ FIREBASE_PROJECT_ID
36
+ )
37
+ message = {
38
+ 'topic': "89023", # OR token if you want to send to a specific device
39
+ # 'token': "000iddqd",
40
+ 'data': {
41
+ payload: {
42
+ data: {
43
+ id: 1
44
+ }
45
+ }.to_json
46
+ },
47
+ 'notification': {
48
+ title: notification.title_th,
49
+ body: notification.body_th,
50
+ },
51
+ 'android': {},
52
+ 'apns': {
53
+ payload: {
54
+ aps: {
55
+ sound: "default",
56
+ category: "#{Time.zone.now.to_i}"
57
+ }
58
+ }
59
+ },
60
+ 'fcm_options': {
61
+ analytics_label: 'Label'
62
+ }
63
+ }
64
+
65
+ fcm.send_v1(message)
66
+ ```
22
67
 
23
- * `2.0.0`
24
- * `2.1.9`
25
- * `2.2.5`
26
- * `2.3.1`
68
+ ## HTTP Legacy Version
27
69
 
28
- ##Usage
70
+ To migrate to HTTP v1 see: https://firebase.google.com/docs/cloud-messaging/migrate-v1
29
71
 
30
- For your server to send a message to one or more devices, you must first initialise a new `FCM` class with your Firebase server Api key, and then call the `send` method on this and give it 1 or more (up to 1000) registration tokens as an array of strings. You can also optionally send further [HTTP message parameters](https://firebase.google.com/docs/cloud-messaging/http-server-ref) like `data` or `time_to_live` etc. as a hash via the second optional argument to `send`.
72
+ For your server to send a message to one or more devices, you must first initialise a new `FCM` class with your Firebase Cloud Messaging server key, and then call the `send` method on this and give it 1 or more (up to 1000) registration tokens as an array of strings. You can also optionally send further [HTTP message parameters](https://firebase.google.com/docs/cloud-messaging/http-server-ref) like `data` or `time_to_live` etc. as a hash via the second optional argument to `send`.
31
73
 
32
74
  Example sending notifications:
33
75
 
34
76
  ```ruby
35
77
  require 'fcm'
36
78
 
37
- fcm = FCM.new("my_api_key")
38
- # you can set option parameters in here
39
- # - all options are pass to HTTParty method arguments
40
- # - ref: https://github.com/jnunemaker/httparty/blob/master/lib/httparty.rb#L29-L60
41
- # fcm = FCM.new("my_api_key", timeout: 3)
79
+ fcm = FCM.new("my_server_key")
42
80
 
43
81
  registration_ids= ["12", "13"] # an array of one or more client registration tokens
44
- options = {data: {score: "123"}, collapse_key: "updated_score"}
82
+
83
+ # See https://firebase.google.com/docs/cloud-messaging/http-server-ref for all available options.
84
+ options = { "notification": {
85
+ "title": "Portugal vs. Denmark",
86
+ "body": "5 to 1"
87
+ }
88
+ }
45
89
  response = fcm.send(registration_ids, options)
46
90
  ```
47
91
 
48
- Currently `response` is just a hash containing the response `body`, `headers` and `status`. Check [here](https://firebase.google.com/docs/cloud-messaging/server#response) to see how to interpret the responses.
92
+ Currently `response` is just a hash containing the response `body`, `headers` and `status_code`. Check [here](https://firebase.google.com/docs/cloud-messaging/server#response) to see how to interpret the responses.
49
93
 
50
94
  ## Device Group Messaging
51
95
 
52
96
  With [device group messaging](https://firebase.google.com/docs/cloud-messaging/notifications), you can send a single message to multiple instance of an app running on devices belonging to a group. Typically, "group" refers a set of different devices that belong to a single user. However, a group could also represent a set of devices where the app instance functions in a highly correlated manner. To use this feature, you will first need an initialised `FCM` class.
53
97
 
54
98
  ### Generate a Notification Key for device group
55
- Then you will need a notification key which you can create for a particular `key_name` which needs to be uniquely named per app in case you have multiple apps for the same `project_id`. This ensures that notifications only go to the intended target app. The `create` method will do this and return the token `notification_key`, that represents the device group, in the response:
99
+
100
+ Then you will need a notification key which you can create for a particular `key_name` which needs to be uniquely named per app in case you have multiple apps for the same `project_id`. This ensures that notifications only go to the intended target app. The `create` method will do this and return the token `notification_key`, that represents the device group, in the response:
56
101
 
57
102
  ```ruby
58
- response = fcm.create(key_name: "appUser-Chris",
103
+ params = {key_name: "appUser-Chris",
59
104
  project_id: "my_project_id",
60
- registration_ids: ["4", "8", "15", "16", "23", "42"])
105
+ registration_ids: ["4", "8", "15", "16", "23", "42"]}
106
+ response = fcm.create(*params.values)
61
107
  ```
62
108
 
63
109
  ### Send to Notification Key
110
+
64
111
  Now you can send a message to a particular `notification_key` via the `send_with_notification_key` method. This allows the server to send a single [data](https://firebase.google.com/docs/cloud-messaging/concept-options#data_messages) payload or/and [notification](https://firebase.google.com/docs/cloud-messaging/concept-options#notifications) payload to multiple app instances (typically on multiple devices) owned by a single user (instead of sending to some registration tokens). Note: the maximum number of members allowed for a `notification_key` is 20.
65
112
 
66
113
  ```ruby
@@ -74,31 +121,85 @@ response = fcm.send_with_notification_key("notification_key",
74
121
  You can also add/remove registration Tokens to/from a particular `notification_key` of some `project_id`. For example:
75
122
 
76
123
  ```ruby
77
- response = fcm.add(key_name: "appUser-Chris",
124
+ params = { key_name: "appUser-Chris",
78
125
  project_id: "my_project_id",
79
126
  notification_key:"appUser-Chris-key",
80
- registration_ids:["7", "3"])
127
+ registration_ids:["7", "3"] }
128
+ response = fcm.add(*params.values)
81
129
 
82
- response = fcm.remove(key_name: "appUser-Chris",
130
+ params = { key_name: "appUser-Chris",
83
131
  project_id: "my_project_id",
84
132
  notification_key:"appUser-Chris-key",
85
- registration_ids:["8", "15"])
133
+ registration_ids:["8", "15"] }
134
+ response = fcm.remove(*params.values)
86
135
  ```
87
136
 
88
137
  ## Send Messages to Topics
89
138
 
90
- FCM [topic messaging](https://firebase.google.com/docs/cloud-messaging/topic-messaging) allows your app server to send a message to multiple devices that have opted in to a particular topic. Based on the publish/subscribe model, topic messaging supports unlimited subscriptions per app. Sending to a topic is very similar to sending to an individual device or to a user group, in the sense that you can use the `fcm.send_with_notification_key()` method where the `noticiation_key` matches the regular expression `"/topics/[a-zA-Z0-9-_.~%]+"`:
139
+ FCM [topic messaging](https://firebase.google.com/docs/cloud-messaging/topic-messaging) allows your app server to send a message to multiple devices that have opted in to a particular topic. Based on the publish/subscribe model, topic messaging supports unlimited subscriptions per app. Sending to a topic is very similar to sending to an individual device or to a user group, in the sense that you can use the `fcm.send_with_notification_key()` method where the `notification_key` matches the regular expression `"/topics/[a-zA-Z0-9-_.~%]+"`:
91
140
 
92
141
  ```ruby
93
142
  response = fcm.send_with_notification_key("/topics/yourTopic",
94
- data: {message: "This is a FCM Topic Message!")
143
+ notification: {body: "This is a FCM Topic Message!"})
95
144
  ```
96
145
 
97
146
  Or you can use the helper:
98
147
 
99
148
  ```ruby
100
149
  response = fcm.send_to_topic("yourTopic",
101
- data: {message: "This is a FCM Topic Message!")
150
+ notification: {body: "This is a FCM Topic Message!"})
151
+ ```
152
+
153
+ ### Sending to Multiple Topics
154
+
155
+ To send to combinations of multiple topics, the FCM [docs](https://firebase.google.com/docs/cloud-messaging/send-message#send_messages_to_topics_2) require that you set a **condition** key (instead of the `to:` key) to a boolean condition that specifies the target topics. For example, to send messages to devices that subscribed to _TopicA_ and either _TopicB_ or _TopicC_:
156
+
157
+ ```
158
+ 'TopicA' in topics && ('TopicB' in topics || 'TopicC' in topics)
159
+ ```
160
+
161
+ FCM first evaluates any conditions in parentheses, and then evaluates the expression from left to right. In the above expression, a user subscribed to any single topic does not receive the message. Likewise, a user who does not subscribe to TopicA does not receive the message. These combinations do receive it:
162
+
163
+ - TopicA and TopicB
164
+ - TopicA and TopicC
165
+
166
+ You can include up to five topics in your conditional expression, and parentheses are supported. Supported operators: `&&`, `||`, `!`. Note the usage for !:
167
+
168
+ ```
169
+ !('TopicA' in topics)
170
+ ```
171
+
172
+ With this expression, any app instances that are not subscribed to TopicA, including app instances that are not subscribed to any topic, receive the message.
173
+
174
+ The `send_to_topic_condition` method within this library allows you to specicy a condition of multiple topics to which to send to the data payload.
175
+
176
+ ```ruby
177
+ response = fcm.send_to_topic_condition(
178
+ "'TopicA' in topics && ('TopicB' in topics || 'TopicC' in topics)",
179
+ notification: {
180
+ body: "This is an FCM Topic Message sent to a condition!"
181
+ }
182
+ )
183
+ ```
184
+
185
+ ## Subscribe the client app to a topic
186
+
187
+ Given a registration token and a topic name, you can add the token to the topic using the [Google Instance ID server API](https://developers.google.com/instance-id/reference/server).
188
+
189
+ ```ruby
190
+ topic = "YourTopic"
191
+ registration_id= "12" # a client registration tokens
192
+ response = fcm.topic_subscription(topic, registration_id)
193
+ ```
194
+
195
+ Or you can manage relationship maps for multiple app instances [Google Instance ID server API. Manage relationship](https://developers.google.com/instance-id/reference/server#manage_relationship_maps_for_multiple_app_instances)
196
+
197
+ ```ruby
198
+ topic = "YourTopic"
199
+ registration_ids= ["4", "8", "15", "16", "23", "42"] # an array of one or more client registration tokens
200
+ response = fcm.batch_topic_subscription(topic, registration_ids)
201
+ # or unsubscription
202
+ response = fcm.batch_topic_unsubscription(topic, registration_ids)
102
203
  ```
103
204
 
104
205
  ## Mobile Clients
@@ -109,24 +210,62 @@ The guide to set up an iOS app to get notifications is here: [Setting up a FCM C
109
210
 
110
211
  ## ChangeLog
111
212
 
213
+ ### 1.0.8
214
+ - caches calls to `Google::Auth::ServiceAccountCredentials` #103
215
+ - Allow `faraday` versions from 1 up to 2 #101
216
+
217
+ ### 1.0.7
218
+
219
+ - Fix passing `DEFAULT_TIMEOUT` to `faraday` [#96](https://github.com/decision-labs/fcm/pull/96)
220
+ - Fix issue with `get_instance_id_info` option params [#98](https://github.com/decision-labs/fcm/pull/98)
221
+ - Accept any IO object for credentials [#95](https://github.com/decision-labs/fcm/pull/94)
222
+
223
+ Huge thanks to @excid3 @jsparling @jensljungblad
224
+
225
+ ### 1.0.3
226
+
227
+ - Fix overly strict faraday dependency
228
+
229
+ ### 1.0.2
230
+
231
+ - Bug fix: retrieve notification key" params: https://github.com/spacialdb/fcm/commit/b328a75c11d779a06d0ceda83527e26aa0495774
232
+
233
+ ### 1.0.0
234
+
235
+ - Bumped supported ruby to `>= 2.4`
236
+ - Fix deprecation warnings from `faraday` by changing dependency version to `faraday 1.0.0`
237
+
238
+ ### 0.0.7
239
+
240
+ - replace `httparty` with `faraday`
241
+
112
242
  ### 0.0.2
113
243
 
114
- * Fixed group messaging url.
115
- * Added API to `recover_notification_key`.
244
+ - Fixed group messaging url.
245
+ - Added API to `recover_notification_key`.
246
+
116
247
 
117
248
  ### 0.0.1
118
249
 
119
- * Initial version.
250
+ - Initial version.
251
+
252
+ ## MIT License
120
253
 
121
- ##MIT License
254
+ - Copyright (c) 2016 Kashif Rasul and Shoaib Burq. See LICENSE.txt for details.
122
255
 
123
- * Copyright (c) 2016 Kashif Rasul and Shoaib Burq. See LICENSE.txt for details.
256
+ ## Many thanks to all the contributors
124
257
 
125
- ##Many thanks to all the contributors
258
+ - [Contributors](https://github.com/spacialdb/fcm/contributors)
126
259
 
127
- * [Contributors](https://github.com/spacialdb/fcm/contributors)
260
+ ## Cutting a release
128
261
 
129
- ## Donations
130
- We accept tips through [Gratipay](https://gratipay.com/spacialdb/).
262
+ Update version in `fcm.gemspec` with `VERSION` and update `README.md` `## ChangeLog` section.
131
263
 
132
- [![Gratipay](https://img.shields.io/gratipay/spacialdb.svg)](https://www.gittip.com/spacialdb/)
264
+ ```bash
265
+ # set the version
266
+ # VERSION="1.0.7"
267
+ gem build fcm.gemspec
268
+ git tag -a v${VERSION} -m "Releasing version v${VERSION}"
269
+ git push origin --tags
270
+ gem push fcm-${VERSION}.gem
271
+ ```
data/fcm.gemspec CHANGED
@@ -2,25 +2,23 @@
2
2
  $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
- s.name = "fcm"
6
- s.version = "0.0.2"
7
- s.platform = Gem::Platform::RUBY
8
- s.authors = ["Kashif Rasul", "Shoaib Burq"]
9
- s.email = ["kashif@spacialdb.com", "shoaib@spacialdb.com"]
10
- s.homepage = "https://github.com/spacialdb/fcm"
11
- s.summary = %q{Reliably deliver messages and notifications via FCM}
5
+ s.name = "fcm"
6
+ s.version = "1.0.8"
7
+ s.platform = Gem::Platform::RUBY
8
+ s.authors = ["Kashif Rasul", "Shoaib Burq"]
9
+ s.email = ["kashif@decision-labs.com", "shoaib@decision-labs.com"]
10
+ s.homepage = "https://github.com/decision-labs/fcm"
11
+ s.summary = %q{Reliably deliver messages and notifications via FCM}
12
12
  s.description = %q{fcm provides ruby bindings to Firebase Cloud Messaging (FCM) a cross-platform messaging solution that lets you reliably deliver messages and notifications at no cost to Android, iOS or Web browsers.}
13
- s.license = "MIT"
13
+ s.license = "MIT"
14
14
 
15
- s.required_ruby_version = '>= 2.0.0'
15
+ s.required_ruby_version = ">= 2.4.0"
16
16
 
17
- s.rubyforge_project = "fcm"
18
-
19
- s.files = `git ls-files`.split("\n")
20
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
21
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
22
20
  s.require_paths = ["lib"]
23
21
 
24
- s.add_dependency('httparty')
25
- s.add_dependency('json')
22
+ s.add_runtime_dependency("faraday", ">= 1.0.0", "< 3.0")
23
+ s.add_runtime_dependency("googleauth", "~> 1")
26
24
  end