snm-fcm 0.1.0 → 0.1.3
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/lib/snm/fcm/version.rb +1 -1
- data/lib/snm/fcm.rb +24 -15
- metadata +21 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d84858414150e1f38a1feb48aaa131fc59d282b26669830adadbec5fc89493e9
|
4
|
+
data.tar.gz: 957bdb675a7540a9a38fc036186edf73e6c1ce0885e7c712c490adf35c783c2e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a8facdd1a526d7da68a514bf912ef2cf908c9b53cc58a8bfe6fa2d00c77adf780562ff4541fc1b6ede76904a00c66a302fb583125c9b7f2809c0aab5714ebaae
|
7
|
+
data.tar.gz: a8685c4b424486b78aa754c19bf57089cbac98650f4791ddde635060e1c81228ec635f387fa52db93f8029f85991bfea718efd9cd520024ad75c103ce3262318
|
data/lib/snm/fcm/version.rb
CHANGED
data/lib/snm/fcm.rb
CHANGED
@@ -2,13 +2,15 @@
|
|
2
2
|
|
3
3
|
require_relative "fcm/version"
|
4
4
|
require 'googleauth'
|
5
|
+
require 'http'
|
6
|
+
require 'json'
|
5
7
|
|
6
8
|
module Snm
|
7
9
|
module Fcm
|
8
10
|
class Error < StandardError; end
|
9
11
|
|
10
12
|
class Configuration
|
11
|
-
attr_accessor :
|
13
|
+
attr_accessor :credentails_file_path, :project_id
|
12
14
|
end
|
13
15
|
|
14
16
|
class Notification
|
@@ -16,24 +18,31 @@ module Snm
|
|
16
18
|
@configuration ||= Configuration.new
|
17
19
|
end
|
18
20
|
|
19
|
-
def self.
|
20
|
-
|
21
|
+
def self.setup(&block)
|
22
|
+
yield(configuration)
|
21
23
|
end
|
22
24
|
|
23
|
-
def self.deliver
|
24
|
-
raise '
|
25
|
-
|
26
|
-
HTTP.headers(
|
25
|
+
def self.deliver data={}
|
26
|
+
raise 'Data is missing' if data.nil?
|
27
|
+
|
28
|
+
HTTP.headers("Content-Type"=> "application/json", "Authorization"=> "Bearer #{get_access_token}").post("https://fcm.googleapis.com/v1/projects/#{Notification.configuration.project_id}/messages:send", json: data)
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.get_access_token
|
32
|
+
scope = 'https://www.googleapis.com/auth/cloud-platform'
|
33
|
+
authorizer = Google::Auth::ServiceAccountCredentials.make_creds(
|
34
|
+
json_key_io: File.open(Notification.configuration.credentails_file_path),
|
35
|
+
scope: scope
|
36
|
+
)
|
37
|
+
authorizer.fetch_access_token!['access_token']
|
27
38
|
end
|
28
|
-
end
|
29
39
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
)
|
36
|
-
authorizer.fetch_access_token!['access_token']
|
40
|
+
def self.set_project
|
41
|
+
file = File.read(Notification.configuration.credentails_file_path)
|
42
|
+
data_hash = JSON.parse(file)
|
43
|
+
Notification.configuration.project_id = data_hash["project_id"]
|
44
|
+
end
|
37
45
|
end
|
46
|
+
|
38
47
|
end
|
39
48
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: snm-fcm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- snmmaurya
|
@@ -38,6 +38,26 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '1.11'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: json
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.7'
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: 2.7.2
|
51
|
+
type: :runtime
|
52
|
+
prerelease: false
|
53
|
+
version_requirements: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - "~>"
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '2.7'
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 2.7.2
|
41
61
|
description: ''
|
42
62
|
email:
|
43
63
|
- snmspace@gmail.com
|