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.
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 +24 -15
  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: d84858414150e1f38a1feb48aaa131fc59d282b26669830adadbec5fc89493e9
4
+ data.tar.gz: 957bdb675a7540a9a38fc036186edf73e6c1ce0885e7c712c490adf35c783c2e
5
5
  SHA512:
6
- metadata.gz: d909cbe32ee89a731db36247a84a80fea2ce56d2c512ab898c1290ec367de2ae100589b771c93e8897cb9ac1feca42e069c348c8abc0b3bd42715558d6a455f0
7
- data.tar.gz: a885c38e347a532df9b073b702cd8b4e855a3d12e3f8e83696971ed5067187fd4daae075d57877f1c29a8d639fe1a8271d13369991d4d7c116029370c1ba960b
6
+ metadata.gz: a8facdd1a526d7da68a514bf912ef2cf908c9b53cc58a8bfe6fa2d00c77adf780562ff4541fc1b6ede76904a00c66a302fb583125c9b7f2809c0aab5714ebaae
7
+ data.tar.gz: a8685c4b424486b78aa754c19bf57089cbac98650f4791ddde635060e1c81228ec635f387fa52db93f8029f85991bfea718efd9cd520024ad75c103ce3262318
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Snm
4
4
  module Fcm
5
- VERSION = "0.1.0"
5
+ VERSION = "0.1.3"
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
@@ -16,24 +18,31 @@ module Snm
16
18
  @configuration ||= Configuration.new
17
19
  end
18
20
 
19
- def self.config(&block)
20
- @configuration = yield(configuration)
21
+ def self.setup(&block)
22
+ yield(configuration)
21
23
  end
22
24
 
23
- def self.deliver token, data={}
24
- raise 'Token is missing' if not token.present?
25
- 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)
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
- 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']
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.0
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