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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/snm/fcm/version.rb +1 -1
  3. data/lib/snm/fcm.rb +20 -12
  4. metadata +21 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 573844bd26a9b3a76646549abc1863ae5bd3851a71091f5dc89323d21b0f7597
4
- data.tar.gz: 31fa08dbb3d1da47c294a9e59f4e6a7150cfadb8a0ef301a135c4d7be1229fcf
3
+ metadata.gz: 3f318677c9145ea5f38ef89b8f7f2aef8a250a4142ef9b9cec6dfa3b7fbd5538
4
+ data.tar.gz: 8fa111b44446f8d77856aa4ed0c8b555f6316ecec5206b945462e916f342d2d0
5
5
  SHA512:
6
- metadata.gz: d909cbe32ee89a731db36247a84a80fea2ce56d2c512ab898c1290ec367de2ae100589b771c93e8897cb9ac1feca42e069c348c8abc0b3bd42715558d6a455f0
7
- data.tar.gz: a885c38e347a532df9b073b702cd8b4e855a3d12e3f8e83696971ed5067187fd4daae075d57877f1c29a8d639fe1a8271d13369991d4d7c116029370c1ba960b
6
+ metadata.gz: ead80d7616c95a5e4ba70516ec6f46444841ef25d3b33ffc66ccc6aff62d50c489a598ca998afde63a818558f6d170164a488b8d7e247b97311145ed0405e69c
7
+ data.tar.gz: 0f2c18f67d83b1305caa8648d771d9b404b4fa0116ab16fb47fcc54b13c32cc60f39e962357f72bea82b577f67f23b72513f1db32b27e4ced57cde5fd0176298
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Snm
4
4
  module Fcm
5
- VERSION = "0.1.0"
5
+ VERSION = "0.1.2"
6
6
  end
7
7
  end
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 :project_id, :access_token
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 token, data={}
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 #{Notification.configuration.access_token}").post("https://fcm.googleapis.com/v1/projects/#{Notification.configuration.project_id}/messages:send", json: data)
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
- def self.get_access_token credentails_file_path
31
- scope = 'https://www.googleapis.com/auth/cloud-platform'
32
- authorizer = Google::Auth::ServiceAccountCredentials.make_creds(
33
- json_key_io: File.open(credentails_file_path),
34
- scope: scope
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.0
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