Skip to content

Commit 94970f9

Browse files
author
蔡耀賢
committed
Merge branch 'chore/release-2.0.5-maintenance' into 'master'
Prepare 2.0.5 maintenance release. See merge request kdanmobile/shared-code-base/gems/json_requester!22
2 parents 95e834e + 9b1c17b commit 94970f9

12 files changed

Lines changed: 354 additions & 135 deletions

.gitlab-ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,5 @@ to_gem:
3434
- GEM_NAME=json_requester-$RELEASE_VERSION.gem
3535
- gem build json_requester.gemspec
3636
- gem push $GEM_NAME
37-
only:
38-
- /release-\d+\.\d+\.\d+(\.\d+)?/
37+
rules:
38+
- if: '$CI_COMMIT_TAG =~ /^release-\d+\.\d+\.\d+(\.\d+)?$/'

.rubocop.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
plugins:
2+
- rubocop-performance
3+
4+
AllCops:
5+
NewCops: enable
6+
TargetRubyVersion: 3.0
7+
Exclude:
8+
- 'bin/**/*'
9+
- 'pkg/**/*'
10+
- 'vendor/**/*'
11+
12+
Layout/LineLength:
13+
Max: 200
14+
15+
Style/Documentation:
16+
Enabled: false
17+
18+
Metrics/MethodLength:
19+
Max: 25
20+
21+
Metrics/AbcSize:
22+
Max: 25
23+
24+
Metrics/CyclomaticComplexity:
25+
Max: 10
26+
27+
Metrics/PerceivedComplexity:
28+
Max: 10
29+
30+
Metrics/BlockLength:
31+
Exclude:
32+
- 'spec/**/*'
33+
34+
Metrics/ParameterLists:
35+
Max: 10

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
## [2.0.5] - 2026-03-19
2+
- Update json to version `2.19.2` for `CVE-2026-33210` format string injection vulnerability mitigation.
3+
- Move development dependencies from `gemspec` to `Gemfile`.
4+
- Add RuboCop configuration for project linting and exclude `spec/**/*` from `Metrics/BlockLength`.
5+
- Remove the empty RSpec configuration block in `spec_helper`.
6+
- Refresh the README structure and usage examples.
7+
- Add `SECURITY.md` for vulnerability reporting guidelines.
8+
19
## [2.0.4] - 2026-02-10
210
- Update Faraday to version `2.14.1` for SSRF vulnerability warning.
311

Gemfile

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
1+
# frozen_string_literal: true
2+
13
source 'https://rubygems.org'
24

35
gemspec
46

57
# Simple, but flexible HTTP client library, with support for multiple backends.
68
gem 'faraday', '~> 2.14.1'
79
# Perform multipart-post requests using Faraday.
8-
gem 'faraday-multipart', '~> 1.2.0'
10+
gem 'faraday-multipart', '~> 1.2.0'
11+
12+
group :development, :test do
13+
gem 'pry', '~> 0.16.0'
14+
gem 'rspec', '~> 3.13.0'
15+
gem 'rubocop', '~> 1.85.1'
16+
gem 'rubocop-performance', '~> 1.26.1'
17+
gem 'webmock', '~> 3.26', '>= 3.26.0'
18+
end

Gemfile.lock

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
PATH
22
remote: .
33
specs:
4-
json_requester (2.0.4)
4+
json_requester (2.0.5)
55
faraday (~> 2.0, >= 2.0.1)
66
faraday-multipart (~> 1.2.0)
77

