json_requester 1.1.0 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -1
  3. data/lib/json_requester.rb +8 -4
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cc7d06fc0826a6e7c0de5aa79a3f0f3bfa8825939594a46bd0f94d00fff2b4e2
4
- data.tar.gz: 251126b9edcdd2c645f7510f388d6ab5f80b4954695c309c99bb402758a6ec10
3
+ metadata.gz: 6a0dd5080d2bec29884d6da9cf56099973847d3ba0841f296089591278ce6b84
4
+ data.tar.gz: ac92413b55e07c14f48515ce0e62cfb5e990b701c8eb5ee2b3c7887cd9cdf124
5
5
  SHA512:
6
- metadata.gz: d2eddf1750ef801739e6dae0108a085954b3e0d41276f171a365ba5df5bb99f84ce666467fdcb2c5824c9a6c6be9a35976e219a3e2c95cd848e00e5bae5cd92b
7
- data.tar.gz: 7d2d352b07533fd5906ddf8ea08687d8e320cd1dad193f46abe576bc0b4b304981956e8f87ef84fe32794d958554531dd2cbfffbbd9b676e4cebf84b7f121384
6
+ metadata.gz: 8103bb5bf91b6df2ddfb88558d4c8091beaf3893ce0a24d17a4a91f8dfcc99b0e7aecd73c0b65beac5c5e7e2d21ac6de4b5fe71fe9e6dc2ac3532a31ad66289e
7
+ data.tar.gz: e137988468f479c1e7a26d9a1aaacfe4e2d9935286b884fa42f6edd462e5dc283e94a2e980b9329cccc82c4e94f9ffbe5bbe2a5d140464b95a2b49f0ab57b2eb
data/README.md CHANGED
@@ -30,7 +30,8 @@ $ gem install json_requester
30
30
  # Request by using JSON body or query params, use the `http_send` method.
31
31
  # other methods: `form_send`, `multipart_form_send`
32
32
  # `sort_params` at Faraday gem default is true.
33
- res = requester.http_send(http_method, path, params, headers, sort_params: true)
33
+ # `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`).
34
+ res = requester.http_send(http_method, path, params, headers, sort_params: true, content_type_charset: 'utf-8')
34
35
 
35
36
  # http response code
36
37
  puts res['status'] # 200, 404, .. etc
@@ -12,12 +12,12 @@ class JsonRequester
12
12
  @user_agent = user_agent.strip.to_s
13
13
  end
14
14
 
15
- def http_send(http_method, path, params={}, headers={}, sort_params: true, need_response_header: false)
15
+ def http_send(http_method, path, params={}, headers={}, sort_params: true, need_response_header: false, content_type_charset: 'utf-8')
16
16
  puts "send #{http_method} reqeust to #{@host} with\npath: #{path}\nparams: #{params}\nheaders: #{headers}"
17
17
  if http_method == :get
18
18
  normal_send(http_method, path, params, headers, sort_params: sort_params, need_response_header: need_response_header)
19
19
  else
20
- json_send(http_method, path, params, headers, sort_params: sort_params, need_response_header: need_response_header)
20
+ json_send(http_method, path, params, headers, sort_params: sort_params, need_response_header: need_response_header, content_type_charset: content_type_charset)
21
21
  end
22
22
  end
23
23
 
@@ -33,12 +33,16 @@ class JsonRequester
33
33
  error_response(e)
34
34
  end
35
35
 
36
- def json_send(http_method, path, params={}, headers={}, sort_params: true, need_response_header: false)
36
+ def json_send(http_method, path, params={}, headers={}, sort_params: true, need_response_header: false, content_type_charset: 'utf-8')
37
37
  conn = init_conn(sort_params: sort_params)
38
38
  res = conn.send(http_method) do |req|
39
39
  req.url path
40
40
  req.headers = headers if object_present?(headers)
41
- req.headers['Content-Type'] = 'application/json;charset=utf-8'
41
+ if content_type_charset.present?
42
+ req.headers['Content-Type'] = "application/json;charset=#{content_type_charset}"
43
+ else
44
+ req.headers['Content-Type'] = 'application/json'
45
+ end
42
46
  req.body = params.to_json if object_present?(params)
43
47
  end
44
48
  process_response(res, need_response_header: need_response_header)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json_requester
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - JiaRou Lee
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-12-13 00:00:00.000000000 Z
11
+ date: 2024-06-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday