hey-you-fcm-push 0.1.1 → 0.3.1
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/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/message_object.rb +1 -1
- data/lib/hey_you_fcm_push/version.rb +1 -1
- metadata +22 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 259c1bf26f492d3cad9f8d45e6bbd7ff2fe666d02439df2cf4dc4be2e8e8c4a5
|
4
|
+
data.tar.gz: d87c689e4f8015bc7b3ba105e8fce174833f5e0b7fd015c16418f0cbcd396490
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3c8bb04bff1801c817287bc13fb77345b1ea3560398296551ea0a16b55e974a29dedfe80069cbc75ce64fa7918231196407df2db8cedb8cf55bdfdcfb1b1e6e0
|
7
|
+
data.tar.gz: f18759556a4dba3a8f720c89e5d9e7523a1f888e3b6e8d3e6cd7109968b070fa655dc52c49918c2770238d07f444531c48405f48e9a8150efbee377e9ca31929
|
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", '>= 1.4'
|
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
|
@@ -34,7 +34,7 @@ module HeyYouFcmPush
|
|
34
34
|
@web_push_config = WebPushConfig.new(options[:webpush].transform_keys(&:to_sym)) if options[:web_push_config]
|
35
35
|
@apns_config = ApnsConfig.new(options[:apns].transform_keys(&:to_sym)) if options[:apns_config]
|
36
36
|
@fcm_options = FcmOptions.new(**options[:fcm_options].transform_keys(&:to_sym)) if options[:fcm_options]
|
37
|
-
@push_data = options[:data]
|
37
|
+
@push_data = { data: options[:data].to_json }
|
38
38
|
end
|
39
39
|
|
40
40
|
def to_h
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.1
|
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
|
@@ -16,42 +16,56 @@ dependencies:
|
|
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
|