88
GEM
99
remote: https://rubygems.org/
1010
specs:
11-
addressable (2.8.8)
11+
addressable (2.8.9)
1212
public_suffix (>= 2.0.2, < 8.0)
13+
ast (2.4.3)
1314
bigdecimal (4.0.1)
1415
coderay (1.1.3)
1516
crack (1.0.1)
@@ -26,17 +27,32 @@ GEM
2627
net-http (~> 0.5)
2728
hashdiff (1.2.1)
2829
io-console (0.8.2)
29-
json (2.18.1)
30+
json (2.19.2)
31+
json-schema (6.2.0)
32+
addressable (~> 2.8)
33+
bigdecimal (>= 3.1, < 5)
34+
language_server-protocol (3.17.0.5)
35+
lint_roller (1.1.0)
3036
logger (1.7.0)
37+
mcp (0.8.0)
38+
json-schema (>= 4.1)
3139
method_source (1.1.0)
3240
multipart-post (2.4.1)
3341
net-http (0.9.1)
3442
uri (>= 0.11.1)
43+
parallel (1.27.0)
44+
parser (3.3.10.2)
45+
ast (~> 2.4.1)
46+
racc
47+
prism (1.9.0)
3548
pry (0.16.0)
3649
coderay (~> 1.1)
3750
method_source (~> 1.0)
3851
reline (>= 0.6.0)
39-
public_suffix (7.0.0)
52+
public_suffix (7.0.5)
53+
racc (1.8.1)
54+
rainbow (3.1.1)
55+
regexp_parser (2.11.3)
4056
reline (0.6.3)
4157
io-console (~> 0.5)
4258
rexml (3.4.4)
@@ -49,12 +65,35 @@ GEM
4965
rspec-expectations (3.13.5)
5066
diff-lcs (>= 1.2.0, < 2.0)
5167
rspec-support (~> 3.13.0)
52-
rspec-mocks (3.13.7)
68+
rspec-mocks (3.13.8)
5369
diff-lcs (>= 1.2.0, < 2.0)
5470
rspec-support (~> 3.13.0)
55-
rspec-support (3.13.6)
71+
rspec-support (3.13.7)
72+
rubocop (1.85.1)
73+
json (~> 2.3)
74+
language_server-protocol (~> 3.17.0.2)
75+
lint_roller (~> 1.1.0)
76+
mcp (~> 0.6)
77+
parallel (~> 1.10)
78+
parser (>= 3.3.0.2)
79+
rainbow (>= 2.2.2, < 4.0)
80+
regexp_parser (>= 2.9.3, < 3.0)
81+
rubocop-ast (>= 1.49.0, < 2.0)
82+
ruby-progressbar (~> 1.7)
83+
unicode-display_width (>= 2.4.0, < 4.0)
84+
rubocop-ast (1.49.1)
85+
parser (>= 3.3.7.2)
86+
prism (~> 1.7)
87+
rubocop-performance (1.26.1)
88+
lint_roller (~> 1.1)
89+
rubocop (>= 1.75.0, < 2.0)
90+
rubocop-ast (>= 1.47.1, < 2.0)
91+
ruby-progressbar (1.13.0)
92+
unicode-display_width (3.2.0)
93+
unicode-emoji (~> 4.1)
94+
unicode-emoji (4.2.0)
5695
uri (1.1.1)
57-
webmock (3.26.1)
96+
webmock (3.26.2)
5897
addressable (>= 2.8.0)
5998
crack (>= 0.3.2)
6099
hashdiff (>= 0.4.0, < 2.0.0)
@@ -68,6 +107,8 @@ DEPENDENCIES
68107
json_requester!
69108
pry (~> 0.16.0)
70109
rspec (~> 3.13.0)
110+
rubocop (~> 1.85.1)
111+
rubocop-performance (~> 1.26.1)
71112
webmock (~> 3.26, >= 3.26.0)
72113

73114
BUNDLED WITH

README.md

Lines changed: 144 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,156 @@
11
# JsonRequester
22

3-
### A Wrapper of Faraday Gem
3+
[![Gem Version](https://badge.fury.io/rb/json_requester.svg?icon=si%3Arubygems)](https://badge.fury.io/rb/json_requester)
44

5-
### Install
5+
`JsonRequester` is a lightweight wrapper around Faraday for sending
6+
JSON, form-encoded, and multipart HTTP requests.
7+
8+
## Requirements
9+
10+
- Ruby `>= 3.0.0`
11+
- Faraday `2.x`
12+
13+
## Installation
14+
15+
### For Faraday 2.x
16+
17+
Install `json_requester` 2.x:
618

7-
If you want to use faraday 1.x version, install json_requester 1.x version:
819
```bash
9-
$ gem install json_requester -v '~> 1.0'
20+
gem install json_requester -v '~> 2.0'
1021
```
1122

12-
If you want to use faraday 2.x version, install json_requester 2.x version:
23+
### For Faraday 1.x
24+
25+
If you still need Faraday 1.x, install `json_requester` 1.x:
26+
1327
```bash
14-
$ gem install json_requester -v '~> 2.0'
28+
gem install json_requester -v '~> 1.0'
29+
```
30+
31+
## Usage
32+
33+
### Initialize a requester
34+
35+
```ruby
36+
host = 'http://httpbingo.org'
37+
38+
requester = JsonRequester.new(
39+
host,
40+
timeout: 120,
41+
user_agent: 'My Agent 1.2'
42+
)
1543
```
1644

17-
### How to Use
45+
Available initialization options:
46+
47+
- `timeout`: request timeout in seconds, default is `60`
48+
- `user_agent`: custom user agent string
49+
- `multipart`: enable multipart request middleware, default is `false`
50+
- `ssl_verify`: enable SSL certificate verification, default is `true`
51+
52+
### Send JSON requests
53+
54+
Use `http_send` for regular JSON-based requests.
55+
56+
- `:get` sends params as query parameters
57+
- other HTTP methods send params as a JSON body
1858

1959
```ruby
20-
# initialize the JsonRequester class
21-
host = 'http://httpbingo.org'
22-
# `timeout` at Faraday gem default is 60 secs.
23-
# `user_agent` at Faraday gem default is like "Faraday v1.10.0", it would be deep_merge at Faraday default setting.
24-
# `multipart` option enables multipart form requests (for file uploads), default is false
25-
# `ssl_verify` controls SSL certificate verification, default is true
26-
requester = JsonRequester.new(host, timeout: 120, user_agent: 'My Agent 1.2')
27-
28-
http_method = :get # :get / :post / :put / :delete
29-
path = ''
30-
headers = { 'Authorization' => 'Bearer token' }
31-
32-
# The `:get` method will use query params;
33-
# Other HTTP methods will use JSON body to request.
34-
params = {
35-
key_1: 'value_1',
36-
key_2: 'value_2'
37-
}
38-
39-
# Request by using JSON body or query params, use the `http_send` method.
40-
# other methods: `form_send`, `multipart_form_send`
41-
# `sort_params` at Faraday gem default is true.
42-
# `content_type_charset` default is 'utf-8', this will add ; charset=utf-8 after `Content-Type` header (ex. `Content-Type=application/json; charset=utf-8`).
43-
# `need_response_header` when set to true will include response headers in the result
44-
res = requester.http_send(http_method, path, params, headers, sort_params: true, content_type_charset: 'utf-8')
45-
46-
# http response code
47-
puts res['status'] # 200, 404, .. etc
48-
# the response JSON body
49-
puts res['body'] # { foo: 'bar' }
50-
# If need_response_header is true, you can access response headers
51-
puts res['headers'] if res.key?('headers')
52-
53-
# For form-encoded requests (application/x-www-form-urlencoded)
54-
form_res = requester.form_send(:post, '/post', params, headers)
55-
56-
# For file uploads or multipart form requests
57-
# First initialize with multipart: true
58-
multipart_requester = JsonRequester.new(host, multipart: true)
59-
60-
# Then prepare your payload with file objects
61-
upload_params = {
62-
file: Faraday::Multipart::FilePart.new('path/to/file.txt', 'text/plain'),
63-
description: 'File upload example'
64-
}
65-
66-
# Send multipart request
67-
upload_res = multipart_requester.multipart_form_send(:post, '/upload_path', upload_params, headers)
68-
```
60+
path = '/post-path'
61+
headers = { 'Authorization' => 'Bearer token' }
62+
params = {
63+
key_1: 'value_1',
64+
key_2: 'value_2'
65+
}
66+
67+
response = requester.http_send(
68+
:post,
69+
path,
70+
params,
71+
headers,
72+
sort_params: true,
73+
content_type_charset: 'utf-8',
74+
need_response_header: true
75+
)
76+
77+
puts response['status']
78+
puts response['body']
79+
puts response['headers'] if response.key?('headers')
80+
```
81+
82+
### Send form-encoded requests
83+
84+
Use `form_send` for `application/x-www-form-urlencoded` requests.
85+
86+
```ruby
87+
path = '/post-path'
88+
headers = { 'Authorization' => 'Bearer token' }
89+
params = {
90+
key_1: 'value_1',
91+
key_2: 'value_2'
92+
}
93+
94+
form_response = requester.form_send(
95+
:post,
96+
path,
97+
params,
98+
headers,
99+
sort_params: true,
100+
need_response_header: true
101+
)
102+
```
103+
104+
### Send multipart requests
105+
106+
Use `multipart_form_send` for file uploads or multipart form data.
107+
108+
```ruby
109+
multipart_requester = JsonRequester.new(host, multipart: true)
110+
111+
upload_params = {
112+
file: Faraday::Multipart::FilePart.new('path/to/file.txt', 'text/plain'),
113+
description: 'File upload example'
114+
}
115+
116+
upload_response = multipart_requester.multipart_form_send(
117+
:post,
118+
'/upload_path',
119+
upload_params,
120+
{ 'Authorization' => 'Bearer token' }
121+
)
122+
```
123+
124+
## Request Methods
125+
126+
- `http_send`: JSON body or query-parameter requests
127+
- `form_send`: form-encoded requests
128+
- `multipart_form_send`: multipart form requests
129+
130+
### Method overview
131+
132+
- `http_send`: uses query params for `:get`, and sends a JSON body for
133+
other HTTP methods
134+
- `form_send`: sends requests as `application/x-www-form-urlencoded`
135+
- `multipart_form_send`: sends multipart form data, typically for file
136+
uploads
137+
138+
`http_send`, `form_send`, and `multipart_form_send` accept HTTP verbs
139+
such as:
140+
141+
- `:get`
142+
- `:post`
143+
- `:put`
144+
- `:delete`
145+
146+
### Common options
147+
148+
- `sort_params`: controls whether query parameters are sorted before sending, default is `true`
149+
- `content_type_charset`: used by `http_send` for JSON requests,
150+
default is `'utf-8'`
151+
- `need_response_header`: when set to `true`, includes response
152+
headers in the returned result
153+
154+
## Security
155+
156+
Please see [SECURITY.md](SECURITY.md) for vulnerability reporting instructions.

0 commit comments

Comments
 (0)