inova_fcm 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 7a5c3f2db558546de2db1fbc8e5bd1ec590c503888c793de28fa9c5011381b28
4
+ data.tar.gz: ccb4df677e12bf71a44215580e7c255536797a043fd17133ea3744061b372424
5
+ SHA512:
6
+ metadata.gz: 9a32fce4e8763f73aedc990aebd72859dbd90e4acdaa2d62e53cf41d9d1b2fa9db2a23d3c5329072bcdd8a42512d76847c898495920a5a2dbc1548c5717e8329
7
+ data.tar.gz: b7f361981e123ef2575077670747b11c8bcc25fff5c3173b4efda7b4f0cc819c234e2d7f1844970f87ae9846781c14a100c3ce7e526b98bfa0cceaa1a1ef1fb7
data/.standard.yml ADDED
@@ -0,0 +1,3 @@
1
+ # For available configuration options, see:
2
+ # https://github.com/testdouble/standard
3
+ ruby_version: 3.1.2
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2023-12-06
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at ahmed.mosad@inovaeg.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 Ahmed Mos`ad
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,53 @@
1
+ # InovaFCM
2
+
3
+ InovaFCM is a Ruby gem designed to simplify interactions with Firebase Cloud Messaging (FCM) for Ruby applications, particularly those built with Ruby on Rails, This gem heavily depends on [fcm](https://github.com/decision-labs/fcm)
4
+
5
+ ## Installation
6
+
7
+ To use this gem in your project, add it to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'inova_fcm', '~> 0.1.0'
11
+ ```
12
+
13
+ Alternatively, you can install the gem directly using:
14
+
15
+ ```bash
16
+ gem install inova_fcm -v '~> 0.1.0'
17
+ ```
18
+
19
+ ## Requirments
20
+
21
+ - Ruby >= 3.1.2
22
+ - Rails >= 6.1
23
+
24
+ ## Usage
25
+
26
+ ```bash
27
+ rails generate inova_fcm:install
28
+ ```
29
+
30
+ This will create a configuration file at config/initializers/inova_aws_s3.rb. Open the file and set your AWS credentials:
31
+
32
+ ```ruby
33
+ InovaFCM.configure do |config|
34
+ # Set your configuration options here
35
+ config.fcm_key = "AAAA..."
36
+ config.firebase_admin_sdk_path = "path/to/service_account.json"
37
+ config.firebase_project_id = "your_firebase_project_id"
38
+ end
39
+ ```
40
+
41
+ Replace the placeholder values with your actual AWS credentials.
42
+
43
+ ## Contributing
44
+
45
+ Bug reports and pull requests are welcome on GitHub at <https://github.com/ahmedmos3ad/inova_fcm/pulls>. 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/ahmedmos3ad/inova_fcm/blob/master/CODE_OF_CONDUCT.md).
46
+
47
+ ## License
48
+
49
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
50
+
51
+ ## Code of Conduct
52
+
53
+ Everyone interacting in the InovaAwsS3 project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/ahmedmos3ad/inova_fcm/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test"
8
+ t.libs << "lib"
9
+ t.test_files = FileList["test/**/test_*.rb"]
10
+ end
11
+
12
+ require "standard/rake"
13
+
14
+ task default: %i[test standard]
data/inova_fcm.gemspec ADDED
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/inova_fcm/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "inova_fcm"
7
+ spec.version = InovaFCM::VERSION
8
+ spec.authors = ["Ahmed Mos`ad"]
9
+ spec.email = ["ahmed.mosad555@gmail.com"]
10
+
11
+ spec.summary = "Ruby gem to send messages via firebase cloud messaging."
12
+ spec.homepage = "https://github.com/ahmedmos3ad/inova_fcm"
13
+ spec.license = "MIT"
14
+ spec.required_ruby_version = ">= 3.1.2"
15
+ spec.add_dependency "rails", ">= 6.1"
16
+ spec.add_dependency "fcm", ">= 1.0.8"
17
+
18
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
19
+
20
+ spec.metadata["homepage_uri"] = spec.homepage
21
+ spec.metadata["source_code_uri"] = "https://github.com/ahmedmos3ad/inova_fcm"
22
+ spec.metadata["changelog_uri"] = "https://github.com/ahmedmos3ad/inova_fcm/blob/master/CHANGELOG.md"
23
+
24
+ # Specify which files should be added to the gem when it is released.
25
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
26
+ spec.files = Dir.chdir(__dir__) do
27
+ `git ls-files -z`.split("\x0").reject do |f|
28
+ (File.expand_path(f) == __FILE__) ||
29
+ f.start_with?(*%w[bin/ test/ spec/ features/ .git .github appveyor Gemfile])
30
+ end
31
+ end
32
+ spec.bindir = "exe"
33
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
34
+ spec.require_paths = ["lib"]
35
+
36
+ # Uncomment to register a new dependency of your gem
37
+ # spec.add_dependency "example-gem", "~> 1.0"
38
+
39
+ # For more information and examples about making a new gem, check out our
40
+ # guide at: https://bundler.io/guides/creating_gem.html
41
+ end
@@ -0,0 +1,13 @@
1
+ require "rails/generators"
2
+
3
+ module InovaFcm
4
+ module Generators
5
+ class InstallGenerator < Rails::Generators::Base
6
+ source_root File.expand_path("templates", __dir__)
7
+
8
+ def create_initializer_file
9
+ copy_file "inova_fcm_initializer.rb", "config/initializers/inova_fcm.rb"
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,6 @@
1
+ InovaFCM.configure do |config|
2
+ # Set your configuration options here
3
+ config.fcm_key = "AAAA..."
4
+ config.firebase_admin_sdk_path = "path/to/service_account.json"
5
+ config.firebase_project_id = "your_firebase_project_id"
6
+ end
@@ -0,0 +1,14 @@
1
+ module InovaFCM
2
+ class Configuration
3
+ attr_accessor :fcm_key, :firebase_admin_sdk_path, :firebase_project_id
4
+
5
+ def validate!
6
+ required_attributes = [:fcm_key, :firebase_admin_sdk_path, :firebase_project_id]
7
+
8
+ required_attributes.each do |attribute|
9
+ value = send(attribute)
10
+ raise ArgumentError, "#{attribute} is required in the configuration" if value.nil? || (value.respond_to?(:empty?) && value.empty?)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,77 @@
1
+ module InovaFCM
2
+ class Service
3
+ require "fcm"
4
+ require "json"
5
+
6
+ attr_reader :registration_ids, :notification, :data, :topic
7
+
8
+ def initialize(registration_ids: [], notification: {}, data: {}, topic: SecureRandom.uuid + Time.now.to_i.to_s)
9
+ @topic = topic
10
+ @registration_ids = registration_ids.uniq
11
+ @notification = notification
12
+ @data = data
13
+
14
+ InovaFCM.configuration.validate!
15
+
16
+ @fcm = FCM.new(InovaFCM.configuration.fcm_key,
17
+ InovaFCM.configuration.firebase_admin_sdk_path,
18
+ InovaFCM.configuration.firebase_project_id)
19
+
20
+ validate_attributes!
21
+ end
22
+
23
+ def send_notification
24
+ if @registration_ids.count > 1
25
+ bulk_send_notification
26
+ else
27
+ @fcm.send_v1(prepare_token_message)
28
+ end
29
+ end
30
+
31
+ private
32
+
33
+ def bulk_send_notification
34
+ register_tokens_to_topic
35
+ @fcm.send_v1(prepare_topic_message)
36
+ unregister_tokens_from_topic
37
+ end
38
+
39
+ def prepare_topic_message
40
+ prepare_message.merge(topic: @topic)
41
+ end
42
+
43
+ def prepare_token_message
44
+ prepare_message.merge(token: @registration_ids.first)
45
+ end
46
+
47
+ def prepare_message
48
+ {
49
+ data: {
50
+ payload: data.to_json,
51
+ click_action: "FLUTTER_NOTIFICATION_CLICK"
52
+ },
53
+ notification: {
54
+ title: @notification[:title],
55
+ body: @notification[:body]
56
+ }
57
+ }
58
+ end
59
+
60
+ def register_tokens_to_topic
61
+ @fcm.batch_topic_subscription(@topic, @registration_ids)
62
+ end
63
+
64
+ def unregister_tokens_from_topic
65
+ @fcm.batch_topic_unsubscription(@topic, @registration_ids)
66
+ end
67
+
68
+ def validate_attributes!
69
+ required_attributes = [:registration_ids, :notification, :data]
70
+
71
+ required_attributes.each do |attribute|
72
+ value = send(attribute)
73
+ raise ArgumentError, "#{attribute} is required" if value.nil? || (value.respond_to?(:empty?) && value.empty?)
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,15 @@
1
+ # test_config.rb
2
+
3
+ module InovaFCM
4
+ class Configuration
5
+ require "dotenv"
6
+ Dotenv.load(".env")
7
+ # attr_accessor :fcm_key, :firebase_admin_sdk_path, :firebase_project_id
8
+
9
+ def initialize
10
+ @fcm_key = ENV["FCM_KEY"]
11
+ @firebase_admin_sdk_path = ENV["FIREBASE_ADMIN_SDK_PATH"]
12
+ @firebase_project_id = ENV["FIREBASE_PROJECT_ID"]
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module InovaFCM
4
+ VERSION = "0.1.0"
5
+ end
data/lib/inova_fcm.rb ADDED
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "inova_fcm/version"
4
+ require_relative "inova_fcm/configuration"
5
+ require_relative "inova_fcm/service"
6
+
7
+ module InovaFCM
8
+ class Error < StandardError; end
9
+ # Your code goes here...
10
+
11
+ class << self
12
+ attr_accessor :configuration
13
+ end
14
+
15
+ def self.configure
16
+ self.configuration ||= Configuration.new
17
+ yield(configuration)
18
+ end
19
+ end
data/sig/inova_fcm.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module InovaFCM
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: inova_fcm
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ahmed Mos`ad
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-12-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '6.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '6.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: fcm
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.0.8
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 1.0.8
41
+ description:
42
+ email:
43
+ - ahmed.mosad555@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".standard.yml"
49
+ - CHANGELOG.md
50
+ - CODE_OF_CONDUCT.md
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - inova_fcm.gemspec
55
+ - lib/generators/inova_fcm/install_generator.rb
56
+ - lib/generators/inova_fcm/templates/inova_fcm_initializer.rb
57
+ - lib/inova_fcm.rb
58
+ - lib/inova_fcm/configuration.rb
59
+ - lib/inova_fcm/service.rb
60
+ - lib/inova_fcm/test_config.rb
61
+ - lib/inova_fcm/version.rb
62
+ - sig/inova_fcm.rbs
63
+ homepage: https://github.com/ahmedmos3ad/inova_fcm
64
+ licenses:
65
+ - MIT
66
+ metadata:
67
+ allowed_push_host: https://rubygems.org
68
+ homepage_uri: https://github.com/ahmedmos3ad/inova_fcm
69
+ source_code_uri: https://github.com/ahmedmos3ad/inova_fcm
70
+ changelog_uri: https://github.com/ahmedmos3ad/inova_fcm/blob/master/CHANGELOG.md
71
+ post_install_message:
72
+ rdoc_options: []
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: 3.1.2
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ requirements: []
86
+ rubygems_version: 3.3.7
87
+ signing_key:
88
+ specification_version: 4
89
+ summary: Ruby gem to send messages via firebase cloud messaging.
90
+ test_files: []