# frozen_string_literal: true module PlatformSdk module OpsGenie # Client for OpsGenie API class Client attr_reader :connection OPSGENIE_API_URL = "https://api.opsgenie.com" def initialize(opsgenie_secret, conn = nil) raise ArgumentError, "opsgenie_secret cannot be nil" unless opsgenie_secret @connection = conn || build_connection(opsgenie_secret) end def heartbeat(heartbeat_name) connection.get("v2/heartbeats/#{heartbeat_name}/ping") end private def build_connection(secret) Faraday.new(url: OPSGENIE_API_URL) do |conn| conn.request :url_encoded conn.request :retry conn.response :raise_error conn.adapter Faraday.default_adapter conn.headers[:Authorization] = "GenieKey #{secret}" end end end end end