13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/cc/api/http/http_requestor.rb', line 13
def request_for_json(params)
start_time = Time.now
if params[:request][:method] == "POST"
response_body = HTTParty.post(
params[:request][:url],
:basic_auth => basic_auth,
:body => params[:request][:body].to_json,
:headers => { 'Content-Type' => 'application/json' }
)
else
response_body = HTTParty.get(params[:request][:url], :basic_auth => basic_auth)
end
puts "#{params[:request][:method] || "GET"} #{params[:request][:url]} #{params[:request][:body]}"
end_time = Time.now
raise UnauthorizedAccessException, "You don't have enough privilege to access." if response_body.code == 401
raise ServerProblemException, "There's a problem with the server. Server response not expected." if response_body.code == 500
return {body: response_body, response_time: end_time - start_time}
end
|