ffccmmx 0.1.0 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6f3a989f55da2e1b9187f012bb1bf4571504f0e8dd1cacab4c8ac3e8bd26648b
4
- data.tar.gz: 38cbd21555d467bb2c3f023c102e810a87dea0ac2357eac7405874d924d2b8f0
3
+ metadata.gz: '09626f45c71c010b2ce077e7d157fb44303f4a6ae4d665495777fd5e55a3db8c'
4
+ data.tar.gz: 869d953e07906287046ae010af36b28e829c0ded358866eccd794c9ef77436c3
5
5
  SHA512:
6
- metadata.gz: f433427d542b61b7c959994cb3420bd6eccf4228306a786ef48baf72918cbe3d22aa67bb2c5fbc86e7caf54d030f07ff5fc9c568b97063dd5ce7a3f82f1f90f2
7
- data.tar.gz: c5cca8df39b59e5abfb61e1a934588cd547615c3861ede7b8ba7feb032441de5bfc073f9d865075819ddec1ec50442beef07e730e8fd80b07e06fb11b80bf97c
6
+ metadata.gz: f4117c3bf719196e8eeaa9b63b08c289d4f1404f351c5470558ad0b22cdc9f75959ca033d3dd559121a363597d899fac8b86fd2a8f95ad587d1429c46d0f337e
7
+ data.tar.gz: '0956a194ad06f27940b5e50d06b7d72e48004fbe9d7fbc51efcc62474fef1c7b1cc1164b3bb23f6da568791a3e65ca6094248ea5d971e986cbe5f8510370f998'
data/.rubocop.yml CHANGED
@@ -16,3 +16,13 @@ Metrics/ClassLength:
16
16
  Metrics/BlockLength:
17
17
  Exclude:
18
18
  - 'spec/**/*'
19
+ - 'ffccmmx.gemspec'
20
+
21
+
22
+ Metrics/MethodLength:
23
+ Exclude:
24
+ - 'spec/**/*'
25
+
26
+ Style/MultilineBlockChain:
27
+ Exclude:
28
+ - 'spec/**/*'
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.2.0] - 2025-07-18
4
+
5
+ - Add HTTPXRetryableError
6
+
3
7
  ## [0.1.0] - 2025-06-20
4
8
 
5
9
  - Initial release
data/README.md CHANGED
@@ -7,18 +7,16 @@ By leveraging httpx, this gem enables HTTP/2 communication while maintaining an
7
7
 
8
8
  ## Installation
9
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
10
  Install the gem and add to the application's Gemfile by executing:
13
11
 
14
12
  ```bash
15
- bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
13
+ bundle add ffccmmx
16
14
  ```
17
15
 
18
16
  If bundler is not being used to manage dependencies, install the gem by executing:
19
17
 
20
18
  ```bash
21
- gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
19
+ gem install ffccmmx
22
20
  ```
23
21
 
24
22
  ## Usage
@@ -137,6 +135,19 @@ response = @client.unsubscribe('/topics/test_topic', device_token)
137
135
  response = @client.unsubscribe('/topics/test_topic', *device_tokens)
