# frozen_string_literal: true require 'httparty' module NoradBeacon # Class to post http payloads class NoradAPI include HTTParty @norad_root = ENV.fetch('NORAD_ROOT') class << self def post_payload(http_payload) http_req http_payload, :post end def patch_payload(http_payload) http_req http_payload, :patch end def delete_payload(http_payload) http_req http_payload, :delete end alias post_results post_payload private def http_req(http_payload, verb) auth_header = { 'NORAD-SIGNATURE' => http_payload.compute_signature } address = @norad_root + http_payload.url send( verb, address, body: http_payload.payload, headers: { 'Content-Type' => 'application/json' }.merge(auth_header) ) end end end end