8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/skn_utils/http_processor.rb', line 8
def self.call(command)
completion = false
response = Net::HTTP.start( command.uri.host,command.uri.port,
use_ssl: command.uri.scheme.eql?("https")
) do |http|
http.open_timeout = 5 http.read_timeout = 15 if command.uri.scheme.eql?("https")
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
end
http.request(command.request)
end
if ( response.kind_of?(Net::HTTPClientError) or response.kind_of?(Net::HTTPServerError) )
completion = SknFailure.call(response.code, response.message)
else
payload = command.json? ? JSON.load(response.body) : response.body
completion = SknSuccess.call(payload, response.class.name)
end
completion
rescue => exception
SknFailure.call(command.uri.request_uri, "#{exception.message}; #{exception.backtrace[0]}")
end
|