json_requester 0.1.2 → 1.0.2
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 +19 -7
- metadata +18 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 21eaf675a4c5ed77b6eea64f37717038e2c82627f399423dd20a1452fa62be5e
|
4
|
+
data.tar.gz: d2fe47889d68c4a1e8c03af212359de1273117a3286adced729515a40acbe4b4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 316d952a76c2003e82c9d9082fb5c75aca54f45e4ac815fcf04516dbc6a5c960e8e5743e7c1a08f051b6bd23c9cbd005c3514e513963fe0ae87d3b2aaa065685
|
7
|
+
data.tar.gz: b043b90e1469c34655138c5175a6b90d6c1d7e64db58da9c04f03caa66612ad507840573d19c86e177c567016ddeff4bb03efda7177b692d1d2992564b13c343
|
data/lib/json_requester.rb
CHANGED
@@ -4,8 +4,9 @@ require 'json'
|
|
4
4
|
class JsonRequester
|
5
5
|
attr_reader :host, :conn
|
6
6
|
|
7
|
-
def initialize(host)
|
7
|
+
def initialize(host, multipart: false)
|
8
8
|
@host = host
|
9
|
+
@multipart = multipart
|
9
10
|
@conn = init_conn
|
10
11
|
end
|
11
12
|
|
@@ -28,34 +29,44 @@ class JsonRequester
|
|
28
29
|
error_response(e)
|
29
30
|
end
|
30
31
|
|
31
|
-
def
|
32
|
+
def json_send(http_method, path, params={}, headers={})
|
32
33
|
res = @conn.send(http_method) do |req|
|
33
34
|
req.url path
|
34
35
|
req.headers = headers if object_present?(headers)
|
35
|
-
req.headers['Content-Type'] = 'application/
|
36
|
-
req.body = params if object_present?(params)
|
36
|
+
req.headers['Content-Type'] = 'application/json;charset=utf-8'
|
37
|
+
req.body = params.to_json if object_present?(params)
|
37
38
|
end
|
38
39
|
process_response(res)
|
39
40
|
rescue => e
|
40
41
|
error_response(e)
|
41
42
|
end
|
42
43
|
|
43
|
-
def
|
44
|
+
def form_send(http_method, path, params={}, headers={})
|
44
45
|
res = @conn.send(http_method) do |req|
|
45
46
|
req.url path
|
46
47
|
req.headers = headers if object_present?(headers)
|
47
|
-
req.headers['Content-Type'] = 'application/
|
48
|
-
req.body = params
|
48
|
+
req.headers['Content-Type'] = 'application/x-www-form-urlencoded ;charset=utf-8'
|
49
|
+
req.body = URI.encode_www_form(params) if object_present?(params)
|
49
50
|
end
|
50
51
|
process_response(res)
|
51
52
|
rescue => e
|
52
53
|
error_response(e)
|
53
54
|
end
|
54
55
|
|
56
|
+
def multipart_form_send(http_method, path, params={}, headers={})
|
57
|
+
res = @conn.send(http_method) do |req|
|
58
|
+
req.url path
|
59
|
+
req.headers = headers if object_present?(headers)
|
60
|
+
req.body = params if object_present?(params)
|
61
|
+
end
|
62
|
+
process_response(res)
|
63
|
+
end
|
64
|
+
|
55
65
|
private
|
56
66
|
|
57
67
|
def init_conn
|
58
68
|
Faraday.new(url: host) do |faraday|
|
69
|
+
faraday.request :multipart if @multipart # multipart form POST request
|
59
70
|
faraday.request :url_encoded # form-encode POST params
|
60
71
|
faraday.response :logger # log requests to $stdout
|
61
72
|
faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
|
@@ -81,4 +92,5 @@ class JsonRequester
|
|
81
92
|
def object_present?(object)
|
82
93
|
!(object.nil? || object.empty?)
|
83
94
|
end
|
95
|
+
|
84
96
|
end
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: json_requester
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.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:
|
12
|
-
dependencies:
|
11
|
+
date: 2021-05-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.0.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.0.0
|
13
27
|
description: wrapper of faraday
|
14
28
|
email: laura34963@kdanmobile.com
|
15
29
|
executables: []
|
@@ -39,7 +53,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
39
53
|
- !ruby/object:Gem::Version
|
40
54
|
version: '0'
|
41
55
|
requirements: []
|
42
|
-
rubygems_version: 3.0.
|
56
|
+
rubygems_version: 3.0.3
|
43
57
|
signing_key:
|
44
58
|
specification_version: 4
|
45
59
|
summary: Basic Wrapper of Faraday
|