Class: ClientApi::Api
Constant Summary
Constants included
from ClientApi
VERSION
Instance Method Summary
collapse
Methods included from ClientApi
#base_url, #basic_auth, configuration, configure, #datatype, #deep_traverse, #headers, #is_num?, #json_output, #payload, #time_out, #validate, #validate_json, #validate_schema
Methods inherited from Request
#basic_encode, #connect, #delete_request, #get_request, #header, #patch_request, #post_request, #pre_logger, #put_request, #uri
Constructor Details
#initialize ⇒ Api
9
10
11
|
# File 'lib/client-api/base.rb', line 9
def initialize
((FileUtils.rm Dir.glob("./#{json_output['Dirname']}/*.json"); $roo = true)) if json_output && $roo == nil
end
|
Instance Method Details
#body ⇒ Object
Also known as:
resp
47
48
49
50
51
|
# File 'lib/client-api/base.rb', line 47
def body
unless @output.body == "" || @output.body.nil? || @output.body == "{}"
JSON.parse(@output.body)
end
end
|
#delete(url, headers = nil) ⇒ Object
25
26
27
28
29
|
# File 'lib/client-api/base.rb', line 25
def delete(url, = nil)
@output = delete_request(url, :headers => )
self.post_logger if $logger
self.output_json_body if json_output
end
|
#get(url, headers = nil) ⇒ Object
13
14
15
16
17
|
# File 'lib/client-api/base.rb', line 13
def get(url, = nil)
@output = get_request(url, :headers => )
self.post_logger if $logger
self.output_json_body if json_output
end
|
#message ⇒ Object
67
68
69
|
# File 'lib/client-api/base.rb', line 67
def message
@output.message
end
|
#output_json_body ⇒ Object
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/client-api/base.rb', line 53
def output_json_body
unless @output.body == "" || @output.body.nil? || @output.body == "{}"
unless json_output['Dirname'] == nil
FileUtils.mkdir_p "#{json_output['Dirname']}"
time_now = (Time.now.to_f).to_s.gsub('.','')
begin
File.open("./#{json_output['Dirname']}/#{json_output['Filename']+"_"+time_now}""#{time_now}"".json", "wb") {|file| file.puts JSON.pretty_generate(JSON.parse(@output.body))}
rescue StandardError => e
raise("\n"+" Not a compatible (or) Invalid JSON response => [kindly check the uri & request details]".brown + " \n\n #{e.message}")
end
end
end
end
|
#patch(url, body, headers = nil) ⇒ Object
37
38
39
40
41
|
# File 'lib/client-api/base.rb', line 37
def patch(url, body, = nil)
@output = patch_request(url, :body => body, :headers => )
self.post_logger if $logger
self.output_json_body if json_output
end
|
#post(url, body, headers = nil) ⇒ Object
19
20
21
22
23
|
# File 'lib/client-api/base.rb', line 19
def post(url, body, = nil)
@output = post_request(url, :body => body, :headers => )
self.post_logger if $logger
self.output_json_body if json_output
end
|
#post_logger ⇒ Object
71
72
73
74
75
76
77
|
# File 'lib/client-api/base.rb', line 71
def post_logger
(@output.body == "" || @output.body.nil? || @output.body == "{}") ? res_body = 'empty response body' : res_body = body
$logger.debug("Response code == #{@output.code.to_i}")
$logger.debug("Response body == #{res_body}")
$logger.debug("=====================================================================================")
end
|
#put(url, body, headers = nil) ⇒ Object
31
32
33
34
35
|
# File 'lib/client-api/base.rb', line 31
def put(url, body, = nil)
@output = put_request(url, :body => body, :headers => )
self.post_logger if $logger
self.output_json_body if json_output
end
|
#status ⇒ Object
Also known as:
code
43
44
45
|
# File 'lib/client-api/base.rb', line 43
def status
@output.code.to_i
end
|