138
136
  ```
139
137
 
138
+ ## Error Response
139
+
140
+ `Ffccmmx::HTTPXRetryableError` is returned, you can use the retry_time method to get a Time object indicating when the next request can be executed.
141
+ If the request has already been attempted multiple times, you can pass the attempt count as an argument, and it will be taken into account even if the Retry-After header is not present in the response.
142
+
143
+ ```ruby
144
+ begin
145
+ @client.push(notification_message)
146
+ rescue Ffccmmx::HTTPXRetryableError => e
147
+ puts "Retry after: #{e.retry_time}"
148
+ end
149
+ ```
150
+
140
151
  ## Development
141
152
 
142
153
  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.
@@ -139,6 +139,10 @@ module Ffccmmx
139
139
  def send_post_request(uri, json, headers)
140
140
  httpx.bearer_auth(access_token).post(uri.to_s, json:, headers:).raise_for_status
141
141
  rescue HTTPX::Error => e
142
+ if Ffccmmx::HTTPXRetryableError.retryable_error?(e)
143
+ raise Ffccmmx::HTTPXRetryableError, response: e.response, cause: e
144
+ end
145
+
142
146
  raise Ffccmmx::HTTPXError, cause: e
143
147
  rescue StandardError => e
144
148
  raise Ffccmmx::Error, cause: e
@@ -4,4 +4,27 @@ module Ffccmmx
4
4
  class Error < StandardError; end
5
5
 
6
6
  class HTTPXError < Error; end
7
+
8
+ class HTTPXRetryableError < HTTPXError
9
+ attr_reader :response
10
+
11
+ RETRYABLE_STATUS_CODES = [408, 429, 500, 502, 503, 504].freeze
12
+ private_constant :RETRYABLE_STATUS_CODES
13
+ def self.retryable_error?(error)
14
+ return false unless error.respond_to?(:response)
15
+ return false if error.response.nil?
16
+
17
+ RETRYABLE_STATUS_CODES.include?(error.response.status)
18
+ end
19
+
20
+ def initialize(response)
21
+ @response = response
22
+ super()
23
+ end
24
+
25
+ def retry_time(count: 1)
26
+ retry_seconds = response.headers["retry-after"] ? response.headers["retry-after"].to_i : 2**count
27
+ Time.now + retry_seconds
28
+ end
29
+ end
7
30
  end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "ffccmmx/exceptions"
4
+
3
5
  module Ffccmmx
4
6
  class Response
5
7
  def initialize(response)
@@ -9,6 +11,10 @@ module Ffccmmx
9
11
  def value
10
12
  @response.raise_for_status
11
13
  rescue HTTPX::Error => e
14
+ if Ffccmmx::HTTPXRetryableError.retryable_error?(e)
15
+ raise Ffccmmx::HTTPXRetryableError, response: e.response, cause: e
16
+ end
17
+
12
18
  raise Ffccmmx::HTTPXError, cause: e
13
19
  rescue StandardError => e
14
20
  raise Ffccmmx::Error, cause: e
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Ffccmmx
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
@@ -7,10 +7,10 @@ module Ffccmmx
7
7
 
8
8
  def subscribe: (String, *String,?query: Enumerable[untyped], ?headers: Hash[Symbol,untyped] ) -> HTTPX::Response
9
9
 
10
- def concurrent_subscribe: (Array[String], *String,?query: Enumerable[untyped], ?headers: Hash[Symbol,untyped] ) -> HTTPX::Response
10
+ def concurrent_subscribe: (String, *String,?query: Enumerable[untyped], ?headers: Hash[Symbol,untyped] ) -> HTTPX::Response
11
11
 
12
12
  def unsubscribe: (String, *String ,?query: Enumerable[untyped], ?headers: Hash[Symbol,untyped] ) -> HTTPX::Response
13
13
 
14
- def concurrent_unsubscribe: (Array[String], *String,?query: Enumerable[untyped], ?headers: Hash[Symbol,untyped] ) -> HTTPX::Response
14
+ def concurrent_unsubscribe: (String, *String,?query: Enumerable[untyped], ?headers: Hash[Symbol,untyped] ) -> HTTPX::Response
15
15
  end
16
16
  end
@@ -0,0 +1,9 @@
1
+ module Ffccmmx
2
+ class HTTPXRetryableError < HTTPX::Error
3
+ attr_reader response: HTTPX::Response
4
+
5
+ def self.retryable_error?:(HTTPX::Error) -> bool
6
+
7
+ def retry_time:(?count: Integer) -> Time
8
+ end
9
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ffccmmx
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - anatofuz
@@ -37,6 +37,34 @@ dependencies:
37
37
  - - "~>"
38
38
  - !ruby/object:Gem::Version
39
39
  version: '1.5'
40
+ - !ruby/object:Gem::Dependency
41
+ name: timecop
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '0.9'
47
+ type: :development
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '0.9'
54
+ - !ruby/object:Gem::Dependency
55
+ name: webmock
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '3.25'
61
+ type: :development
62
+ prerelease: false
63
+ version_requirements: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '3.25'
40
68
  description: FCM API wrapper, supports HTTP/2 using httpx gem. This gem is based on
41
69
  fcmpush gem.
42
70
  email:
@@ -61,6 +89,7 @@ files:
61
89
  - sig/ffccmmx.rbs
62
90
  - sig/ffccmmx/client.rbs
63
91
  - sig/ffccmmx/configuration.rbs
92
+ - sig/ffccmmx/exceptions.rbs
64
93
  - sig/ffccmmx/response.rbs
65
94
  homepage: https://github.com/AnaTofuZ/ffccmmx
66
95
  licenses: