client-api 0.2.9 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/client-api/base.rb +21 -3
- data/lib/client-api/request.rb +13 -0
- data/lib/client-api/version.rb +1 -1
- 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: c4f4fc9b992556d30a2b18109f3311b4ad7537c4899cf28bdf6b4546b3be92a2
|
4
|
+
data.tar.gz: 52a54136c51d74c7ec5150f8e839fb41ee29bee4accad87e80d14c08927b42a7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 05412312db15d9542baaefdda445d2c4f0124c62cff3fd3ec7a08ea9556449c559c9cfd3c7c6451818237ad2a806a49e3db1a88798e03b3c080749d6dd6ffdbb
|
7
|
+
data.tar.gz: 56e2dc60bdfb115ee4a45fd0c22d4e4ad08d38f5c1a08daf95bcb1debdaf848cef0e2deaa63cb1dfaaed41b46071182f252b717aa2feac19df4f05a9f0a647cb
|
data/lib/client-api/base.rb
CHANGED
@@ -23,7 +23,16 @@ module ClientApi
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def post(url, body, headers = nil)
|
26
|
-
|
26
|
+
if body.is_a? Hash
|
27
|
+
if body['type'] && body['data']
|
28
|
+
@output = post_request_x(url, :body => body, :headers => headers)
|
29
|
+
else
|
30
|
+
@output = post_request(url, :body => body, :headers => headers)
|
31
|
+
end
|
32
|
+
else
|
33
|
+
raise 'invalid body'
|
34
|
+
end
|
35
|
+
|
27
36
|
self.post_logger if $logger
|
28
37
|
self.output_json_body if json_output
|
29
38
|
end
|
@@ -104,8 +113,17 @@ module ClientApi
|
|
104
113
|
alias :resp :body
|
105
114
|
end
|
106
115
|
|
107
|
-
def payload(
|
108
|
-
|
116
|
+
def payload(args)
|
117
|
+
if args['type'].nil?
|
118
|
+
JSON.parse(File.read(args))
|
119
|
+
else
|
120
|
+
case args['type'].downcase
|
121
|
+
when 'multipart/form-data', 'application/x-www-form-urlencoded'
|
122
|
+
args
|
123
|
+
else
|
124
|
+
raise "invalid body type | try: payload('./data/request/file.png', 'multipart/form-data')"
|
125
|
+
end
|
126
|
+
end
|
109
127
|
end
|
110
128
|
|
111
129
|
alias :schema_from_json :payload
|
data/lib/client-api/request.rb
CHANGED
@@ -36,6 +36,19 @@ module ClientApi
|
|
36
36
|
@http.post(uri(url).path, body.to_json, initheader = header(options))
|
37
37
|
end
|
38
38
|
|
39
|
+
def post_request_x(url, options = {})
|
40
|
+
body = options[:body]
|
41
|
+
connect(url)
|
42
|
+
|
43
|
+
request = Net::HTTP::Post.new(uri(url))
|
44
|
+
body['data'].each { |key,value| request.set_form([[key.to_s,File.open(value)]], body['type'])}
|
45
|
+
final_header = header(options).delete_if{ |k,| ['Content-Type', 'content-type', 'Content-type', 'content-Type'].include? k }
|
46
|
+
final_header.each { |key,value| request.add_field(key,value)}
|
47
|
+
|
48
|
+
pre_logger(:log_url => uri(url), :log_header => header(options), :log_body => body, :log_method => 'POST') if $logger
|
49
|
+
@http.request(request)
|
50
|
+
end
|
51
|
+
|
39
52
|
def delete_request(url, options = {})
|
40
53
|
connect(url)
|
41
54
|
pre_logger(:log_url => uri(url), :log_header => header(options), :log_method => 'DELETE') if $logger
|
data/lib/client-api/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: client-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Prashanth Sams
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-11-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|