fcmpush 1.2.1 → 1.5.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/fcmpush.gemspec +3 -3
- data/lib/fcmpush/client.rb +35 -9
- data/lib/fcmpush/configuration.rb +15 -1
- data/lib/fcmpush/exceptions.rb +1 -0
- data/lib/fcmpush/version.rb +1 -1
- metadata +12 -16
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a437176b9b06e22c8ccbfc7caed5603ff2fc331111c22dbfc585dceb782ab6f2
|
|
4
|
+
data.tar.gz: 250617403b4caa35cda5395fca5daef64649dd428e20c5f1e619561984bf8ef8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5628699a3505d7dbc67c7b62fd90b15db6177f97dec2e1f979b4c6bb79b41496104af8325db819b3b83a354a3dec120d5e965b5eee7f5be5a945bba2da652923
|
|
7
|
+
data.tar.gz: 4cdbbde0ea2649e681756c9b66671cc60dfff34b062886dd22a01af8b39284a4ce202916f393aa3c92e64939f1302c31fd3ec002aa5c967fd7963e99b181f189
|
data/fcmpush.gemspec
CHANGED
|
@@ -22,10 +22,10 @@ Gem::Specification.new do |spec|
|
|
|
22
22
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
23
23
|
spec.require_paths = ['lib']
|
|
24
24
|
|
|
25
|
-
spec.required_ruby_version = '>= 2.
|
|
25
|
+
spec.required_ruby_version = '>= 2.6', '< 3.5'
|
|
26
26
|
|
|
27
|
-
spec.add_dependency '
|
|
28
|
-
spec.add_dependency 'net-http-persistent', '
|
|
27
|
+
spec.add_dependency 'google-apis-identitytoolkit_v3'
|
|
28
|
+
spec.add_dependency 'net-http-persistent', '~> 4.0.1'
|
|
29
29
|
|
|
30
30
|
spec.add_development_dependency 'bundler', '~> 2.0'
|
|
31
31
|
spec.add_development_dependency 'rake', '~> 13'
|
data/lib/fcmpush/client.rb
CHANGED
|
@@ -23,8 +23,25 @@ module Fcmpush
|
|
|
23
23
|
access_token_response = v1_authorize
|
|
24
24
|
@access_token = access_token_response['access_token']
|
|
25
25
|
@access_token_expiry = Time.now.utc + access_token_response['expires_in']
|
|
26
|
-
@server_key = configuration.server_key
|
|
26
|
+
# @server_key = configuration.server_key
|
|
27
27
|
@connection = Net::HTTP::Persistent.new
|
|
28
|
+
|
|
29
|
+
@connection.open_timeout = configuration.open_timeout if configuration.open_timeout
|
|
30
|
+
@connection.read_timeout = configuration.read_timeout if configuration.read_timeout
|
|
31
|
+
|
|
32
|
+
if !configuration.proxy
|
|
33
|
+
# do nothing
|
|
34
|
+
elsif configuration.proxy == :ENV
|
|
35
|
+
@connection.proxy = :ENV
|
|
36
|
+
elsif configuration.proxy && configuration.proxy[:uri]
|
|
37
|
+
uri = URI(configuration.proxy[:uri])
|
|
38
|
+
# user name must not be a empty string, password can
|
|
39
|
+
if configuration.proxy[:user] && configuration.proxy[:user].strip != ''
|
|
40
|
+
uri.user = configuration.proxy[:user]
|
|
41
|
+
uri.password = configuration.proxy[:password] if configuration.proxy[:password]
|
|
42
|
+
end
|
|
43
|
+
@connection.proxy = uri
|
|
44
|
+
end
|
|
28
45
|
end
|
|
29
46
|
|
|
30
47
|
def v1_authorize
|
|
@@ -34,6 +51,7 @@ module Fcmpush
|
|
|
34
51
|
else
|
|
35
52
|
File.open(configuration.json_key_io)
|
|
36
53
|
end
|
|
54
|
+
io.rewind if io.respond_to?(:read)
|
|
37
55
|
Google::Auth::ServiceAccountCredentials.make_creds(
|
|
38
56
|
json_key_io: io,
|
|
39
57
|
scope: configuration.scope
|
|
@@ -69,12 +87,15 @@ module Fcmpush
|
|
|
69
87
|
raise NetworkError, "A network error occurred: #{e.class} (#{e.message})"
|
|
70
88
|
end
|
|
71
89
|
|
|
90
|
+
#-------------------------------------------------------------------------------
|
|
91
|
+
# BATCH REQUESTS DEPRECATED BY GOOGLE ON June 20,2023 AND SHUTDOWN ON June 21, 2024
|
|
92
|
+
# https://firebase.google.com/support/faq/#fcm-depr-features
|
|
93
|
+
#
|
|
94
|
+
# Until upgrading to use HTTP/2, warning and throwing error
|
|
95
|
+
#-------------------------------------------------------------------------------
|
|
72
96
|
def batch_push(messages, query: {}, headers: {})
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
BatchResponse.new(response)
|
|
76
|
-
rescue Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError => e
|
|
77
|
-
raise NetworkError, "A network error occurred: #{e.class} (#{e.message})"
|
|
97
|
+
warn '[DEPRECATION] `batch_push` is deprecated. Please use `push` for each message instead.'
|
|
98
|
+
raise DeprecatedApiError, 'BATCH REQUESTS DEPRECATED BY GOOGLE ON June 20,2023 AND SHUTDOWN ON June 21, 2024 (https://firebase.google.com/support/faq/#fcm-depr-features)'
|
|
78
99
|
end
|
|
79
100
|
|
|
80
101
|
private
|
|
@@ -97,7 +118,10 @@ module Fcmpush
|
|
|
97
118
|
uri = URI.join(TOPIC_DOMAIN, TOPIC_ENDPOINT_PREFIX + suffix)
|
|
98
119
|
uri.query = URI.encode_www_form(query) unless query.empty?
|
|
99
120
|
|
|
100
|
-
headers =
|
|
121
|
+
headers = v1_authorized_header(headers)
|
|
122
|
+
# cf. https://takanamito.hateblo.jp/entry/2020/07/04/175045
|
|
123
|
+
# cf. https://github.com/miyataka/fcmpush/issues/40
|
|
124
|
+
headers['access_token_auth'] = 'true'
|
|
101
125
|
post = Net::HTTP::Post.new(uri, headers)
|
|
102
126
|
post.body = make_subscription_body(topic, *instance_ids)
|
|
103
127
|
|
|
@@ -118,15 +142,17 @@ module Fcmpush
|
|
|
118
142
|
'Authorization' => "Bearer #{access_token}")
|
|
119
143
|
end
|
|
120
144
|
|
|
145
|
+
# @deprecated TODO: remove this method next version
|
|
121
146
|
def legacy_authorized_header(headers)
|
|
147
|
+
warn "[DEPRECATION] `legacy_authorized_header` is deprecated. Please use `v1_authorized_header` instead."
|
|
122
148
|
headers.merge('Content-Type' => 'application/json',
|
|
123
149
|
'Accept' => 'application/json',
|
|
124
|
-
'Authorization' => "Bearer
|
|
150
|
+
'Authorization' => "Bearer #{server_key}")
|
|
125
151
|
end
|
|
126
152
|
|
|
127
153
|
def exception_handler(response)
|
|
128
154
|
error = STATUS_TO_EXCEPTION_MAPPING[response.code]
|
|
129
|
-
raise error.new("
|
|
155
|
+
raise error.new("Received an error response #{response.code} #{error.to_s.split('::').last}: #{response.body}", response) if error
|
|
130
156
|
|
|
131
157
|
response
|
|
132
158
|
end
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
module Fcmpush
|
|
2
2
|
class Configuration
|
|
3
|
-
attr_accessor :scope, :json_key_io, :server_key
|
|
3
|
+
attr_accessor :scope, :json_key_io, :server_key, :proxy, :open_timeout, :read_timeout
|
|
4
4
|
|
|
5
5
|
def initialize
|
|
6
6
|
@scope = ['https://www.googleapis.com/auth/firebase.messaging']
|
|
@@ -15,7 +15,21 @@ module Fcmpush
|
|
|
15
15
|
# ENV['GOOGLE_PRIVATE_KEY'] = '-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n'
|
|
16
16
|
|
|
17
17
|
# regacy auth
|
|
18
|
+
# @deprecated TODO: remove this next version
|
|
18
19
|
@server_key = ENV['FCM_SERVER_KEY']
|
|
20
|
+
if @server_key
|
|
21
|
+
warn '[DEPRECATION] `FCM_SERVER_KEY` environment variable, also @server_key is deprecated. This attribute will be removed next version.'
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# THIS IS EXPERIMENTAL
|
|
25
|
+
# NOT support `HTTPS_PROXY` environment variable. This feature not tested well on CI.
|
|
26
|
+
# cf. https://github.com/miyataka/fcmpush/pull/39#issuecomment-1722533622
|
|
27
|
+
# proxy
|
|
28
|
+
@proxy = :ENV
|
|
29
|
+
|
|
30
|
+
# connection timeouts
|
|
31
|
+
@open_timeout = nil
|
|
32
|
+
@read_timeout = nil
|
|
19
33
|
end
|
|
20
34
|
end
|
|
21
35
|
end
|
data/lib/fcmpush/exceptions.rb
CHANGED
data/lib/fcmpush/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,43 +1,42 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: fcmpush
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.5.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- miyataka
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: exe
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 2025-01-05 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
|
-
name:
|
|
13
|
+
name: google-apis-identitytoolkit_v3
|
|
15
14
|
requirement: !ruby/object:Gem::Requirement
|
|
16
15
|
requirements:
|
|
17
16
|
- - ">="
|
|
18
17
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: 0
|
|
18
|
+
version: '0'
|
|
20
19
|
type: :runtime
|
|
21
20
|
prerelease: false
|
|
22
21
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
22
|
requirements:
|
|
24
23
|
- - ">="
|
|
25
24
|
- !ruby/object:Gem::Version
|
|
26
|
-
version: 0
|
|
25
|
+
version: '0'
|
|
27
26
|
- !ruby/object:Gem::Dependency
|
|
28
27
|
name: net-http-persistent
|
|
29
28
|
requirement: !ruby/object:Gem::Requirement
|
|
30
29
|
requirements:
|
|
31
|
-
- - "
|
|
30
|
+
- - "~>"
|
|
32
31
|
- !ruby/object:Gem::Version
|
|
33
|
-
version:
|
|
32
|
+
version: 4.0.1
|
|
34
33
|
type: :runtime
|
|
35
34
|
prerelease: false
|
|
36
35
|
version_requirements: !ruby/object:Gem::Requirement
|
|
37
36
|
requirements:
|
|
38
|
-
- - "
|
|
37
|
+
- - "~>"
|
|
39
38
|
- !ruby/object:Gem::Version
|
|
40
|
-
version:
|
|
39
|
+
version: 4.0.1
|
|
41
40
|
- !ruby/object:Gem::Dependency
|
|
42
41
|
name: bundler
|
|
43
42
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -80,7 +79,6 @@ dependencies:
|
|
|
80
79
|
- - "~>"
|
|
81
80
|
- !ruby/object:Gem::Version
|
|
82
81
|
version: '3.0'
|
|
83
|
-
description:
|
|
84
82
|
email:
|
|
85
83
|
- voyager.3taka28@gmail.com
|
|
86
84
|
executables: []
|
|
@@ -102,7 +100,6 @@ licenses:
|
|
|
102
100
|
metadata:
|
|
103
101
|
homepage_uri: https://github.com/miyataka/fcmpush
|
|
104
102
|
source_code_uri: https://github.com/miyataka/fcmpush
|
|
105
|
-
post_install_message:
|
|
106
103
|
rdoc_options: []
|
|
107
104
|
require_paths:
|
|
108
105
|
- lib
|
|
@@ -110,18 +107,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
110
107
|
requirements:
|
|
111
108
|
- - ">="
|
|
112
109
|
- !ruby/object:Gem::Version
|
|
113
|
-
version: '2.
|
|
110
|
+
version: '2.6'
|
|
114
111
|
- - "<"
|
|
115
112
|
- !ruby/object:Gem::Version
|
|
116
|
-
version: '
|
|
113
|
+
version: '3.5'
|
|
117
114
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
118
115
|
requirements:
|
|
119
116
|
- - ">="
|
|
120
117
|
- !ruby/object:Gem::Version
|
|
121
118
|
version: '0'
|
|
122
119
|
requirements: []
|
|
123
|
-
rubygems_version: 3.
|
|
124
|
-
signing_key:
|
|
120
|
+
rubygems_version: 3.6.2
|
|
125
121
|
specification_version: 4
|
|
126
122
|
summary: Firebase Cloud Messaging API wrapper for ruby, supports HTTP v1. And including
|
|
127
123
|
access_token Auto Refresh feature!
|