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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aed822e33bf25c1e59e030e3d32d4aa45de406535a3993339ae12e43cd27b90c
4
- data.tar.gz: d11416aeea95d06bbaa598a0d3c3c2c61c7912c0361f4e2888c378de9cf7add9
3
+ metadata.gz: d24c2d105f438186df3d49d8e68a7b6b1728476d6ace7c2315d66dc57ebaed21
4
+ data.tar.gz: ef084a4c6de9df4c9461c325b7a22860cf8a79c0332ee5f2f111aeda26daed73
5
5
  SHA512:
6
- metadata.gz: 793828acf069f18159e6ec301327b0cbe21e4e8600c1485931e26b0229e299d7c287e8b275aa0e7e5ca254fab8e5317f5d618f703eea78cc01d8572ebb482e91
7
- data.tar.gz: 8bd496cc69b14561a847e5ae7ce1b198a9d21a98642abec25c11e46863be75b1e8ae5af357c04ec24728d0050178f3f346eeeb7ae553624271cbb7ae5d736393
6
+ metadata.gz: d113132fff3cbb6d65e12267b3c299c96c447dae7e581c7b24b3136789b097213434df2424255e0fee76ec70ce23374dec9474c2f7aa1f4cdad1cc44a570f40c
7
+ data.tar.gz: a58686a6dd3d64ada7595d792b01c6e81a42a490638e560e14690576e93e9d4f00aaa5ba6990d551129ff9e72c87eb50dcbe4270023742d2ef01ec2c170784db
@@ -4,7 +4,7 @@ class CreateJeraPushMessagesDevices < ActiveRecord::Migration<%= migration_versi
4
4
  t.integer :device_id, index: true
5
5
  t.integer :message_id, index: true
6
6
  t.string :status
7
- t.string :error_message
7
+ t.text :error_message
8
8
  t.string :firebase_id
9
9
 
10
10
  t.timestamps
@@ -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
- config.project_name = "YOUR_PROJECT_NAME"
8
- config.credentials_path = "YOUR_CREDENTIALS_PATH" #https://firebase.google.com/docs/cloud-messaging/migrate-v1?hl=pt-br#provide-credentials-manually
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.project_name}", push.to_json, options: { retries: 3, multiplier: 1, max_interval: 2 })
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
@@ -1,3 +1,3 @@
1
1
  module JeraPush
2
- VERSION = "2.1.0"
2
+ VERSION = "2.1.3"
3
3
  end
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.0
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-05-24 00:00:00.000000000 Z
11
+ date: 2024-09-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails