json_requester 1.1.2 → 1.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/json_requester.rb +12 -8
  3. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6a0dd5080d2bec29884d6da9cf56099973847d3ba0841f296089591278ce6b84
4
- data.tar.gz: ac92413b55e07c14f48515ce0e62cfb5e990b701c8eb5ee2b3c7887cd9cdf124
3
+ metadata.gz: b4f982cccc8a4c27d2013a2c007b907c0cbf3f6aa05eff09464bba82cc6cd59f
4
+ data.tar.gz: f36d85249ef2b341aeff0435da4c3398d10e8c7146f2233c7c35f11a61b588c3
5
5
  SHA512:
6
- metadata.gz: 8103bb5bf91b6df2ddfb88558d4c8091beaf3893ce0a24d17a4a91f8dfcc99b0e7aecd73c0b65beac5c5e7e2d21ac6de4b5fe71fe9e6dc2ac3532a31ad66289e
7
- data.tar.gz: e137988468f479c1e7a26d9a1aaacfe4e2d9935286b884fa42f6edd462e5dc283e94a2e980b9329cccc82c4e94f9ffbe5bbe2a5d140464b95a2b49f0ab57b2eb
6
+ metadata.gz: 02bcd235be1471113c0b0c1640bad36f308a839e7d3143a072877cd124bec70af77079093934e97ace2a85db5bcdd6d7ab2ec2029dd05dee774f9dbabcc741e2
7
+ data.tar.gz: 86c13263c31f9174cb3a0ba66f0283958bc783f80c635649d28ee60b0072c2cc3b92ec931010a91a6507e1a3ecc44e6cde5217659db152ba5bbd33a11c86afbe
@@ -13,7 +13,7 @@ class JsonRequester
13
13
  end
14
14
 
15
15
  def http_send(http_method, path, params={}, headers={}, sort_params: true, need_response_header: false, content_type_charset: 'utf-8')
16
- puts "send #{http_method} reqeust to #{@host} with\npath: #{path}\nparams: #{params}\nheaders: #{headers}"
16
+ puts "send #{http_method} request 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
@@ -38,11 +38,7 @@ class JsonRequester
38
38
  res = conn.send(http_method) do |req|
39
39
  req.url path
40
40
  req.headers = headers if object_present?(headers)
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
41
+ req.headers['Content-Type'] = object_present?(content_type_charset) ? "application/json;charset=#{content_type_charset}" : 'application/json'
46
42
  req.body = params.to_json if object_present?(params)
47
43
  end
48
44
  process_response(res, need_response_header: need_response_header)
@@ -104,11 +100,19 @@ class JsonRequester
104
100
  end
105
101
 
106
102
  def error_response(err)
107
- {'status' => 500, 'message' => "#{err.class.name}: #{err.message}"}
103
+ { 'status' => 500, 'message' => "#{err.class.name}: #{err.message}" }
108
104
  end
109
105
 
110
106
  def object_present?(object)
111
- !(object.nil? || object.empty?)
107
+ # Ref: https://github.com/rails/rails/blob/v7.1.4.2/activesupport/lib/active_support/core_ext/object/blank.rb#L25
108
+ # active_support present? method
109
+ !object_blank?(object)
110
+ end
111
+
112
+ def object_blank?(object)
113
+ # Ref: https://github.com/rails/rails/blob/v7.1.4.2/activesupport/lib/active_support/core_ext/object/blank.rb#L18
114
+ # active_support blank? method
115
+ object.respond_to?(:empty?) ? !!object.empty? : false
112
116
  end
113
117
 
114
118
  end
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.2
4
+ version: 1.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - JiaRou Lee
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-06-28 00:00:00.000000000 Z
11
+ date: 2024-10-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -75,7 +75,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
75
75
  - !ruby/object:Gem::Version
76
76
  version: '0'
77
77
  requirements: []
78
- rubygems_version: 3.4.10
78
+ rubygems_version: 3.5.16
79
79
  signing_key:
80
80
  specification_version: 4
81
81
  summary: Basic Wrapper of Faraday