hey-you-fcm-push 0.1.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/README.md +1 -1
- data/bin/console +1 -1
- data/hey-you-fcm-push.gemspec +4 -3
- data/lib/hey_you/builder/fcm_push.rb +9 -6
- data/lib/hey_you/channels/fcm_push.rb +17 -4
- data/lib/hey_you_fcm_push/connection.rb +4 -2
- data/lib/hey_you_fcm_push/version.rb +1 -1
- metadata +24 -11
- data/Gemfile.lock +0 -89
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2c0257aa8ade1be78f29df6848c00715173d2ae5c78c970a2a09dc1e5e886b2a
|
4
|
+
data.tar.gz: b95b7df61da1e685c59f0053ec009d66c0a077ca17a2eb8b46248b8d280ac8c9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 72eeb800201406306b2ab9364cfb1bdf4e60275af08ff74821d678f57d4e67b504202619bd3a8508ff6dc5ff5ecffafa267d618dbcdf29004859b6512d45f587
|
7
|
+
data.tar.gz: 2141a92b76a82232de92dfa2e313137458d222fc61f0ed1148ead0dbf428a0ef79d580879d7f46d845298794f3f01b4d46964172ff6ee64769b9bd9782d1d43a
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# Hey, You, FCM!
|
2
|
-
[![Build Status](https://travis-ci.com/QNester/hey-you-fcm-push.svg?branch=
|
2
|
+
[![Build Status](https://travis-ci.com/QNester/hey-you-fcm-push.svg?branch=main)](https://travis-ci.com/QNester/hey-you-fcm-push#)[![Gem Version](https://badge.fury.io/rb/hey-you-fcm-push.svg)](https://badge.fury.io/rb/hey-you-fcm-push)
|
3
3
|
|
4
4
|
Send fcm pushes via [hey-you gem](https://github.com/QNester/hey-you) using [google fcm protocol](https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages/send)
|
5
5
|
|
data/bin/console
CHANGED
data/hey-you-fcm-push.gemspec
CHANGED
@@ -26,9 +26,10 @@ Gem::Specification.new do |spec|
|
|
26
26
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
27
|
spec.require_paths = ["lib"]
|
28
28
|
|
29
|
-
spec.add_runtime_dependency "hey-you", '
|
30
|
-
spec.add_runtime_dependency "googleauth", '~> 0.
|
31
|
-
spec.add_runtime_dependency "httparty", '~> 0.18
|
29
|
+
spec.add_runtime_dependency "hey-you", '>= 1.4.2'
|
30
|
+
spec.add_runtime_dependency "googleauth", '~> 0.14'
|
31
|
+
spec.add_runtime_dependency "httparty", '~> 0.18'
|
32
|
+
spec.add_runtime_dependency "activesupport", '>= 5'
|
32
33
|
|
33
34
|
spec.add_development_dependency "rake", "~> 13.0"
|
34
35
|
spec.add_development_dependency "rspec", "~> 3.0"
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'hey_you_fcm_push/message_object'
|
2
|
+
require 'active_support/core_ext/object/deep_dup'
|
2
3
|
|
3
4
|
module HeyYou
|
4
5
|
class Builder
|
@@ -12,15 +13,17 @@ module HeyYou
|
|
12
13
|
@condition = ch_data.fetch('condition', nil)
|
13
14
|
@name = ch_data.fetch('name', nil)
|
14
15
|
|
15
|
-
@notification = interpolate_notification(ch_data.fetch('notification', nil))
|
16
|
+
@notification = interpolate_notification(ch_data.fetch('notification', nil)&.deep_dup)
|
16
17
|
|
17
|
-
@android = interpolate_notification(ch_data.fetch('android', nil))
|
18
|
-
@webpush = interpolate_notification(ch_data.fetch('webpush', nil))
|
19
|
-
@apns = interpolate_notification(ch_data.fetch('apns', nil))
|
20
|
-
@fcm_options = interpolate_notification(ch_data.fetch('fcm_options', nil))
|
21
|
-
@push_data = ch_data.fetch('push_data', nil)
|
18
|
+
@android = interpolate_notification(ch_data.fetch('android', nil)&.deep_dup)
|
19
|
+
@webpush = interpolate_notification(ch_data.fetch('webpush', nil)&.deep_dup)
|
20
|
+
@apns = interpolate_notification(ch_data.fetch('apns', nil)&.deep_dup)
|
21
|
+
@fcm_options = interpolate_notification(ch_data.fetch('fcm_options', nil)&.deep_dup)
|
22
|
+
@push_data = ch_data.fetch('push_data', nil)&.deep_dup
|
22
23
|
end
|
23
24
|
|
25
|
+
private
|
26
|
+
|
24
27
|
def interpolate_notification(data)
|
25
28
|
return unless data
|
26
29
|
|
@@ -10,6 +10,7 @@ module HeyYou
|
|
10
10
|
# @param [HeyYou::Builder] builder - builder with notifications texts and settings
|
11
11
|
# @option [String] name - Output Only. The identifier of the message sent
|
12
12
|
# @option [String] token - Registration token to send a message to.
|
13
|
+
# @option [String] to - Alias for `token`. `token` in high priority.
|
13
14
|
# @option [String] topic - Topic name to send a message to, e.g. "weather".
|
14
15
|
# @option [String] condition - Condition to send a message to, e.g. "'foo' in topics && 'bar' in topics".
|
15
16
|
# @option [Hash] notification - Basic notification template to use across all platforms.
|
@@ -19,12 +20,24 @@ module HeyYou
|
|
19
20
|
# @option [Hash] fcm_options - Platform independent options for features provided by the FCM SDKs.
|
20
21
|
# @option [Hash] push_data - Input only. Arbitrary key/value payload. The key should not be a reserved word ("from", "message_type", or any word starting with "google" or "gcm").
|
21
22
|
#
|
22
|
-
# @return [Hash] - FCM
|
23
|
+
# @return [Array{Hash}] - FCM responses
|
23
24
|
#
|
24
25
|
# @see: https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages#resource:-message
|
25
26
|
def send!(builder, **options)
|
26
|
-
|
27
|
-
|
27
|
+
options[:token] ||= options[:to]
|
28
|
+
|
29
|
+
if options[:token].is_a?(Array)
|
30
|
+
messages = options[:token].map { |token| build_message(builder, **options.merge(token: token)) }
|
31
|
+
end
|
32
|
+
|
33
|
+
messages ||= [build_message(builder, **options)]
|
34
|
+
|
35
|
+
messages.map do |message|
|
36
|
+
{
|
37
|
+
receiver: message.receiver_hash,
|
38
|
+
response: HeyYouFcmPush::Connection.instance.send_notification(message.to_h, validate_only: options[:validate_only])
|
39
|
+
}
|
40
|
+
end
|
28
41
|
end
|
29
42
|
|
30
43
|
private
|
@@ -41,7 +54,7 @@ module HeyYou
|
|
41
54
|
apns: options[:apns] || builder.fcm_push.apns,
|
42
55
|
fcm_options: options[:fcm_options]|| builder.fcm_push.fcm_options,
|
43
56
|
data: options[:push_data] || builder.fcm_push.push_data
|
44
|
-
)
|
57
|
+
)
|
45
58
|
end
|
46
59
|
end
|
47
60
|
end
|
@@ -10,7 +10,7 @@ module HeyYouFcmPush
|
|
10
10
|
RETRY_COUNT = 1
|
11
11
|
HTTP_CODES = {
|
12
12
|
not_auth: 401,
|
13
|
-
|
13
|
+
server_error: 500
|
14
14
|
}
|
15
15
|
|
16
16
|
attr_reader :authorization, :options, :project_id, :uri
|
@@ -44,13 +44,15 @@ module HeyYouFcmPush
|
|
44
44
|
private
|
45
45
|
|
46
46
|
def make_request(request_options)
|
47
|
+
HeyYou::Config.instance.logger&.debug("Send request to #{uri} with options #{request_options}")
|
47
48
|
response = HTTParty.post(uri, request_options)
|
49
|
+
HeyYou::Config.instance.logger&.debug("Response: #{response}")
|
48
50
|
process_response(response)
|
49
51
|
end
|
50
52
|
|
51
53
|
def process_response(response)
|
52
54
|
raise AuthError if response.code == HTTP_CODES[:not_auth]
|
53
|
-
return response.to_hash if response.code
|
55
|
+
return response.to_hash if response.code <= HTTP_CODES[:server_error]
|
54
56
|
|
55
57
|
raise ResponseError, "response code: #{response.code}"
|
56
58
|
end
|
metadata
CHANGED
@@ -1,57 +1,71 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hey-you-fcm-push
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sergey Nesterov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-02-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hey-you
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 1.4.2
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 1.4.2
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: googleauth
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.
|
33
|
+
version: '0.14'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0.
|
40
|
+
version: '0.14'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: httparty
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 0.18
|
47
|
+
version: '0.18'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 0.18
|
54
|
+
version: '0.18'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: activesupport
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '5'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '5'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: rake
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -121,7 +135,6 @@ files:
|
|
121
135
|
- ".travis.yml"
|
122
136
|
- CHANGELOG.md
|
123
137
|
- Gemfile
|
124
|
-
- Gemfile.lock
|
125
138
|
- Makefile
|
126
139
|
- README.md
|
127
140
|
- Rakefile
|
data/Gemfile.lock
DELETED
@@ -1,89 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
hey-you-fcm-push (0.1.0)
|
5
|
-
googleauth (~> 0.10.0)
|
6
|
-
hey-you (~> 1.4)
|
7
|
-
httparty (~> 0.18.0)
|
8
|
-
|
9
|
-
GEM
|
10
|
-
remote: https://rubygems.org/
|
11
|
-
specs:
|
12
|
-
addressable (2.7.0)
|
13
|
-
public_suffix (>= 2.0.2, < 5.0)
|
14
|
-
byebug (11.1.3)
|
15
|
-
concurrent-ruby (1.1.7)
|
16
|
-
crack (0.4.4)
|
17
|
-
diff-lcs (1.4.4)
|
18
|
-
faraday (0.17.3)
|
19
|
-
multipart-post (>= 1.2, < 3)
|
20
|
-
fcm (0.0.6)
|
21
|
-
httparty (~> 0.10, >= 0.10.0)
|
22
|
-
ffaker (2.17.0)
|
23
|
-
googleauth (0.10.0)
|
24
|
-
faraday (~> 0.12)
|
25
|
-
jwt (>= 1.4, < 3.0)
|
26
|
-
memoist (~> 0.16)
|
27
|
-
multi_json (~> 1.11)
|
28
|
-
os (>= 0.9, < 2.0)
|
29
|
-
signet (~> 0.12)
|
30
|
-
hashdiff (1.0.1)
|
31
|
-
hey-you (1.4.0)
|
32
|
-
fcm (~> 0.0.2)
|
33
|
-
i18n (~> 1.0)
|
34
|
-
mail (~> 2.7)
|
35
|
-
httparty (0.18.1)
|
36
|
-
mime-types (~> 3.0)
|
37
|
-
multi_xml (>= 0.5.2)
|
38
|
-
i18n (1.8.5)
|
39
|
-
concurrent-ruby (~> 1.0)
|
40
|
-
jwt (2.2.2)
|
41
|
-
mail (2.7.1)
|
42
|
-
mini_mime (>= 0.1.1)
|
43
|
-
memoist (0.16.2)
|
44
|
-
mime-types (3.3.1)
|
45
|
-
mime-types-data (~> 3.2015)
|
46
|
-
mime-types-data (3.2020.1104)
|
47
|
-
mini_mime (1.0.2)
|
48
|
-
multi_json (1.15.0)
|
49
|
-
multi_xml (0.6.0)
|
50
|
-
multipart-post (2.1.1)
|
51
|
-
os (1.1.1)
|
52
|
-
public_suffix (4.0.6)
|
53
|
-
rake (13.0.3)
|
54
|
-
rspec (3.10.0)
|
55
|
-
rspec-core (~> 3.10.0)
|
56
|
-
rspec-expectations (~> 3.10.0)
|
57
|
-
rspec-mocks (~> 3.10.0)
|
58
|
-
rspec-core (3.10.0)
|
59
|
-
rspec-support (~> 3.10.0)
|
60
|
-
rspec-expectations (3.10.0)
|
61
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
62
|
-
rspec-support (~> 3.10.0)
|
63
|
-
rspec-mocks (3.10.0)
|
64
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
65
|
-
rspec-support (~> 3.10.0)
|
66
|
-
rspec-support (3.10.0)
|
67
|
-
signet (0.14.0)
|
68
|
-
addressable (~> 2.3)
|
69
|
-
faraday (>= 0.17.3, < 2.0)
|
70
|
-
jwt (>= 1.5, < 3.0)
|
71
|
-
multi_json (~> 1.10)
|
72
|
-
webmock (3.11.0)
|
73
|
-
addressable (>= 2.3.6)
|
74
|
-
crack (>= 0.3.2)
|
75
|
-
hashdiff (>= 0.4.0, < 2.0.0)
|
76
|
-
|
77
|
-
PLATFORMS
|
78
|
-
ruby
|
79
|
-
|
80
|
-
DEPENDENCIES
|
81
|
-
byebug
|
82
|
-
ffaker (~> 2.15)
|
83
|
-
hey-you-fcm-push!
|
84
|
-
rake (~> 13.0)
|
85
|
-
rspec (~> 3.0)
|
86
|
-
webmock (~> 3.4)
|
87
|
-
|
88
|
-
BUNDLED WITH
|
89
|
-
2.1.4
|