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 +4 -4
- data/.rubocop.yml +10 -0
- data/CHANGELOG.md +4 -0
- data/README.md +15 -4
- data/lib/ffccmmx/client.rb +4 -0
- data/lib/ffccmmx/exceptions.rb +23 -0
- data/lib/ffccmmx/response.rb +6 -0
- data/lib/ffccmmx/version.rb +1 -1
- data/sig/ffccmmx/client.rbs +2 -2
- data/sig/ffccmmx/exceptions.rbs +9 -0
- metadata +30 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '09626f45c71c010b2ce077e7d157fb44303f4a6ae4d665495777fd5e55a3db8c'
|
4
|
+
data.tar.gz: 869d953e07906287046ae010af36b28e829c0ded358866eccd794c9ef77436c3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f4117c3bf719196e8eeaa9b63b08c289d4f1404f351c5470558ad0b22cdc9f75959ca033d3dd559121a363597d899fac8b86fd2a8f95ad587d1429c46d0f337e
|
7
|
+
data.tar.gz: '0956a194ad06f27940b5e50d06b7d72e48004fbe9d7fbc51efcc62474fef1c7b1cc1164b3bb23f6da568791a3e65ca6094248ea5d971e986cbe5f8510370f998'
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
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
|
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
|
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.
|
data/lib/ffccmmx/client.rb
CHANGED
@@ -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
|
data/lib/ffccmmx/exceptions.rb
CHANGED
@@ -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
|
data/lib/ffccmmx/response.rb
CHANGED
@@ -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
|
data/lib/ffccmmx/version.rb
CHANGED
data/sig/ffccmmx/client.rbs
CHANGED
@@ -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: (
|
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: (
|
14
|
+
def concurrent_unsubscribe: (String, *String,?query: Enumerable[untyped], ?headers: Hash[Symbol,untyped] ) -> HTTPX::Response
|
15
15
|
end
|
16
16
|
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.
|
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:
|