json_requester 1.0.11 → 1.0.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/json_requester.rb +15 -13
- 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: '0845954f6576fcb489054c9dba9649432baf657c49e83e77bfcc0e5c70cc0e89'
|
4
|
+
data.tar.gz: cbe77bc53e67caedf438644d5f5302fa5bbf78761f79a96762b3b401c126b035
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aa8352783d500877db5023c7d9f77d0cd5488e9af3418c25fba9e7cbb863e4e247bb40e534919e42ea15137636de0ced368c54d2148883e2c7139fe1e6386948
|
7
|
+
data.tar.gz: e0da8dcf1a2faaefedee3724d46fa56945db6d0495674a776870b813719c81299b8f5f10dad3aef0f2083995a609ba9e90d1994cf58477bf23d00e1ff1ce1772
|
data/lib/json_requester.rb
CHANGED
@@ -11,28 +11,28 @@ class JsonRequester
|
|
11
11
|
@timeout = timeout
|
12
12
|
end
|
13
13
|
|
14
|
-
def http_send(http_method, path, params={}, headers={}, sort_params: true)
|
14
|
+
def http_send(http_method, path, params={}, headers={}, sort_params: true, need_response_header: false)
|
15
15
|
puts "send #{http_method} reqeust to #{@host} with\npath: #{path}\nparams: #{params}\nheaders: #{headers}"
|
16
16
|
if http_method == :get
|
17
|
-
normal_send(http_method, path, params, headers, sort_params: sort_params)
|
17
|
+
normal_send(http_method, path, params, headers, sort_params: sort_params, need_response_header: need_response_header)
|
18
18
|
else
|
19
|
-
json_send(http_method, path, params, headers, sort_params: sort_params)
|
19
|
+
json_send(http_method, path, params, headers, sort_params: sort_params, need_response_header: need_response_header)
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
def normal_send(http_method, path, params={}, headers={}, sort_params: true)
|
23
|
+
def normal_send(http_method, path, params={}, headers={}, sort_params: true, need_response_header: false)
|
24
24
|
conn = init_conn(sort_params: sort_params)
|
25
25
|
res = conn.send(http_method) do |req|
|
26
26
|
req.url path
|
27
27
|
req.headers = headers if object_present?(headers)
|
28
28
|
req.params = params if object_present?(params)
|
29
29
|
end
|
30
|
-
process_response(res)
|
30
|
+
process_response(res, need_response_header: need_response_header)
|
31
31
|
rescue => e
|
32
32
|
error_response(e)
|
33
33
|
end
|
34
34
|
|
35
|
-
def json_send(http_method, path, params={}, headers={}, sort_params: true)
|
35
|
+
def json_send(http_method, path, params={}, headers={}, sort_params: true, need_response_header: false)
|
36
36
|
conn = init_conn(sort_params: sort_params)
|
37
37
|
res = conn.send(http_method) do |req|
|
38
38
|
req.url path
|
@@ -40,12 +40,12 @@ class JsonRequester
|
|
40
40
|
req.headers['Content-Type'] = 'application/json;charset=utf-8'
|
41
41
|
req.body = params.to_json if object_present?(params)
|
42
42
|
end
|
43
|
-
process_response(res)
|
43
|
+
process_response(res, need_response_header: need_response_header)
|
44
44
|
rescue => e
|
45
45
|
error_response(e)
|
46
46
|
end
|
47
47
|
|
48
|
-
def form_send(http_method, path, params={}, headers={}, sort_params: true)
|
48
|
+
def form_send(http_method, path, params={}, headers={}, sort_params: true, need_response_header: false)
|
49
49
|
conn = init_conn(sort_params: sort_params)
|
50
50
|
res = conn.send(http_method) do |req|
|
51
51
|
req.url path
|
@@ -53,19 +53,19 @@ class JsonRequester
|
|
53
53
|
req.headers['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8'
|
54
54
|
req.body = URI.encode_www_form(params) if object_present?(params)
|
55
55
|
end
|
56
|
-
process_response(res)
|
56
|
+
process_response(res, need_response_header: need_response_header)
|
57
57
|
rescue => e
|
58
58
|
error_response(e)
|
59
59
|
end
|
60
60
|
|
61
|
-
def multipart_form_send(http_method, path, params={}, headers={}, sort_params: true)
|
61
|
+
def multipart_form_send(http_method, path, params={}, headers={}, sort_params: true, need_response_header: false)
|
62
62
|
conn = init_conn(sort_params: sort_params)
|
63
63
|
res = conn.send(http_method) do |req|
|
64
64
|
req.url path
|
65
65
|
req.headers = headers if object_present?(headers)
|
66
66
|
req.body = params if object_present?(params)
|
67
67
|
end
|
68
|
-
process_response(res)
|
68
|
+
process_response(res, need_response_header: need_response_header)
|
69
69
|
end
|
70
70
|
|
71
71
|
private
|
@@ -83,7 +83,7 @@ class JsonRequester
|
|
83
83
|
end
|
84
84
|
end
|
85
85
|
|
86
|
-
def process_response(response)
|
86
|
+
def process_response(response, need_response_header: false)
|
87
87
|
result = {'status' => response.status}
|
88
88
|
begin
|
89
89
|
body = JSON.parse(response.body)
|
@@ -92,7 +92,9 @@ class JsonRequester
|
|
92
92
|
rescue
|
93
93
|
body = {'body' => response.body}
|
94
94
|
end
|
95
|
-
result.merge(body)
|
95
|
+
result.merge!(body)
|
96
|
+
result['headers'] = response.headers.to_h if need_response_header
|
97
|
+
result
|
96
98
|
end
|
97
99
|
|
98
100
|
def error_response(err)
|
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.0.
|
4
|
+
version: 1.0.12
|
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-
|
11
|
+
date: 2023-10-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|