snm-fcm 0.1.5 → 0.1.6
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/README.md +64 -16
- data/lib/snm/fcm/version.rb +1 -1
- data/lib/snm/fcm.rb +16 -9
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d59ac9bf55d1e9380c20cf2ff2c94f170bd160fc1fd32d2437bbaa4f559b715a
|
4
|
+
data.tar.gz: 988218b976e0e35a148aba9cb17aadbf6bd19d5a8e0e45092b3d3c090256fce0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 94f041e6ab5cf3ea1a0a88a0ed53e828576e3b5ee7b349074df60bbe8fbafb9db9feaaf02feff0a4b5d76d42de1db5560fc6d929fdd7c293404b3f56de8c01d7
|
7
|
+
data.tar.gz: 85bcbe3e2aeed13eafc76fc09c9efbd653d0ca8d5fb16e005a2c5f931b87ebdd8173d2d0ec058b94c439dbeeba7b855c7babf141fbc6151d03381f084a14e094
|
data/README.md
CHANGED
@@ -1,34 +1,82 @@
|
|
1
1
|
# Snm::Fcm
|
2
2
|
|
3
|
-
|
3
|
+
Ruby Library to send notification on android via Firebase Cloud Messaging API (V1)
|
4
4
|
|
5
|
-
|
5
|
+
This library is based on Firebase Cloud Messaging API (V1) to send notification on android devices.
|
6
6
|
|
7
|
-
##
|
7
|
+
## Requirements
|
8
|
+
Version 0.1.6 requires at least Ruby 3.0.0, This library dependents on googleauth, redis, json and http gem.
|
8
9
|
|
9
|
-
|
10
|
+
## Installation
|
10
11
|
|
11
12
|
Install the gem and add to the application's Gemfile by executing:
|
12
13
|
|
13
|
-
$
|
14
|
+
$ gem 'snm-fcm', '~> 0.1.5'
|
14
15
|
|
15
16
|
If bundler is not being used to manage dependencies, install the gem by executing:
|
16
17
|
|
17
|
-
$ gem install
|
18
|
+
$ gem install snm-fcm
|
18
19
|
|
19
20
|
## Usage
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
21
|
+
### Setup
|
22
|
+
Create an initializer file for ex rails-project/config/initializers/snm_fcm.rb
|
23
|
+
```
|
24
|
+
Snm::Fcm::Notification.configure do |config|
|
25
|
+
config.credentails_file_path = 'path/to/my-fcm-e65a9915e042.json'
|
26
|
+
config.redis_endpoint = 'redis://localhost:6379/1'
|
27
|
+
end
|
28
|
+
Snm::Fcm::Notification.setup
|
29
|
+
```
|
30
|
+
### Send notification
|
31
|
+
```
|
32
|
+
msg_data = {
|
33
|
+
'message'=> {
|
34
|
+
'token'=> 'android-device-fcm-token',
|
35
|
+
'notification'=>
|
36
|
+
{
|
37
|
+
'title'=> 'Lorem ipsum',
|
38
|
+
'body'=> 'Lorem ipsum dolor sit amet, consectetur adipiscing elit',
|
39
|
+
'image'=> 'https://www.snmmaurya.com/images/me.jpg'
|
40
|
+
},
|
41
|
+
'data'=> {
|
42
|
+
'key1'=> 'value1',
|
43
|
+
'key2'=> 'value2'
|
44
|
+
}
|
45
|
+
}
|
46
|
+
}
|
47
|
+
respoonse = Snm::Fcm::Notification.deliver(msg_data)
|
48
|
+
|
49
|
+
# Success response:
|
50
|
+
|
51
|
+
{"name"=>"projects/my-fcm/messages/0:1715935676674045%f570bc3bf570bc3b"}
|
52
|
+
|
53
|
+
```
|
54
|
+
## How to get my-fcm-e65a9915e042.json
|
55
|
+
|
56
|
+
1. Got go https://console.firebase.google.com/
|
57
|
+
|
58
|
+
### For Android (FE)
|
59
|
+
|
60
|
+
2. Create your project for ex 'my-fcm' and download google-services.json to set up your android project.
|
61
|
+
|
62
|
+
### For Ruby
|
63
|
+
3. Go to the project click on settings icon next to Project Overview top left cornor.
|
64
|
+
|
65
|
+
3.1 in the general tab you will find 'project id' copy this id and put somewhere in your system.
|
66
|
+
|
67
|
+
3.2 Click on Cloud Messging tab -
|
68
|
+
|
69
|
+
3.3 In side Firebase Cloud Messaging API (V1) panel.
|
70
|
+
|
71
|
+
3.4 Click on Manage Service Accounts On the next page a service already be there click on the name of that serive name for ex 'firebase-adminsdk-4apop@my-fcm.iam.gserviceaccount.com'
|
72
|
+
|
73
|
+
3.5 Click on advanced settings - choose 'keys' tab.
|
74
|
+
|
75
|
+
3.6 Now create a new key type json download it (automatically downloaded) put this file somewhere in your system. this file is your my-fcm-e65a9915e042.json
|
28
76
|
|
29
77
|
## Contributing
|
30
78
|
|
31
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
79
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/snmmaurya/snm-fcm. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/snmmaurya/snm-fcm/blob/main/CODE_OF_CONDUCT.md).
|
32
80
|
|
33
81
|
## License
|
34
82
|
|
@@ -36,4 +84,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
36
84
|
|
37
85
|
## Code of Conduct
|
38
86
|
|
39
|
-
Everyone interacting in the Snm::Fcm project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/
|
87
|
+
Everyone interacting in the Snm::Fcm project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/snmmaurya/snm-fcm/blob/main/CODE_OF_CONDUCT.md).
|
data/lib/snm/fcm/version.rb
CHANGED
data/lib/snm/fcm.rb
CHANGED
@@ -4,13 +4,14 @@ require_relative "fcm/version"
|
|
4
4
|
require 'googleauth'
|
5
5
|
require 'http'
|
6
6
|
require 'json'
|
7
|
+
require 'redis'
|
7
8
|
|
8
9
|
module Snm
|
9
10
|
module Fcm
|
10
11
|
class Error < StandardError; end
|
11
12
|
|
12
13
|
class Configuration
|
13
|
-
attr_accessor :credentails_file_path, :project_id
|
14
|
+
attr_accessor :credentails_file_path, :project_id, :redis_endpoint, :snm_fcm_redis
|
14
15
|
end
|
15
16
|
|
16
17
|
class Notification
|
@@ -18,7 +19,7 @@ module Snm
|
|
18
19
|
@configuration ||= Configuration.new
|
19
20
|
end
|
20
21
|
|
21
|
-
def self.
|
22
|
+
def self.configure(&block)
|
22
23
|
yield(configuration)
|
23
24
|
end
|
24
25
|
|
@@ -30,18 +31,24 @@ module Snm
|
|
30
31
|
end
|
31
32
|
|
32
33
|
def self.get_access_token
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
34
|
+
access_token = Notification.configuration.snm_fcm_redis.get('access_token')
|
35
|
+
if access_token.nil?
|
36
|
+
scope = 'https://www.googleapis.com/auth/cloud-platform'
|
37
|
+
authorizer = Google::Auth::ServiceAccountCredentials.make_creds(
|
38
|
+
json_key_io: File.open(Notification.configuration.credentails_file_path),
|
39
|
+
scope: scope
|
40
|
+
)
|
41
|
+
access_token = authorizer.fetch_access_token!['access_token']
|
42
|
+
Notification.configuration.snm_fcm_redis.setex('access_token', 3599, access_token)
|
43
|
+
end
|
44
|
+
access_token
|
39
45
|
end
|
40
46
|
|
41
|
-
def self.
|
47
|
+
def self.setup
|
42
48
|
file = File.read(Notification.configuration.credentails_file_path)
|
43
49
|
data_hash = JSON.parse(file)
|
44
50
|
Notification.configuration.project_id = data_hash["project_id"]
|
51
|
+
Notification.configuration.snm_fcm_redis = Redis.new(url: Notification.configuration.redis_endpoint)
|
45
52
|
end
|
46
53
|
end
|
47
54
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- snmmaurya
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-05-
|
11
|
+
date: 2024-05-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: http
|
@@ -58,6 +58,20 @@ dependencies:
|
|
58
58
|
- - ">="
|
59
59
|
- !ruby/object:Gem::Version
|
60
60
|
version: 2.7.2
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: redis
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '5.2'
|
68
|
+
type: :runtime
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '5.2'
|
61
75
|
description: Ruby Library to send notification on android via Firebase Cloud Messaging
|
62
76
|
API (V1)
|
63
77
|
email:
|