philiprehberger-http_client 0.8.2 → 0.9.1

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: ad967beaec9e64b19f5f3ff422942f5d74af63c347eec2e4b7fa61b1038d5eea
4
- data.tar.gz: 5d16323e87ea653e03069fbf53800840b9f6a0bef8c6dc939fa9ec8a1ec3d54e
3
+ metadata.gz: 87104396621af222e4e5c94c6f7bdaedbfd6ff95ad89d9e147e7980ab33d868f
4
+ data.tar.gz: 9b814c9ded6a9792d4dd782343e9b622790dc0d6cd86c6979b7e54c300031e02
5
5
  SHA512:
6
- metadata.gz: 27f4f025e16759d0403e121164843047a582057e94874be251d167ad585401dc6125eb88960573bb25b1e9c2e0f8c012ef79548f1c963e2d29910fb1a4b7843d
7
- data.tar.gz: d78db1e5fb6f70df4cdfef60f5339477c64a4a50f568f89dd6d10b32ee187ac7307543347b952caeeb30983c8fdc92a207ef25823e4b53fcab15436400adf3ed
6
+ metadata.gz: 1e8c83eff3473cd63ea842deb56a7660aeb3fcf3139ba4ae22da7f279f45d8e9686a1e4091dea1e583314c1c682d32f4dab9fb0082521841fbd9cb8825a545e3
7
+ data.tar.gz: 58b943703382d92960828bf002b7e00e48e45ffcc1a27b8dfaae4ece0d8b047181f440272fffac0bb87bbb10dfc1c02d2c07e732d291faadec83b0b200239a31
data/CHANGELOG.md CHANGED
@@ -7,6 +7,17 @@ and this gem adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.9.1] - 2026-04-23
11
+
12
+ ### Changed
13
+ - Added YARD documentation on `Philiprehberger::HttpClient.new` and `Philiprehberger::HttpClient.open` module methods.
14
+ - Completed Keep a Changelog version link references for all released versions.
15
+
16
+ ## [0.9.0] - 2026-04-20
17
+
18
+ ### Added
19
+ - `Response#json?` — returns `true` when the `Content-Type` header advertises JSON, including RFC 6838 `+json` structured-syntax suffixes (e.g. `application/problem+json`). Case-insensitive header lookup; charset parameters are ignored.
20
+
10
21
  ## [0.8.2] - 2026-04-16
11
22
 
12
23
  ### Added
@@ -166,5 +177,27 @@ and this gem adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
166
177
  - Response wrapper with `ok?` and `json` convenience methods
167
178
  - Zero dependencies — built on Ruby stdlib `net/http`
168
179
 
169
- [0.2.0]: https://github.com/philiprehberger/rb-http-client/releases/tag/v0.2.0
180
+ [Unreleased]: https://github.com/philiprehberger/rb-http-client/compare/v0.9.1...HEAD
181
+ [0.9.1]: https://github.com/philiprehberger/rb-http-client/compare/v0.9.0...v0.9.1
182
+ [0.9.0]: https://github.com/philiprehberger/rb-http-client/compare/v0.8.2...v0.9.0
183
+ [0.8.2]: https://github.com/philiprehberger/rb-http-client/compare/v0.8.1...v0.8.2
184
+ [0.8.1]: https://github.com/philiprehberger/rb-http-client/compare/v0.8.0...v0.8.1
185
+ [0.8.0]: https://github.com/philiprehberger/rb-http-client/compare/v0.7.0...v0.8.0
186
+ [0.7.0]: https://github.com/philiprehberger/rb-http-client/compare/v0.6.1...v0.7.0
187
+ [0.6.1]: https://github.com/philiprehberger/rb-http-client/compare/v0.6.0...v0.6.1
188
+ [0.6.0]: https://github.com/philiprehberger/rb-http-client/compare/v0.5.0...v0.6.0
189
+ [0.5.0]: https://github.com/philiprehberger/rb-http-client/compare/v0.4.7...v0.5.0
190
+ [0.4.7]: https://github.com/philiprehberger/rb-http-client/compare/v0.4.6...v0.4.7
191
+ [0.4.6]: https://github.com/philiprehberger/rb-http-client/compare/v0.4.5...v0.4.6
192
+ [0.4.5]: https://github.com/philiprehberger/rb-http-client/compare/v0.4.4...v0.4.5
193
+ [0.4.4]: https://github.com/philiprehberger/rb-http-client/compare/v0.4.3...v0.4.4
194
+ [0.4.3]: https://github.com/philiprehberger/rb-http-client/compare/v0.4.2...v0.4.3
195
+ [0.4.2]: https://github.com/philiprehberger/rb-http-client/compare/v0.4.1...v0.4.2
196
+ [0.4.1]: https://github.com/philiprehberger/rb-http-client/compare/v0.4.0...v0.4.1
197
+ [0.4.0]: https://github.com/philiprehberger/rb-http-client/compare/v0.3.3...v0.4.0
198
+ [0.3.3]: https://github.com/philiprehberger/rb-http-client/compare/v0.3.2...v0.3.3
199
+ [0.3.2]: https://github.com/philiprehberger/rb-http-client/compare/v0.3.1...v0.3.2
200
+ [0.3.1]: https://github.com/philiprehberger/rb-http-client/compare/v0.3.0...v0.3.1
201
+ [0.3.0]: https://github.com/philiprehberger/rb-http-client/compare/v0.2.0...v0.3.0
202
+ [0.2.0]: https://github.com/philiprehberger/rb-http-client/compare/v0.1.0...v0.2.0
170
203
  [0.1.0]: https://github.com/philiprehberger/rb-http-client/releases/tag/v0.1.0
