client-api 0.2.9 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5fa8ffde50bd3a08b2e4b3854b9e7f198940b020fa3c8f97ff08e86f896ba8fb
4
- data.tar.gz: 44e53563c7b2de413100b9bb424ed6c0fc94612a33e986718411ee07ced1ebff
3
+ metadata.gz: c4f4fc9b992556d30a2b18109f3311b4ad7537c4899cf28bdf6b4546b3be92a2
4
+ data.tar.gz: 52a54136c51d74c7ec5150f8e839fb41ee29bee4accad87e80d14c08927b42a7
5
5
  SHA512:
6
- metadata.gz: 344e376014c558541b066c192a6f31aaba842e2172db89ddbdff669339241ec50e512ef468de9275366a505afeaf907c8f51b368c57a93e23047bb6f53761b93
7
- data.tar.gz: '083c265fdc63554f1f05d9058fa74e6066648839a89c4627b237452d58e90850a84814f16593e95450f68ccec6838a7ff95ef3d47dea3b7968644da138ff505f'
6
+ metadata.gz: 05412312db15d9542baaefdda445d2c4f0124c62cff3fd3ec7a08ea9556449c559c9cfd3c7c6451818237ad2a806a49e3db1a88798e03b3c080749d6dd6ffdbb
7
+ data.tar.gz: 56e2dc60bdfb115ee4a45fd0c22d4e4ad08d38f5c1a08daf95bcb1debdaf848cef0e2deaa63cb1dfaaed41b46071182f252b717aa2feac19df4f05a9f0a647cb
@@ -23,7 +23,16 @@ module ClientApi
23
23
  end
24
24
 
25
25
  def post(url, body, headers = nil)
26
- @output = post_request(url, :body => body, :headers => headers)
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(path)
108
- JSON.parse(File.read(path))
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
@@ -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
@@ -1,3 +1,3 @@
1
1
  module ClientApi
2
- VERSION = "0.2.9".freeze
2
+ VERSION = "0.3.0".freeze
3
3
  end
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.2.9
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-10-29 00:00:00.000000000 Z
11
+ date: 2019-11-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler