modulofcm 0.1.0 → 1.1.0
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 +4 -4
- data/CHANGELOG.md +11 -1
- data/README.md +16 -6
- data/lib/modulofcm/client.rb +45 -14
- data/lib/modulofcm/configurator.rb +2 -2
- data/lib/modulofcm/file_i_o.rb +18 -0
- data/lib/modulofcm/response.rb +1 -1
- data/lib/modulofcm/version.rb +1 -1
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bdc31f10864691f7e97b5edbf8967f53226e9452b641887bfd8f37e0113cd76f
|
4
|
+
data.tar.gz: 6192c8281134963a1ad038fc98ee4202b8647511a885092ca96518407f9c3716
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c0c19a73605c65b10a64e95306270c4f20cc3244cc644a2b54b32a95fb900e5efabbb88fd3d30afbdff547da02533f1163e4d37d8ec4c0ab12f936679e137853
|
7
|
+
data.tar.gz: a8e088c71c57b27af300bd70194c9fefdb38aa237503af84374e263108c4040385a48ff57e003d54c12b63ad7336673177187aaee59e594b03ce32e60d3e14e5
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,16 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [1.1.0] - 2024-05-23
|
4
|
+
|
5
|
+
- Send Android notifications with priority high
|
6
|
+
|
7
|
+
## [1.0.0] - 2024-05-22
|
8
|
+
|
9
|
+
- Implement API v1
|
10
|
+
- Fix Modulofcm::Configurator#validate_client for APIv1 clients
|
11
|
+
- Fix typo for Modulofcm::Response#success?
|
12
|
+
|
3
13
|
## [0.1.0] - 2024-04-24
|
4
14
|
|
5
15
|
- Initial release
|
6
|
-
- Send Legacy push notifications.
|
16
|
+
- Send Legacy push notifications.
|
data/README.md
CHANGED
@@ -20,9 +20,14 @@ Modulofcm.configure do |config|
|
|
20
20
|
client.api_key = 'My Legacy HTTP API key - will cease to function after June 2024.'
|
21
21
|
end
|
22
22
|
|
23
|
-
config.client(:
|
24
|
-
client.
|
25
|
-
client.
|
23
|
+
config.client(:api_v1_client) do |client|
|
24
|
+
client.firebase_project_id = 'Firebase Project id'
|
25
|
+
client.google_application_credentials = '{"type": "service_account", "project_id": "...", ...}'
|
26
|
+
end
|
27
|
+
|
28
|
+
config.client(:another_api_v1_client) do |client|
|
29
|
+
client.firebase_project_id = 'Firebase Project id'
|
30
|
+
client.google_application_credentials_path = 'config/google_application_credentials.json'
|
26
31
|
end
|
27
32
|
end
|
28
33
|
|
@@ -30,7 +35,11 @@ end
|
|
30
35
|
data = {
|
31
36
|
id: 232_342,
|
32
37
|
key: 'asd9adfiu6bn',
|
33
|
-
mission_id: 234_323
|
38
|
+
mission_id: 234_323,
|
39
|
+
data: {
|
40
|
+
user_id: 15_123,
|
41
|
+
company_id: 23_341
|
42
|
+
}
|
34
43
|
}
|
35
44
|
|
36
45
|
# All keyword arguments are optional and references a field in Firebase documentation:
|
@@ -54,8 +63,9 @@ data = {
|
|
54
63
|
# data: Arbitrary key/value payload, which must be UTF-8 encoded. The key should not be a reserved word ("from", "message_type", or any word starting with "google" or "gcm").
|
55
64
|
# Legacy: `data`
|
56
65
|
# APIv1: `message.data`
|
57
|
-
Modulofcm.client(:legacy_client).push('
|
58
|
-
Modulofcm.client(:
|
66
|
+
Modulofcm.client(:legacy_client).push('Registration token', data: data, title: 'My title', body: 'The body', sound: 'notif.caf', content_available: true)
|
67
|
+
Modulofcm.client(:api_v1_client).push('Registration token', data: data, title: 'My title', body: 'The body', sound: 'notif.caf', content_available: true)
|
68
|
+
Modulofcm.client(:another_api_v1_client).push('Registration token', data: data, title: 'My title', body: 'The body', sound: 'notif.caf', content_available: true)
|
59
69
|
```
|
60
70
|
|
61
71
|
## Development
|
data/lib/modulofcm/client.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative 'file_i_o'
|
3
4
|
require_relative 'response'
|
4
5
|
|
5
6
|
# rubocop:disable Metrics/ParameterLists
|
@@ -7,14 +8,15 @@ module Modulofcm
|
|
7
8
|
|
8
9
|
class Client
|
9
10
|
|
10
|
-
attr_reader :name, :api_key, :
|
11
|
+
attr_reader :name, :api_key, :google_application_credentials, :firebase_project_id, :mode
|
11
12
|
|
12
|
-
def initialize(name:, api_key: nil,
|
13
|
+
def initialize(name:, api_key: nil,
|
14
|
+
google_application_credentials_path: nil, google_application_credentials: nil,
|
13
15
|
firebase_project_id: nil)
|
14
16
|
@name = name.to_sym
|
15
17
|
@api_key = api_key
|
16
|
-
@api_token = api_token
|
17
18
|
@google_application_credentials_path = google_application_credentials_path
|
19
|
+
@google_application_credentials = google_application_credentials
|
18
20
|
@firebase_project_id = firebase_project_id
|
19
21
|
@mode = :api_v1
|
20
22
|
end
|
@@ -49,12 +51,13 @@ module Modulofcm
|
|
49
51
|
when :legacy
|
50
52
|
push_legacy(token, data: data, title: title, body: body, sound: sound, content_available: content_available)
|
51
53
|
else
|
52
|
-
|
53
|
-
# push_v1(token, data: data, title: title, body: body, sound: sound, content_available: content_available)
|
54
|
+
push_v1(token, data: data, title: title, body: body, sound: sound, content_available: content_available)
|
54
55
|
end
|
55
56
|
end
|
56
57
|
|
57
|
-
%w[
|
58
|
+
%w[
|
59
|
+
api_key firebase_project_id google_application_credentials_path google_application_credentials
|
60
|
+
].each do |attribute|
|
58
61
|
define_method("#{attribute}=") do |value|
|
59
62
|
instance_variable_set(:"@#{attribute}", value)
|
60
63
|
|
@@ -62,10 +65,24 @@ module Modulofcm
|
|
62
65
|
end
|
63
66
|
end
|
64
67
|
|
68
|
+
def google_application_credentials_path
|
69
|
+
if @google_application_credentials_path.present? || @google_application_credentials.blank?
|
70
|
+
return @google_application_credentials_path
|
71
|
+
end
|
72
|
+
|
73
|
+
@google_application_credentials_path = if @google_application_credentials.is_a?(String)
|
74
|
+
FileIO.new(@google_application_credentials, 'creds.json')
|
75
|
+
elsif @google_application_credentials.respond_to?(:to_json)
|
76
|
+
FileIO.new(@google_application_credentials.to_json, 'creds.json')
|
77
|
+
else
|
78
|
+
@google_application_credentials
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
65
82
|
private
|
66
83
|
|
67
84
|
def update_mode
|
68
|
-
api_v1_fields_all_present = [
|
85
|
+
api_v1_fields_all_present = [google_application_credentials_path, firebase_project_id].all?(&:present?)
|
69
86
|
api_key_blank = api_key.blank?
|
70
87
|
|
71
88
|
@mode = if api_v1_fields_all_present || api_key_blank
|
@@ -78,7 +95,7 @@ module Modulofcm
|
|
78
95
|
when :legacy
|
79
96
|
FCM.new(api_key)
|
80
97
|
else
|
81
|
-
FCM.new(
|
98
|
+
FCM.new('', google_application_credentials_path, firebase_project_id)
|
82
99
|
end
|
83
100
|
end
|
84
101
|
|
@@ -98,6 +115,16 @@ module Modulofcm
|
|
98
115
|
handle_data(payload, data)
|
99
116
|
handle_notification(payload, body, sound, title)
|
100
117
|
|
118
|
+
# According to Firebase documentation, all values must be strings. So all hashes/arrays are JSON-ified and other
|
119
|
+
# fields (including numbers) are converted to strings.
|
120
|
+
payload[:data].transform_values! do |value|
|
121
|
+
if value.is_a?(Hash) || value.is_a?(Array)
|
122
|
+
value.to_json
|
123
|
+
else
|
124
|
+
value.to_s
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
101
128
|
make_v1_response(@client.send_v1(payload))
|
102
129
|
end
|
103
130
|
|
@@ -109,10 +136,14 @@ module Modulofcm
|
|
109
136
|
}
|
110
137
|
else
|
111
138
|
{
|
112
|
-
android: {
|
113
|
-
|
114
|
-
|
115
|
-
|
139
|
+
android: {
|
140
|
+
priority: "high"
|
141
|
+
},
|
142
|
+
apns: {
|
143
|
+
payload: {
|
144
|
+
aps: {
|
145
|
+
'content-available' => content_available ? 1 : 0
|
146
|
+
}
|
116
147
|
}
|
117
148
|
}
|
118
149
|
}
|
@@ -143,7 +174,7 @@ module Modulofcm
|
|
143
174
|
when :legacy
|
144
175
|
payload[:notification][:sound] = value
|
145
176
|
else
|
146
|
-
payload[:apns][:aps][:sound] = value
|
177
|
+
payload[:apns][:payload][:aps][:sound] = value
|
147
178
|
payload[:android][:sound] = value
|
148
179
|
end
|
149
180
|
end
|
@@ -155,7 +186,7 @@ module Modulofcm
|
|
155
186
|
def make_v1_response(response)
|
156
187
|
response_body = JSON.parse(response[:body])
|
157
188
|
|
158
|
-
Response.new(success:
|
189
|
+
Response.new(success: response[:response] == 'success',
|
159
190
|
status: response[:status_code], body: response_body)
|
160
191
|
end
|
161
192
|
|
@@ -38,14 +38,14 @@ module Modulofcm
|
|
38
38
|
|
39
39
|
@errors << 'Required field: name' if client.name.blank?
|
40
40
|
|
41
|
-
if [client.google_application_credentials_path, client.
|
41
|
+
if [client.google_application_credentials_path, client.firebase_project_id].all?(&:present?)
|
42
42
|
return [@errors.empty?, @errors]
|
43
43
|
end
|
44
44
|
|
45
45
|
return [@errors.empty?, @errors] if client.api_key.present?
|
46
46
|
|
47
47
|
# rubocop:disable Layout/LineLength
|
48
|
-
@errors << 'Either an API key for Legacy API (deprecated) either the
|
48
|
+
@errors << 'Either an API key for Legacy API (deprecated) either the Google application credentials and the Firebase project id are required'
|
49
49
|
# rubocop:enable Layout/LineLength
|
50
50
|
|
51
51
|
[false, @errors]
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class FileIO < StringIO
|
2
|
+
|
3
|
+
attr_reader :original_filename
|
4
|
+
attr_reader :identifier
|
5
|
+
|
6
|
+
def initialize(stream, filename)
|
7
|
+
super(stream.to_s)
|
8
|
+
@original_filename = filename
|
9
|
+
@filename = filename
|
10
|
+
end
|
11
|
+
|
12
|
+
def read(...)
|
13
|
+
rewind
|
14
|
+
|
15
|
+
super(...)
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
data/lib/modulofcm/response.rb
CHANGED
data/lib/modulofcm/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: modulofcm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthieu Ciappara
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-05-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -61,6 +61,7 @@ files:
|
|
61
61
|
- lib/modulofcm/client.rb
|
62
62
|
- lib/modulofcm/configurator.rb
|
63
63
|
- lib/modulofcm/errors.rb
|
64
|
+
- lib/modulofcm/file_i_o.rb
|
64
65
|
- lib/modulofcm/response.rb
|
65
66
|
- lib/modulofcm/version.rb
|
66
67
|
- modulofcm.gemspec
|
@@ -73,7 +74,7 @@ metadata:
|
|
73
74
|
source_code_uri: https://github.com/moduloTech/modulofcm
|
74
75
|
changelog_uri: https://github.com/moduloTech/modulofcm/blob/master/CHANGELOG.md
|
75
76
|
rubygems_mfa_required: 'true'
|
76
|
-
post_install_message:
|
77
|
+
post_install_message:
|
77
78
|
rdoc_options: []
|
78
79
|
require_paths:
|
79
80
|
- lib
|
@@ -88,8 +89,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
88
89
|
- !ruby/object:Gem::Version
|
89
90
|
version: '0'
|
90
91
|
requirements: []
|
91
|
-
rubygems_version: 3.
|
92
|
-
signing_key:
|
92
|
+
rubygems_version: 3.3.7
|
93
|
+
signing_key:
|
93
94
|
specification_version: 4
|
94
95
|
summary: Firebase Cloud Messaging client library
|
95
96
|
test_files: []
|