data/README.md CHANGED
@@ -493,6 +493,7 @@ client.head("/resource")
493
493
  | `headers` | Hash | Response headers |
494
494
  | `ok?` | Boolean | `true` if status is 200-299 |
495
495
  | `json` | Hash | Parsed JSON body |
496
+ | `json?` | Boolean | `true` if `Content-Type` is `application/json` or `+json` suffix |
496
497
  | `streaming?` | Boolean | `true` if response was streamed |
497
498
  | `metrics` | Metrics | Request timing breakdown (total_time, first_byte_time, etc.) |
498
499
  | `redirects` | Array | Redirect chain URLs (empty if no redirects) |
@@ -44,6 +44,20 @@ module Philiprehberger
44
44
  @json ||= JSON.parse(body)
45
45
  end
46
46
 
47
+ # Returns true if the `Content-Type` response header advertises JSON.
48
+ # Matches `application/json`, `application/problem+json`, and any
49
+ # other `+json` structured-syntax suffix defined by RFC 6838.
50
+ # Header lookup is case-insensitive.
51
+ #
52
+ # @return [Boolean]
53
+ def json?
54
+ header = headers.find { |k, _| k.to_s.downcase == 'content-type' }
55
+ return false unless header
56
+
57
+ value = header[1].to_s.downcase.split(';').first.to_s.strip
58
+ value == 'application/json' || value.end_with?('+json')
59
+ end
60
+
47
61
  # Returns request timing metrics (nil if not available).
48
62
  #
49
63
  # @return [Metrics, nil]
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Philiprehberger
4
4
  module HttpClient
5
- VERSION = '0.8.2'
5
+ VERSION = '0.9.1'
6
6
  end
7
7
  end
@@ -15,18 +15,28 @@ require_relative 'http_client/client'
15
15
 
16
16
  module Philiprehberger
17
17
  module HttpClient
18
- # Convenience constructor.
18
+ # Convenience constructor that instantiates a new {Client}.
19
19
  #
20
- # @param options [Hash] Forwarded to {Client#initialize}
21
- # @return [Client]
20
+ # This is a thin wrapper around {Client.new} so callers can write
21
+ # `Philiprehberger::HttpClient.new(base_url: '...')` without reaching
22
+ # into the nested {Client} constant.
23
+ #
24
+ # @param options [Hash] Keyword options forwarded to {Client#initialize}
25
+ # (e.g. `base_url:`, `headers:`, `timeout:`, `retries:`, `pool:`, `cache:`)
26
+ # @return [Client] a new configured client instance
22
27
  def self.new(**options)
23
28
  Client.new(**options)
24
29
  end
25
30
 
26
- # Block form — creates a client, yields it, and ensures cleanup.
31
+ # Block form constructor — creates a {Client}, yields it, and guarantees
32
+ # cleanup by calling `#close` in an `ensure` block when the block exits.
33
+ #
34
+ # Equivalent to {Client.open}; prefer this form when you want automatic
35
+ # connection pool draining without manually calling `#close`.
27
36
  #
28
- # @param options [Hash] Forwarded to {Client#initialize}
29
- # @yield [Client]
37
+ # @param options [Hash] Keyword options forwarded to {Client#initialize}
38
+ # @yield [client] yields the client instance to the block
39
+ # @yieldparam client [Client] the newly created client
30
40
  # @return [Object] the return value of the block
31
41
  def self.open(...)
32
42
  Client.open(...)
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.8.2
4
+ version: 0.9.1
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-04-16 00:00:00.000000000 Z
11
+ date: 2026-04-23 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.