snm-fcm 0.1.0 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/snm/fcm/version.rb +1 -1
- data/lib/snm/fcm.rb +20 -12
- 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: 3f318677c9145ea5f38ef89b8f7f2aef8a250a4142ef9b9cec6dfa3b7fbd5538
|
4
|
+
data.tar.gz: 8fa111b44446f8d77856aa4ed0c8b555f6316ecec5206b945462e916f342d2d0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ead80d7616c95a5e4ba70516ec6f46444841ef25d3b33ffc66ccc6aff62d50c489a598ca998afde63a818558f6d170164a488b8d7e247b97311145ed0405e69c
|
7
|
+
data.tar.gz: 0f2c18f67d83b1305caa8648d771d9b404b4fa0116ab16fb47fcc54b13c32cc60f39e962357f72bea82b577f67f23b72513f1db32b27e4ced57cde5fd0176298
|
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
|
@@ -20,20 +22,26 @@ module Snm
|
|
20
22
|
@configuration = yield(configuration)
|
21
23
|
end
|
22
24
|
|
23
|
-
def self.deliver
|
24
|
-
raise 'Token is missing' if not token.present?
|
25
|
+
def self.deliver data={}
|
25
26
|
raise 'Data is missing' if not data.present?
|
26
|
-
HTTP.headers('Content-Type: application/json', "Authorization: Bearer #{
|
27
|
+
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)
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.get_access_token
|
31
|
+
scope = 'https://www.googleapis.com/auth/cloud-platform'
|
32
|
+
authorizer = Google::Auth::ServiceAccountCredentials.make_creds(
|
33
|
+
json_key_io: File.open(Notification.configuration.credentails_file_path),
|
34
|
+
scope: scope
|
35
|
+
)
|
36
|
+
authorizer.fetch_access_token!['access_token']
|
27
37
|
end
|
28
|
-
end
|
29
38
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
)
|
36
|
-
authorizer.fetch_access_token!['access_token']
|
39
|
+
def self.set_project
|
40
|
+
file = File.read(Notification.configuration.credentails_file_path)
|
41
|
+
data_hash = JSON.parse(file)
|
42
|
+
Notification.configuration.project_id = data_hash["project_id"]
|
43
|
+
end
|
37
44
|
end
|
45
|
+
|
38
46
|
end
|
39
47
|
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.2
|
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
|