Module: Autoscale::Agent::Request
- Defined in:
- lib/autoscale/agent/request.rb
Class Method Summary collapse
Class Method Details
.dispatch(body, token:) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/autoscale/agent/request.rb', line 6 def dispatch(body, token:) url = ENV["AUTOSCALE_METRICS_URL"] || "https://metrics.autoscale.app" headers = { "User-Agent" => "Autoscale Agent (Ruby)", "Content-Type" => "application/json", "Autoscale-Metric-Token" => token } post(url, body, headers) end |
.post(url, body, headers = {}) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/autoscale/agent/request.rb', line 18 def post(url, body, headers = {}) uri = URI.parse(url) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = uri.port == 443 http.open_timeout = 5 http.read_timeout = 5 request = Net::HTTP::Post.new(uri.request_uri) headers.each { |key, value| request[key] = value } request.body = body http.request(request) end |