philiprehberger-http_client 0.9.1 → 0.11.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/CHANGELOG.md +21 -2
- data/README.md +20 -3
- data/lib/philiprehberger/http_client/response.rb +29 -4
- data/lib/philiprehberger/http_client/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0e7ebec429195d4e674adf7836c916e2e9fa40938c1fe79209d8c10ad4c0df5d
|
|
4
|
+
data.tar.gz: 94fd543943abe6573cb5ce9bdc686bc5c7aa79858b312aab251a4851c4f9718f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ba7e2ba9e18a068391353b8164393deb5205faa86367fffb1101b782ca08e72d1db2c8eecf8343621062b61629268c09254c9a597d333da59657979903090882
|
|
7
|
+
data.tar.gz: 2ab2ebe6ab143e5417e7939905c9b971bce1237cf434f0d4a360f912ab02d37468affa783368297ed11e1de44689847239a55f9fbd7e51864c9ba7ec6be595fa
|
data/CHANGELOG.md
CHANGED
|
@@ -3,10 +3,27 @@
|
|
|
3
3
|
All notable changes to this gem will be documented in this file.
|
|
4
4
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
|
-
and this
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.11.0] - 2026-05-13
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- `Response#header(name)` — case-insensitive header value accessor. Returns `nil` when the header is absent.
|
|
14
|
+
|
|
15
|
+
### Changed
|
|
16
|
+
- `Response#json?` now delegates to `Response#header` for Content-Type lookup.
|
|
17
|
+
|
|
18
|
+
## [0.10.0] - 2026-05-07
|
|
19
|
+
|
|
20
|
+
### Added
|
|
21
|
+
- `Response#client_error?` — returns true for 4xx status codes.
|
|
22
|
+
- `Response#server_error?` — returns true for 5xx status codes.
|
|
23
|
+
|
|
24
|
+
### Changed
|
|
25
|
+
- CHANGELOG header wording aligned with the standard template ("this project adheres" instead of "this gem adheres").
|
|
26
|
+
|
|
10
27
|
## [0.9.1] - 2026-04-23
|
|
11
28
|
|
|
12
29
|
### Changed
|
|
@@ -177,7 +194,9 @@ and this gem adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
|
|
177
194
|
- Response wrapper with `ok?` and `json` convenience methods
|
|
178
195
|
- Zero dependencies — built on Ruby stdlib `net/http`
|
|
179
196
|
|
|
180
|
-
[Unreleased]: https://github.com/philiprehberger/rb-http-client/compare/v0.
|
|
197
|
+
[Unreleased]: https://github.com/philiprehberger/rb-http-client/compare/v0.11.0...HEAD
|
|
198
|
+
[0.11.0]: https://github.com/philiprehberger/rb-http-client/compare/v0.10.0...v0.11.0
|
|
199
|
+
[0.10.0]: https://github.com/philiprehberger/rb-http-client/compare/v0.9.1...v0.10.0
|
|
181
200
|
[0.9.1]: https://github.com/philiprehberger/rb-http-client/compare/v0.9.0...v0.9.1
|
|
182
201
|
[0.9.0]: https://github.com/philiprehberger/rb-http-client/compare/v0.8.2...v0.9.0
|
|
183
202
|
[0.8.2]: https://github.com/philiprehberger/rb-http-client/compare/v0.8.1...v0.8.2
|
data/README.md
CHANGED
|
@@ -38,9 +38,11 @@ require "philiprehberger/http_client"
|
|
|
38
38
|
client = Philiprehberger::HttpClient.new(base_url: "https://api.example.com")
|
|
39
39
|
|
|
40
40
|
response = client.get("/users", params: { page: 1 })
|
|
41
|
-
puts response.status
|
|
42
|
-
puts response.ok?
|
|
43
|
-
puts response.
|
|
41
|
+
puts response.status # => 200
|
|
42
|
+
puts response.ok? # => true
|
|
43
|
+
puts response.client_error? # => false (true for 4xx)
|
|
44
|
+
puts response.server_error? # => false (true for 5xx)
|
|
45
|
+
puts response.json # => [{"id" => 1, "name" => "Alice"}, ...]
|
|
44
46
|
```
|
|
45
47
|
|
|
46
48
|
### POST with JSON body
|
|
@@ -422,6 +424,18 @@ client.delete("/resource/1")
|
|
|
422
424
|
client.head("/resource")
|
|
423
425
|
```
|
|
424
426
|
|
|
427
|
+
### Case-insensitive header lookup
|
|
428
|
+
|
|
429
|
+
`Response#header` returns the value for a header regardless of capitalization, returning `nil` when it is missing:
|
|
430
|
+
|
|
431
|
+
```ruby
|
|
432
|
+
response = client.head("/resource")
|
|
433
|
+
|
|
434
|
+
response.header("Content-Type") # => "application/json"
|
|
435
|
+
response.header("etag") # works for any casing
|
|
436
|
+
response.header("X-Missing") # => nil
|
|
437
|
+
```
|
|
438
|
+
|
|
425
439
|
## API
|
|
426
440
|
|
|
427
441
|
### `Philiprehberger::HttpClient.new(**options)`
|
|
@@ -491,7 +505,10 @@ client.head("/resource")
|
|
|
491
505
|
| `status` | Integer | HTTP status code |
|
|
492
506
|
| `body` | String | Raw response body (`nil` if streamed) |
|
|
493
507
|
| `headers` | Hash | Response headers |
|
|
508
|
+
| `header(name)` | String | Header value for `name` (case-insensitive), `nil` if absent |
|
|
494
509
|
| `ok?` | Boolean | `true` if status is 200-299 |
|
|
510
|
+
| `client_error?` | Boolean | Returns true for 4xx status codes |
|
|
511
|
+
| `server_error?` | Boolean | Returns true for 5xx status codes |
|
|
495
512
|
| `json` | Hash | Parsed JSON body |
|
|
496
513
|
| `json?` | Boolean | `true` if `Content-Type` is `application/json` or `+json` suffix |
|
|
497
514
|
| `streaming?` | Boolean | `true` if response was streamed |
|
|
@@ -29,6 +29,20 @@ module Philiprehberger
|
|
|
29
29
|
status >= 200 && status < 300
|
|
30
30
|
end
|
|
31
31
|
|
|
32
|
+
# Returns true if the status code is in the 4xx range.
|
|
33
|
+
#
|
|
34
|
+
# @return [Boolean]
|
|
35
|
+
def client_error?
|
|
36
|
+
status >= 400 && status < 500
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# Returns true if the status code is in the 5xx range.
|
|
40
|
+
#
|
|
41
|
+
# @return [Boolean]
|
|
42
|
+
def server_error?
|
|
43
|
+
status >= 500 && status < 600
|
|
44
|
+
end
|
|
45
|
+
|
|
32
46
|
# Returns true if the response was streamed.
|
|
33
47
|
#
|
|
34
48
|
# @return [Boolean]
|
|
@@ -44,6 +58,17 @@ module Philiprehberger
|
|
|
44
58
|
@json ||= JSON.parse(body)
|
|
45
59
|
end
|
|
46
60
|
|
|
61
|
+
# Returns the header value for `name`, matching case-insensitively.
|
|
62
|
+
# Returns `nil` when the header is not present.
|
|
63
|
+
#
|
|
64
|
+
# @param name [String, Symbol] header name (case-insensitive)
|
|
65
|
+
# @return [String, nil]
|
|
66
|
+
def header(name)
|
|
67
|
+
key = name.to_s.downcase
|
|
68
|
+
headers.each { |k, v| return v if k.to_s.downcase == key }
|
|
69
|
+
nil
|
|
70
|
+
end
|
|
71
|
+
|
|
47
72
|
# Returns true if the `Content-Type` response header advertises JSON.
|
|
48
73
|
# Matches `application/json`, `application/problem+json`, and any
|
|
49
74
|
# other `+json` structured-syntax suffix defined by RFC 6838.
|
|
@@ -51,11 +76,11 @@ module Philiprehberger
|
|
|
51
76
|
#
|
|
52
77
|
# @return [Boolean]
|
|
53
78
|
def json?
|
|
54
|
-
|
|
55
|
-
return false unless
|
|
79
|
+
value = header('content-type')
|
|
80
|
+
return false unless value
|
|
56
81
|
|
|
57
|
-
|
|
58
|
-
|
|
82
|
+
primary = value.to_s.downcase.split(';').first.to_s.strip
|
|
83
|
+
primary == 'application/json' || primary.end_with?('+json')
|
|
59
84
|
end
|
|
60
85
|
|
|
61
86
|
# Returns request timing metrics (nil if not available).
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: philiprehberger-http_client
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.11.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Philip Rehberger
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
11
|
+
date: 2026-05-14 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: A zero-dependency HTTP client built on Ruby's net/http with automatic
|
|
14
14
|
retries, request/response interceptors, and a clean API for JSON services.
|