Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow disabling retries #36

Merged
merged 4 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@ jobs:

strategy:
matrix:
ruby-version: ['3.1', '3.0', '2.7']
ruby-version:
- '3.3'
- '3.2'
- '3.1'
- '3.0'

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Ruby ${{ matrix.ruby-version }}
uses: ruby/setup-ruby@359bebbc29cbe6c87da6bc9ea3bc930432750108
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby-version }}
- name: Install dependencies
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 4.3.0

* Add support for disabling retries on timeout for `GET` and `HEAD` requests

## 4.2.0

* Bump ruby required version from 2.6 to 2.7
Expand Down
10 changes: 5 additions & 5 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
grac (4.1.0)
grac (4.3.0)
oj (~> 3.13.23)
typhoeus (~> 1)

Expand All @@ -15,8 +15,8 @@ GEM
ffi (>= 1.15.0)
ffi (1.15.5)
oj (3.13.23)
rack (3.0.6.1)
rack-test (2.0.2)
rack (3.1.8)
rack-test (2.1.0)
rack (>= 1.3)
rake (13.0.1)
rspec (3.12.0)
Expand All @@ -42,8 +42,8 @@ DEPENDENCIES
benchmark-ips (~> 2.10)
builder (~> 3.2)
grac!
rack (~> 3.0.1)
rack-test (~> 2.0.2)
rack (~> 3.1)
rack-test (~> 2.1)
rake (~> 13.0)
rspec (~> 3.12)

Expand Down
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Loading GeoIP information for `github.com`:
require 'grac'
# => true
geoip_client = Grac::Client.new('http://freegeoip.net/json', timeout: 5)
# => #<Grac::Client:0x000000037f0848 @uri="http://freegeoip.net/json", @options={:connecttimeout=>0.1, :timeout=>15, :params=>{}, :headers=>{"User-Agent"=>"Grac v2.X.X","Content-Type"=>"application/json;charset=utf-8"}, :postprocessing=>{}}>
# => #<Grac::Client:0x000000037f0848 @uri="http://freegeoip.net/json", @options={:connecttimeout=>0.1, :timeout=>15, :params=>{}, :headers=>{"User-Agent"=>"Grac v4.X.X","Content-Type"=>"application/json;charset=utf-8"}, :postprocessing=>{}, :retry_get_head=>true}>
geoip_client.path('/{host}', host: 'github.com').get
# => {"ip"=>"8.8.8.8", "country_code"=>"US", "country_name"=>"United States", "region_code"=>"CA", "region_name"=>"California", "city"=>"Mountain View", "zip_code"=>"94040", "time_zone"=>"America/Los_Angeles", "latitude"=>37.3845, "longitude"=>-122.0881, "metro_code"=>807}
```
Expand All @@ -33,7 +33,7 @@ geoip_client.path('/does/not/exist').get

```ruby
client = geoip_client.set(postprocessing: { '\A(latitude|longitude)\z' => -> (v) { v.to_i } })
# => #<Grac::Client:0x00000003d06378 @uri="http://freegeoip.net/json", @options={:connecttimeout=>0.1, :timeout=>5, :params=>{}, :headers=>{"User-Agent"=>"Grac v2.X.X","Content-Type"=>"application/json;charset=utf-8"}, :postprocessing=>{"\\A(latitude|longitude)\\z"=>#<Proc:0x00000003d06530@(irb):18 (lambda)>}}>
# => #<Grac::Client:0x00000003d06378 @uri="http://freegeoip.net/json", @options={:connecttimeout=>0.1, :timeout=>5, :params=>{}, :headers=>{"User-Agent"=>"Grac v4.X.X","Content-Type"=>"application/json;charset=utf-8"}, :postprocessing=>{"\\A(latitude|longitude)\\z"=>#<Proc:0x00000003d06530@(irb):18 (lambda)>}, :retry_get_head=>true}>
client.path('/github.com').get
# => {"ip"=>"192.30.252.128", "country_code"=>"US", "country_name"=>"United States", "region_code"=>"CA", "region_name"=>"California", "city"=>"San Francisco", "zip_code"=>"94107", "time_zone"=>"America/Los_Angeles", "latitude"=>37, "longitude"=>-122, "metro_code"=>807}
```
Expand Down Expand Up @@ -64,9 +64,10 @@ Available options (shown are the default values):
connecttimeout: 0.1, # in seconds
timeout: 15, # in seconds
params: {}, # default query parameters to be attached to the URL
headers: { "User-Agent" => "Grac v2.X.X", "Content-Type" => "application/json;charset=utf-8" },
headers: { "User-Agent" => "Grac v4.X.X", "Content-Type" => "application/json;charset=utf-8" },
postprocessing: {}, # see below
middleware: [] # see below
middleware: [], # see below
retry_get_head: true, # retrying get and head requests on timeout once
}
```

Expand Down Expand Up @@ -146,7 +147,7 @@ Grac allows you to override options and append to the URI by chaining calls to `

```ruby
client = Grac::Client.new("http://localhost:80", timeout: 1)
# => #<Grac::Client:0x00000003d3dd50 @uri="http://localhost:80", @options={:connecttimeout=>0.1, :timeout=>1, :params=>{}, :headers=>{"User-Agent"=>"Grac v2.X.X","Content-Type"=>"application/json;charset=utf-8"}, :postprocessing=>{}}>
# => #<Grac::Client:0x00000003d3dd50 @uri="http://localhost:80", @options={:connecttimeout=>0.1, :timeout=>1, :params=>{}, :headers=>{"User-Agent"=>"Grac v4.X.X","Content-Type"=>"application/json;charset=utf-8"}, :postprocessing=>{}, :retry_get_head=>true}>
client.set(timeout: 20).path("/v1/users").get(per_page: 1000)
# => [...]
```
Expand Down
4 changes: 2 additions & 2 deletions grac.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'rspec', '~> 3.12'
spec.add_development_dependency 'builder', '~> 3.2'
spec.add_development_dependency 'benchmark-ips', '~> 2.10'
spec.add_development_dependency 'rack', '~> 3.0.1'
spec.add_development_dependency 'rack-test', '~> 2.0.2'
spec.add_development_dependency 'rack', '~> 3.1'
spec.add_development_dependency 'rack-test', '~> 2.1'

spec.add_runtime_dependency 'oj', '~> 3.13.23'
spec.add_runtime_dependency 'typhoeus', '~> 1'
Expand Down
Loading
Loading