snm-fcm 0.1.5 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +66 -16
  3. data/lib/snm/fcm/version.rb +1 -1
  4. data/lib/snm/fcm.rb +16 -9
  5. metadata +25 -17
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 991a04d8b3f660e9f74fbdf29a31b7478e0ed39b04a2a510d1353550d6fb16b2
4
- data.tar.gz: c370801fce9fd3413877015b9484a1cfbd1ece69eaeb2d852639dc188c87219b
3
+ metadata.gz: 6cd57d046281fcba5e9eadd49db93c223272bf730a02f11b40e50a14cb1a9fa8
4
+ data.tar.gz: 1ac6cdbcd1128fb291de794cc75bc7bc7bde3e781829997f10f2ba085d264fd0
5
5
  SHA512:
6
- metadata.gz: 52832fe027409c109c83d99dc32eac6bddd0d95f14a8e0cac644026bd9b52a616f5dad840a845456a8d0aeda52e443c6239daaa119e106871870d6d4d2cf6282
7
- data.tar.gz: e7d828acb36fe5b75b88428141714c1c1540a2746bdbb976aa5222d2e2ddcfd43c337dc9aaad133b4ed678ace3c9aac867f3e48fab5a46d958dd072032a38368
6
+ metadata.gz: 30b80cf965fe21b89125e1f533632e65d484f95c0ad0276c4e90e13ba8be4da25a16edaa5b5d270b2abd892d9c72364de8b1d15bdc18a1e81e5555f4089a24cb
7
+ data.tar.gz: d4fd4310aac6d8220451d43fff927f849a3059f27174b6d025f5dc7ae52cc2e91ae1c275b0e662e18f120346af941d0c193ab3e2e20f59bad93f7c3dc715aea4
data/README.md CHANGED
@@ -1,34 +1,84 @@
1
1
  # Snm::Fcm
2
2
 
3
- TODO: Delete this and the text below, and describe your gem
3
+ <a href="https://badge.fury.io/rb/snm-fcm"><img src="https://badge.fury.io/rb/snm-fcm.svg" alt="Gem Version" height="18"></a>
4
4
 
5
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/snm/fcm`. To experiment with that code, run `bin/console` for an interactive prompt.
5
+ Ruby Library to send notification on android via Firebase Cloud Messaging API (V1)
6
6
 
7
- ## Installation
7
+ This library is based on Firebase Cloud Messaging API (V1) to send notification on android devices.
8
+
9
+ ## Requirements
10
+ Version 0.1.6 requires at least Ruby 3.0.0, This library dependents on googleauth, redis, json and http gem.
8
11
 
9
- TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
12
+ ## Installation
10
13
 
11
14
  Install the gem and add to the application's Gemfile by executing:
12
15
 
13
- $ bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
16
+ $ gem 'snm-fcm', '~> 0.1.5'
14
17
 
15
18
  If bundler is not being used to manage dependencies, install the gem by executing:
16
19
 
17
- $ gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
20
+ $ gem install snm-fcm
18
21
 
19
22
  ## Usage
20
-
21
- TODO: Write usage instructions here
22
-
23
- ## Development
24
-
25
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
26
-
27
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
23
+ ### Setup
24
+ Create an initializer file for ex rails-project/config/initializers/snm_fcm.rb
25
+ ```
26
+ Snm::Fcm::Notification.configure do |config|
27
+ config.credentails_file_path = 'path/to/my-fcm-e65a9915e042.json'
28
+ config.redis_endpoint = 'redis://localhost:6379/1'
29
+ end
30
+ Snm::Fcm::Notification.setup
31
+ ```
32
+ ### Send notification
33
+ ```
34
+ msg_data = {
35
+ 'message'=> {
36
+ 'token'=> 'android-device-fcm-token',
37
+ 'notification'=>
38
+ {
39
+ 'title'=> 'Lorem ipsum',
40
+ 'body'=> 'Lorem ipsum dolor sit amet, consectetur adipiscing elit',
41
+ 'image'=> 'https://www.snmmaurya.com/images/me.jpg'
42
+ },
43
+ 'data'=> {
44
+ 'key1'=> 'value1',
45
+ 'key2'=> 'value2'
46
+ }
47
+ }
48
+ }
49
+ respoonse = Snm::Fcm::Notification.deliver(msg_data)
50
+
51
+ # Success response:
52
+
53
+ {"name"=>"projects/my-fcm/messages/0:1715935676674045%f570bc3bf570bc3b"}
54
+
55
+ ```
56
+ ## How to get my-fcm-e65a9915e042.json
57
+
58
+ 1. Got go https://console.firebase.google.com/
59
+
60
+ ### For Android (FE)
61
+
62
+ 2. Create your project for ex 'my-fcm' and download google-services.json to set up your android project.
63
+
64
+ ### For Ruby
65
+ 3. Go to the project click on settings icon next to Project Overview top left cornor.
66
+
67
+ 3.1 in the general tab you will find 'project id' copy this id and put somewhere in your system.
68
+
69
+ 3.2 Click on Cloud Messging tab -
70
+
71
+ 3.3 In side Firebase Cloud Messaging API (V1) panel.
72
+
73
+ 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'
74
+
75
+ 3.5 Click on advanced settings - choose 'keys' tab.
76
+
77
+ 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
78
 
29
79
  ## Contributing
30
80
 
31
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/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/[USERNAME]/snm-fcm/blob/main/CODE_OF_CONDUCT.md).
81
+ 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
82
 
33
83
  ## License
34
84
 
@@ -36,4 +86,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
36
86
 
37
87
  ## Code of Conduct
38
88
 
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/[USERNAME]/snm-fcm/blob/main/CODE_OF_CONDUCT.md).
89
+ 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).
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Snm
4
4
  module Fcm
5
- VERSION = "0.1.5"
5
+ VERSION = "0.1.7"
6
6
  end
7
7
  end
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.setup(&block)
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
- scope = 'https://www.googleapis.com/auth/cloud-platform'
34
- authorizer = Google::Auth::ServiceAccountCredentials.make_creds(
35
- json_key_io: File.open(Notification.configuration.credentails_file_path),
36
- scope: scope
37
- )
38
- authorizer.fetch_access_token!['access_token']
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.set_project
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,63 +1,71 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: snm-fcm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.7
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-16 00:00:00.000000000 Z
11
+ date: 2024-05-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '5.2'
19
+ version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '5.2'
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: googleauth
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '1.11'
33
+ version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '1.11'
40
+ version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: json
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '2.7'
48
45
  - - ">="
49
46
  - !ruby/object:Gem::Version
50
- version: 2.7.2
47
+ version: '0'
51
48
  type: :runtime
52
49
  prerelease: false
53
50
  version_requirements: !ruby/object:Gem::Requirement
54
51
  requirements:
55
- - - "~>"
52
+ - - ">="
56
53
  - !ruby/object:Gem::Version
57
- version: '2.7'
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: redis
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
58
66
  - - ">="
59
67
  - !ruby/object:Gem::Version
60
- version: 2.7.2
68
+ version: '0'
61
69
  description: Ruby Library to send notification on android via Firebase Cloud Messaging
62
70
  API (V1)
63
71
  email: