jera_push 2.1.0 → 2.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/generators/active_record/templates/create_jera_push_messages_devices.rb +1 -1
- data/lib/generators/jera_push/templates/jera_push.rb +3 -3
- data/lib/jera_push/firebase/client.rb +1 -39
- data/lib/jera_push/models/push_body.rb +1 -1
- data/lib/jera_push/version.rb +1 -1
- data/lib/jera_push.rb +0 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d24c2d105f438186df3d49d8e68a7b6b1728476d6ace7c2315d66dc57ebaed21
|
4
|
+
data.tar.gz: ef084a4c6de9df4c9461c325b7a22860cf8a79c0332ee5f2f111aeda26daed73
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d113132fff3cbb6d65e12267b3c299c96c447dae7e581c7b24b3136789b097213434df2424255e0fee76ec70ce23374dec9474c2f7aa1f4cdad1cc44a570f40c
|
7
|
+
data.tar.gz: a58686a6dd3d64ada7595d792b01c6e81a42a490638e560e14690576e93e9d4f00aaa5ba6990d551129ff9e72c87eb50dcbe4270023742d2ef01ec2c170784db
|
@@ -1,11 +1,11 @@
|
|
1
1
|
#this is the intilizer
|
2
2
|
#here you will set up the jera push configuration
|
3
3
|
JeraPush.setup do |config|
|
4
|
-
config.firebase_api_key = "YOUR_API_KEY"
|
5
4
|
# Change this for every new model
|
6
5
|
config.resources_name = ["<%= file_name.classify %>"]
|
7
|
-
|
8
|
-
config.
|
6
|
+
# You need to create a Account Service on google cloud, with editor permission or administrator. Flow this doc: https://cloud.google.com/iam/docs/service-accounts-create?hl=pt-br
|
7
|
+
config.project_id = "YOUR_PROJECT_ID" # inside of the account service json
|
8
|
+
config.credentials_path = Rails.root.join("YOUR_CREDENTIALS_NAME").to_path #https://firebase.google.com/docs/cloud-messaging/migrate-v1?hl=pt-br#provide-credentials-manually
|
9
9
|
######################################################
|
10
10
|
# Resource attribute showed in views #
|
11
11
|
# IMPORTANT: All models need to have this attributes #
|
@@ -14,53 +14,15 @@ module JeraPush::Firebase
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def send_to_device(push:)
|
17
|
-
@client.send_message("projects/#{::JeraPush.
|
18
|
-
end
|
19
|
-
|
20
|
-
def add_device_to_topic(topic:, device:)
|
21
|
-
send(url: "#{FIREBASE_INSTANCE_ID_URL}/v1/#{device.token}/rel/topics/#{topic}")
|
22
|
-
end
|
23
|
-
|
24
|
-
def remove_device_from_topic(topic:, devices: [])
|
25
|
-
send(
|
26
|
-
url: "#{FIREBASE_INSTANCE_ID_URL}/v1:batchRemove",
|
27
|
-
body: {
|
28
|
-
to: "/topics/#{topic}",
|
29
|
-
registration_tokens: devices.pluck(:token)
|
30
|
-
}.to_json
|
31
|
-
)
|
32
|
-
end
|
33
|
-
|
34
|
-
def send_message_to_topic(message:, topic:)
|
35
|
-
send(
|
36
|
-
url: FIREBASE_URL,
|
37
|
-
body: {
|
38
|
-
title: message.title,
|
39
|
-
body: message.body,
|
40
|
-
to: "/topics/#{topic}",
|
41
|
-
priority: 'high'
|
42
|
-
}.to_json
|
43
|
-
)
|
17
|
+
@client.send_message("projects/#{::JeraPush.project_id}", push.to_json, options: { retries: 3, multiplier: 1, max_interval: 2 })
|
44
18
|
end
|
45
19
|
|
46
20
|
private
|
47
21
|
|
48
|
-
def send(url:, body: {})
|
49
|
-
response = HTTParty.post(url, { body: body, headers: default_headers })
|
50
|
-
JSON.parse(response)
|
51
|
-
end
|
52
|
-
|
53
22
|
def fetch_access_token
|
54
23
|
@authorizer.fetch_access_token! if @authorizer.needs_access_token?
|
55
24
|
|
56
25
|
@authorizer
|
57
26
|
end
|
58
|
-
|
59
|
-
def default_headers
|
60
|
-
{
|
61
|
-
"Authorization" => "key=#{::JeraPush.firebase_api_key}",
|
62
|
-
"Content-Type" => "application/json"
|
63
|
-
}
|
64
|
-
end
|
65
27
|
end
|
66
28
|
end
|
@@ -26,7 +26,7 @@ module JeraPush
|
|
26
26
|
self.device = device
|
27
27
|
self.devices = devices
|
28
28
|
self.validate_only = validate_only
|
29
|
-
self.analytics_label = analytics_label
|
29
|
+
self.analytics_label = analytics_label.gsub(/\s/, '_').gsub(/[^a-zA-Z0-9.~%_]/, '').slice(0, 50).downcase
|
30
30
|
self.ios = ios_config
|
31
31
|
self.notification = notification.nil? ? Notification.new(title: title, body: body, image: image) : notification
|
32
32
|
self.android = android_config
|
data/lib/jera_push/version.rb
CHANGED
data/lib/jera_push.rb
CHANGED
@@ -27,12 +27,6 @@ module JeraPush
|
|
27
27
|
autoload :AndroidConfig, 'jera_push/models/android_config.rb'
|
28
28
|
autoload :Notification, 'jera_push/models/notification.rb'
|
29
29
|
|
30
|
-
mattr_accessor :firebase_api_key
|
31
|
-
@@firebase_api_key = nil
|
32
|
-
|
33
|
-
mattr_accessor :project_name
|
34
|
-
@@project_name = nil
|
35
|
-
|
36
30
|
mattr_accessor :project_id
|
37
31
|
@@project_id = nil
|
38
32
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jera_push
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1.
|
4
|
+
version: 2.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jera
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-09-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|