18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/caliper_api/http.rb', line 18
def post(url, data = "")
begin
uri = URI.parse(@base_uri + url)
http = Net::HTTP.new(uri.host, uri.port)
http.open_timeout = 5 http.read_timeout = 5
request = Net::HTTP::Post.new(uri.request_uri)
request["X_API_KEY"] = Caliper.config[:api_key]
request["Content-Type"] = "application/json"
request["Accept"] = "application/json"
request.body = data
response = http.request(request)
status = response.code.to_i
if status == 401
Caliper.logger.error "CaliperApi: Error: Not authorized check your API key on #{Caliper.config[:api_host]}"
elsif status > 400
Caliper.logger.error "CaliperApi: Error: got #{response.code} from server"
end
rescue Exception => e
Caliper.logger.error "CaliperApi: Http error: #{e.message}"
end
end
|