# frozen_string_literal: true require 'json' require 'rest-client' class DatadogMetrics def initialize(apikey, url) @apikey = apikey @url = url end def send_metrics(metrics_data) puts "Sending received metrics data" response = RestClient::Request.new( method: :post, url: @url, payload: metrics_data.to_json, headers: {'DD-API-KEY': @apikey, content_type: :json } ).execute do |response, request, result| case response.code when 202 return response.body else puts 'Cannot send metrics to Datadog', response.body end end end end