ffccmmx 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 6f3a989f55da2e1b9187f012bb1bf4571504f0e8dd1cacab4c8ac3e8bd26648b
4
+ data.tar.gz: 38cbd21555d467bb2c3f023c102e810a87dea0ac2357eac7405874d924d2b8f0
5
+ SHA512:
6
+ metadata.gz: f433427d542b61b7c959994cb3420bd6eccf4228306a786ef48baf72918cbe3d22aa67bb2c5fbc86e7caf54d030f07ff5fc9c568b97063dd5ce7a3f82f1f90f2
7
+ data.tar.gz: c5cca8df39b59e5abfb61e1a934588cd547615c3861ede7b8ba7feb032441de5bfc073f9d865075819ddec1ec50442beef07e730e8fd80b07e06fb11b80bf97c
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,18 @@
1
+ AllCops:
2
+ TargetRubyVersion: 3.1
3
+
4
+ Style/StringLiterals:
5
+ EnforcedStyle: double_quotes
6
+
7
+ Style/StringLiteralsInInterpolation:
8
+ EnforcedStyle: double_quotes
9
+
10
+ Style/Documentation:
11
+ Enabled: false
12
+
13
+ Metrics/ClassLength:
14
+ Enabled: false
15
+
16
+ Metrics/BlockLength:
17
+ Exclude:
18
+ - 'spec/**/*'
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2025-06-20
4
+
5
+ - Initial release
@@ -0,0 +1,132 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our
6
+ community a harassment-free experience for everyone, regardless of age, body
7
+ size, visible or invisible disability, ethnicity, sex characteristics, gender
8
+ identity and expression, level of experience, education, socio-economic status,
9
+ nationality, personal appearance, race, caste, color, religion, or sexual
10
+ identity and orientation.
11
+
12
+ We pledge to act and interact in ways that contribute to an open, welcoming,
13
+ diverse, inclusive, and healthy community.
14
+
15
+ ## Our Standards
16
+
17
+ Examples of behavior that contributes to a positive environment for our
18
+ community include:
19
+
20
+ * Demonstrating empathy and kindness toward other people
21
+ * Being respectful of differing opinions, viewpoints, and experiences
22
+ * Giving and gracefully accepting constructive feedback
23
+ * Accepting responsibility and apologizing to those affected by our mistakes,
24
+ and learning from the experience
25
+ * Focusing on what is best not just for us as individuals, but for the overall
26
+ community
27
+
28
+ Examples of unacceptable behavior include:
29
+
30
+ * The use of sexualized language or imagery, and sexual attention or advances of
31
+ any kind
32
+ * Trolling, insulting or derogatory comments, and personal or political attacks
33
+ * Public or private harassment
34
+ * Publishing others' private information, such as a physical or email address,
35
+ without their explicit permission
36
+ * Other conduct which could reasonably be considered inappropriate in a
37
+ professional setting
38
+
39
+ ## Enforcement Responsibilities
40
+
41
+ Community leaders are responsible for clarifying and enforcing our standards of
42
+ acceptable behavior and will take appropriate and fair corrective action in
43
+ response to any behavior that they deem inappropriate, threatening, offensive,
44
+ or harmful.
45
+
46
+ Community leaders have the right and responsibility to remove, edit, or reject
47
+ comments, commits, code, wiki edits, issues, and other contributions that are
48
+ not aligned to this Code of Conduct, and will communicate reasons for moderation
49
+ decisions when appropriate.
50
+
51
+ ## Scope
52
+
53
+ This Code of Conduct applies within all community spaces, and also applies when
54
+ an individual is officially representing the community in public spaces.
55
+ Examples of representing our community include using an official email address,
56
+ posting via an official social media account, or acting as an appointed
57
+ representative at an online or offline event.
58
+
59
+ ## Enforcement
60
+
61
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
62
+ reported to the community leaders responsible for enforcement at
63
+ [INSERT CONTACT METHOD].
64
+ All complaints will be reviewed and investigated promptly and fairly.
65
+
66
+ All community leaders are obligated to respect the privacy and security of the
67
+ reporter of any incident.
68
+
69
+ ## Enforcement Guidelines
70
+
71
+ Community leaders will follow these Community Impact Guidelines in determining
72
+ the consequences for any action they deem in violation of this Code of Conduct:
73
+
74
+ ### 1. Correction
75
+
76
+ **Community Impact**: Use of inappropriate language or other behavior deemed
77
+ unprofessional or unwelcome in the community.
78
+
79
+ **Consequence**: A private, written warning from community leaders, providing
80
+ clarity around the nature of the violation and an explanation of why the
81
+ behavior was inappropriate. A public apology may be requested.
82
+
83
+ ### 2. Warning
84
+
85
+ **Community Impact**: A violation through a single incident or series of
86
+ actions.
87
+
88
+ **Consequence**: A warning with consequences for continued behavior. No
89
+ interaction with the people involved, including unsolicited interaction with
90
+ those enforcing the Code of Conduct, for a specified period of time. This
91
+ includes avoiding interactions in community spaces as well as external channels
92
+ like social media. Violating these terms may lead to a temporary or permanent
93
+ ban.
94
+
95
+ ### 3. Temporary Ban
96
+
97
+ **Community Impact**: A serious violation of community standards, including
98
+ sustained inappropriate behavior.
99
+
100
+ **Consequence**: A temporary ban from any sort of interaction or public
101
+ communication with the community for a specified period of time. No public or
102
+ private interaction with the people involved, including unsolicited interaction
103
+ with those enforcing the Code of Conduct, is allowed during this period.
104
+ Violating these terms may lead to a permanent ban.
105
+
106
+ ### 4. Permanent Ban
107
+
108
+ **Community Impact**: Demonstrating a pattern of violation of community
109
+ standards, including sustained inappropriate behavior, harassment of an
110
+ individual, or aggression toward or disparagement of classes of individuals.
111
+
112
+ **Consequence**: A permanent ban from any sort of public interaction within the
113
+ community.
114
+
115
+ ## Attribution
116
+
117
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118
+ version 2.1, available at
119
+ [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
120
+
121
+ Community Impact Guidelines were inspired by
122
+ [Mozilla's code of conduct enforcement ladder][Mozilla CoC].
123
+
124
+ For answers to common questions about this code of conduct, see the FAQ at
125
+ [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
126
+ [https://www.contributor-covenant.org/translations][translations].
127
+
128
+ [homepage]: https://www.contributor-covenant.org
129
+ [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
130
+ [Mozilla CoC]: https://github.com/mozilla/diversity
131
+ [FAQ]: https://www.contributor-covenant.org/faq
132
+ [translations]: https://www.contributor-covenant.org/translations
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 anatofuz
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,156 @@
1
+ # Ffccmmx
2
+
3
+ Ffccmmx is a Firebase Cloud Messaging (FCM) client for Ruby, built on top of the [httpx](https://rubygems.org/gems/httpx).
4
+ It is based on the original [fcmpush gem](https://rubygems.org/gems/fcmpush).
5
+
6
+ By leveraging httpx, this gem enables HTTP/2 communication while maintaining an interface that is almost identical to fcmpush.
7
+
8
+ ## Installation
9
+
10
+ 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.
11
+
12
+ Install the gem and add to the application's Gemfile by executing:
13
+
14
+ ```bash
15
+ bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
16
+ ```
17
+
18
+ If bundler is not being used to manage dependencies, install the gem by executing:
19
+
20
+ ```bash
21
+ gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
22
+ ```
23
+
24
+ ## Usage
25
+
26
+ ### Configuration
27
+
28
+ ```ruby
29
+ Ffccmmx.configure do |config|
30
+ config.scope = ["https://www.googleapis.com/auth/cloud-platform"]
31
+ config.json_key_io = StringIO.new('{"key": "value"}')
32
+ config.proxy = "http://proxy.example.com"
33
+ config.httpx_options = {
34
+ timeout: {
35
+ connect_timeout: 5,
36
+ },
37
+ }
38
+ end
39
+ ```
40
+
41
+ or You can use environment variables:
42
+
43
+ ```bash
44
+ export GOOGLE_ACCOUNT_TYPE = 'service_account'
45
+ export GOOGLE_CLIENT_ID = '000000000000000000000'
46
+ export GOOGLE_CLIENT_EMAIL = 'xxxx@xxxx.iam.gserviceaccount.com'
47
+ export GOOGLE_PRIVATE_KEY = '-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n'
48
+ ```
49
+
50
+ or You can use a JSON key file:
51
+
52
+ ```ruby
53
+ Ffccmmx.configure do |config|
54
+ config.json_key_io = File.open('/path/to/your/service_account_credentials.json')
55
+ end
56
+ ```
57
+
58
+ ### Pushing Messages
59
+
60
+ ```ruby
61
+ @client = Ffccmmx.new(project_id)
62
+ notification_message = {
63
+ message: {
64
+ token: device_token,
65
+ notification: {
66
+ title: "test title",
67
+ body: "test body"
68
+ }
69
+ }
70
+ }
71
+ response = @client.push(notification_message)
72
+ response.json
73
+ ```
74
+
75
+ response is an instance of `HTTPX::Response`, which contains the response from the FCM server. You can access the JSON response using `response.json`.
76
+ The Fcmpush response uses symbols for its keys, while the Ffccmmx response uses strings.
77
+
78
+ ### Concurrent Pushing Messages
79
+
80
+ ```ruby
81
+ @client = Ffccmmx.new(project_id)
82
+ notification_messages = [
83
+ {
84
+ message: {
85
+ token: device_token,
86
+ notification: {
87
+ title: "test title",
88
+ body: "test body"
89
+ }
90
+ }
91
+ },
92
+ {
93
+ message: {
94
+ token: other_device_token,
95
+ notification: {
96
+ title: "test title",
97
+ body: "test body"
98
+ }
99
+ }
100
+ },
101
+ ]
102
+ responses = @client.concurrent_push(notification_messages)
103
+ responses.each do |response|
104
+ httpx_response = response.value
105
+ end
106
+ ```
107
+
108
+ The `concurrent_push` method sends requests using HTTP/2 multiplexing.
109
+ The response is wrapped in an Ffccmmx::Response object. you can get the HTTPX::Response with #value, or an Ffccmmx::Error will be raised.
110
+
111
+
112
+ ### Subscribe
113
+
114
+ ```ruby
115
+ @client = Ffccmmx.new(project_id)
116
+ response = @client.subscribe('/topics/test_topic', device_token)
117
+ ```
118
+
119
+ ## Concurrent Subscribe
120
+
121
+ ```ruby
122
+ @client = Ffccmmx.new(project_id)
123
+ response = @client.subscribe('/topics/test_topic', *device_tokens)
124
+ ```
125
+
126
+ ### Unsubscribe
127
+
128
+ ```ruby
129
+ @client = Ffccmmx.new(project_id)
130
+ response = @client.unsubscribe('/topics/test_topic', device_token)
131
+ ```
132
+
133
+ ## Concurrent Unsubscribe
134
+
135
+ ```ruby
136
+ @client = Ffccmmx.new(project_id)
137
+ response = @client.unsubscribe('/topics/test_topic', *device_tokens)
138
+ ```
139
+
140
+ ## Development
141
+
142
+ 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.
143
+
144
+ 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).
145
+
146
+ ## Contributing
147
+
148
+ Bug reports and pull requests are welcome on GitHub at https://github.com/AnaTofuZ/ffccmmx. 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/AnaTofuZ/ffccmmx/blob/master/CODE_OF_CONDUCT.md).
149
+
150
+ ## License
151
+
152
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
153
+
154
+ ## Code of Conduct
155
+
156
+ Everyone interacting in the Ffccmmx project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/AnaTofuZ/ffccmmx/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
@@ -0,0 +1,162 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "uri"
4
+ require "googleauth"
5
+ require "httpx"
6
+ require "ffccmmx/exceptions"
7
+ require "ffccmmx/response"
8
+
9
+ module Ffccmmx
10
+ class Client
11
+ V1_ENDPOINT_PREFIX = "/v1/projects/"
12
+ V1_ENDPOINT_SUFFIX = "/messages:send"
13
+ TOPIC_ENDPOINT_PREFIX = "/iid/v1"
14
+ TOPIC_BATCH_SUBSCRIBE_SUFFIX = ":batchAdd"
15
+ TOPIC_BATCH_UNSUBSCRIBE_SUFFIX = ":batchRemove"
16
+ private_constant :V1_ENDPOINT_PREFIX, :V1_ENDPOINT_SUFFIX, :TOPIC_ENDPOINT_PREFIX,
17
+ :TOPIC_BATCH_SUBSCRIBE_SUFFIX, :TOPIC_BATCH_UNSUBSCRIBE_SUFFIX
18
+
19
+ attr_reader :base_url, :topic_base_url, :push_uri, :configuration, :access_token, :access_token_expiry, :httpx
20
+
21
+ # rubocop:disable Metrics/MethodLength
22
+ def initialize(base_url, topic_base_url, project_id, configuration) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
23
+ @base_url = base_url
24
+ @topic_base_url = topic_base_url
25
+ @project_id = project_id
26
+
27
+ @push_uri = URI.join(base_url, V1_ENDPOINT_PREFIX + project_id.to_s + V1_ENDPOINT_SUFFIX)
28
+ @batch_subscribe_uri = create_batch_uri(:subscribe)
29
+ @batch_unsubscribe_uri = create_batch_uri(:unsubscribe)
30
+
31
+ @configuration = configuration.dup
32
+ access_token_response = v1_authorize
33
+ @access_token = access_token_response["access_token"]
34
+ @access_token_expiry = Time.now.utc + access_token_response["expires_in"]
35
+ @httpx = ::HTTPX.plugin(:auth).plugin(:persistent, configuration.httpx_options)
36
+ end
37
+ # rubocop:enable Metrics/MethodLength
38
+
39
+ def push(body, headers: {})
40
+ do_push_request(body, headers)
41
+ end
42
+
43
+ def concurrent_push(bodies, headers: {})
44
+ do_concurrent_push_request(bodies, headers)
45
+ end
46
+
47
+ def subscribe(topic, *instance_ids, query: {}, headers: {})
48
+ do_subscription_request(topic, *instance_ids, :subscribe, query, headers)
49
+ end
50
+
51
+ def concurrent_subscribe(topic, *instance_ids, query: {}, headers: {})
52
+ do_concurrent_subscription_request(topic, *instance_ids, :subscribe, query, headers)
53
+ end
54
+
55
+ def unsubscribe(topic, *instance_ids, query: {}, headers: {})
56
+ do_subscription_request(topic, *instance_ids, :unsubscribe, query, headers)
57
+ end
58
+
59
+ def concurrent_unsubscribe(topic, *instance_ids, query: {}, headers: {})
60
+ do_concurrent_subscription_request(topic, *instance_ids, :unsubscribe, query, headers)
61
+ end
62
+
63
+ private
64
+
65
+ def create_batch_uri(action)
66
+ case action
67
+ when :subscribe
68
+ URI.join(topic_base_url, TOPIC_ENDPOINT_PREFIX + TOPIC_BATCH_SUBSCRIBE_SUFFIX)
69
+ when :unsubscribe
70
+ URI.join(topic_base_url, TOPIC_ENDPOINT_PREFIX + TOPIC_BATCH_UNSUBSCRIBE_SUFFIX)
71
+ else
72
+ raise ArgumentError, "Invalid action: #{action}. Use :subscribe or :unsubscribe."
73
+ end
74
+ end
75
+
76
+ def v1_authorize
77
+ @auth ||= if configuration.json_key_io
78
+ Google::Auth::ServiceAccountCredentials.make_creds(
79
+ json_key_io: prepare_json_key_io,
80
+ scope: configuration.scope
81
+ )
82
+ else
83
+ # from ENV
84
+ Google::Auth::ServiceAccountCredentials.make_creds(scope: configuration.scope)
85
+ end
86
+ @auth.fetch_access_token
87
+ end
88
+
89
+ def prepare_json_key_io
90
+ io = if configuration.json_key_io.respond_to?(:read)
91
+ configuration.json_key_io
92
+ else
93
+ File.open(configuration.json_key_io)
94
+ end
95
+ io.rewind if io.respond_to?(:read)
96
+ io
97
+ end
98
+
99
+ def do_push_request(json, headers)
100
+ access_token_refresh
101
+ send_post_request(@push_uri, json, headers)
102
+ end
103
+
104
+ def do_concurrent_push_request(bodies, headers)
105
+ access_token_refresh
106
+ requests = bodies.map { |body| [:post, @push_uri.to_s, { json: body, headers: }] }
107
+ send_concurrent_post_request(requests)
108
+ end
109
+
110
+ def prepare_subscription_request(action, query, headers)
111
+ access_token_refresh
112
+ headers["access_token_auth"] = "true"
113
+ uri = (action == :subscribe ? @batch_subscribe_uri.dup : @batch_unsubscribe_uri).dup
114
+ uri.query = URI.encode_www_form(query) unless query.empty?
115
+ [uri, headers]
116
+ end
117
+
118
+ def do_subscription_request(topic, *instance_ids, action, query, headers)
119
+ uri, headers = prepare_subscription_request(action, query, headers)
120
+ send_post_request(uri, make_subscription_body(topic, *instance_ids), headers)
121
+ end
122
+
123
+ def do_concurrent_subscription_request(topic, *instance_ids, action, query, headers)
124
+ uri, headers = prepare_subscription_request(action, query, headers)
125
+ requests = instance_ids.map do |instance_id|
126
+ [:post, uri.to_s, { json: make_subscription_body(topic, instance_id), headers: }]
127
+ end
128
+ send_concurrent_post_request(requests)
129
+ end
130
+
131
+ def make_subscription_body(topic, *instance_ids)
132
+ topic = topic.start_with?("/topics/") ? topic : "/topics/#{topic}"
133
+ {
134
+ to: topic,
135
+ registration_tokens: instance_ids
136
+ }
137
+ end
138
+
139
+ def send_post_request(uri, json, headers)
140
+ httpx.bearer_auth(access_token).post(uri.to_s, json:, headers:).raise_for_status
141
+ rescue HTTPX::Error => e
142
+ raise Ffccmmx::HTTPXError, cause: e
143
+ rescue StandardError => e
144
+ raise Ffccmmx::Error, cause: e
145
+ end
146
+
147
+ def send_concurrent_post_request(requests)
148
+ httpx.bearer_auth(access_token).request(requests).map { |response| Ffccmmx::Response.new(response) }
149
+ end
150
+
151
+ def access_token_refresh
152
+ # https://cloud.google.com/docs/authentication/token-types#at-lifetime
153
+ # By default, access tokens are good for 1 hour (3,600 seconds).
154
+ # When the access token has expired, your token management code must get a new one.
155
+ return if access_token_expiry > Time.now.utc + 300
156
+
157
+ access_token_response = v1_authorize
158
+ @access_token = access_token_response["access_token"]
159
+ @access_token_expiry = Time.now.utc + access_token_response["expires_in"]
160
+ end
161
+ end
162
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ffccmmx
4
+ class Configuration
5
+ attr_accessor :scope, :json_key_io, :httpx_options
6
+
7
+ def initialize
8
+ @scope = ["https://www.googleapis.com/auth/firebase.messaging"]
9
+
10
+ # set file path
11
+ @json_key_io = nil
12
+
13
+ # Or Environment Variable
14
+ # ENV['GOOGLE_ACCOUNT_TYPE'] = 'service_account'
15
+ # ENV['GOOGLE_CLIENT_ID'] = '000000000000000000000'
16
+ # ENV['GOOGLE_CLIENT_EMAIL'] = 'xxxx@xxxx.iam.gserviceaccount.com'
17
+ # ENV['GOOGLE_PRIVATE_KEY'] = '-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n'
18
+ @httpx_options = nil
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ffccmmx
4
+ class Error < StandardError; end
5
+
6
+ class HTTPXError < Error; end
7
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ffccmmx
4
+ class Response
5
+ def initialize(response)
6
+ @response = response
7
+ end
8
+
9
+ def value
10
+ @response.raise_for_status
11
+ rescue HTTPX::Error => e
12
+ raise Ffccmmx::HTTPXError, cause: e
13
+ rescue StandardError => e
14
+ raise Ffccmmx::Error, cause: e
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ffccmmx
4
+ VERSION = "0.1.0"
5
+ end
data/lib/ffccmmx.rb ADDED
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "ffccmmx/version"
4
+ require_relative "ffccmmx/client"
5
+ require_relative "ffccmmx/configuration"
6
+
7
+ module Ffccmmx
8
+ BASE_URL = "https://fcm.googleapis.com"
9
+ TOPIC_BASE_URL = "https://iid.googleapis.com"
10
+ private_constant :BASE_URL, :TOPIC_BASE_URL
11
+
12
+ class << self
13
+ attr_writer :configuration
14
+
15
+ def build(project_id, base_url: BASE_URL, topic_base_url: TOPIC_BASE_URL)
16
+ ::Ffccmmx::Client.new(base_url, topic_base_url, project_id, configuration)
17
+ end
18
+ alias new build
19
+
20
+ def configuration
21
+ reset_configuration unless @configuration
22
+
23
+ @configuration
24
+ end
25
+
26
+ def reset_configuration
27
+ @configuration = ::Ffccmmx::Configuration.new
28
+ end
29
+
30
+ def configure
31
+ yield(configuration)
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,16 @@
1
+ module Ffccmmx
2
+ class Client
3
+ def initialize: (String, String, String, Configuration) -> void
4
+ def push: (Object,?headers: Hash[Symbol,untyped] ) -> HTTPX::Response
5
+
6
+ def concurrent_push: (Array[Object], ?headers: Hash[Symbol, untyped]) -> untyped
7
+
8
+ def subscribe: (String, *String,?query: Enumerable[untyped], ?headers: Hash[Symbol,untyped] ) -> HTTPX::Response
9
+
10
+ def concurrent_subscribe: (Array[String], *String,?query: Enumerable[untyped], ?headers: Hash[Symbol,untyped] ) -> HTTPX::Response
11
+
12
+ def unsubscribe: (String, *String ,?query: Enumerable[untyped], ?headers: Hash[Symbol,untyped] ) -> HTTPX::Response
13
+
14
+ def concurrent_unsubscribe: (Array[String], *String,?query: Enumerable[untyped], ?headers: Hash[Symbol,untyped] ) -> HTTPX::Response
15
+ end
16
+ end
@@ -0,0 +1,11 @@
1
+ module Ffccmmx
2
+ class Configuration
3
+ @json_key_io: IO?
4
+ @scope: Array[String]
5
+ @httpx_options: HTTPX::Options? | Hash[Symbol, untyped]?
6
+
7
+ attr_accessor json_key_io: IO? | StringIO?
8
+ attr_accessor scope: Array[String]
9
+ attr_accessor httpx_options: HTTPX::Options? | Hash[Symbol, untyped]?
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ module Ffccmmx
2
+ class Response
3
+ def value: -> HTTPX::Response
4
+ end
5
+ end
data/sig/ffccmmx.rbs ADDED
@@ -0,0 +1,10 @@
1
+ module Ffccmmx
2
+ VERSION: String
3
+
4
+ def self.build: (String, ?base_url: String, ?topic_base_url: String)-> Client
5
+ def self.new: (String, ?base_url: String, ?topic_base_url: String)-> Client
6
+
7
+ def self.configuration: () -> Configuration
8
+ def self.reset_configuration: () -> Configuration
9
+ def self.configure: () { (Configuration) -> void } -> void
10
+ end
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ffccmmx
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - anatofuz
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 1980-01-01 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: google-apis-identitytoolkit_v3
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: 0.18.0
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: 0.18.0
26
+ - !ruby/object:Gem::Dependency
27
+ name: httpx
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '1.5'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.5'
40
+ description: FCM API wrapper, supports HTTP/2 using httpx gem. This gem is based on
41
+ fcmpush gem.
42
+ email:
43
+ - anatofuz@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".rspec"
49
+ - ".rubocop.yml"
50
+ - CHANGELOG.md
51
+ - CODE_OF_CONDUCT.md
52
+ - LICENSE.txt
53
+ - README.md
54
+ - Rakefile
55
+ - lib/ffccmmx.rb
56
+ - lib/ffccmmx/client.rb
57
+ - lib/ffccmmx/configuration.rb
58
+ - lib/ffccmmx/exceptions.rb
59
+ - lib/ffccmmx/response.rb
60
+ - lib/ffccmmx/version.rb
61
+ - sig/ffccmmx.rbs
62
+ - sig/ffccmmx/client.rbs
63
+ - sig/ffccmmx/configuration.rbs
64
+ - sig/ffccmmx/response.rbs
65
+ homepage: https://github.com/AnaTofuZ/ffccmmx
66
+ licenses:
67
+ - MIT
68
+ metadata:
69
+ homepage_uri: https://github.com/AnaTofuZ/ffccmmx
70
+ source_code_uri: https://github.com/AnaTofuZ/ffccmmx
71
+ changelog_uri: https://github.com/AnaTofuZ/ffccmmx/blob/main/CHANGELOG.md
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.0
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.6.7
87
+ specification_version: 4
88
+ summary: Firebase Cloud Messaging API wrapper for ruby, supports HTTP/2 using httpx
89
+ gem, based fcmpush
90
+ test_files: []