# frozen_string_literal: true require 'json' require 'openssl' module NoradBeacon class HttpPayload attr_accessor :url def initialize(url = nil) @data = {} @url = url || url_from_env end def add(obj) @data.merge!(obj.to_h) end def payload @payload ||= @data.merge(timestamp: Time.now.to_i).to_json end def compute_signature OpenSSL::HMAC.hexdigest('sha256', ENV['NORAD_SECRET'], payload) end private def url_from_env '' end end end