Sha256: 6b0295b3ca5b9abc7e782068f6d76c185e66452c2e3e93b5054dfb721d864d60

Contents?: true

Size: 559 Bytes

Versions: 3

Compression:

Stored size: 559 Bytes

Contents

# frozen_string_literal: true
require 'json'
require 'openssl'

module NoradBeacon
  class ResultSet
    attr_accessor :url

    def initialize(assessment_url = nil)
      @results = []
      @url = assessment_url || JSON.parse(ENV.fetch('ASSESSMENT_PATHS')).first['assessment']
    end

    def add(result)
      @results.push(result)
    end

    def payload
      @payload ||= { results: @results, timestamp: Time.now.to_i }.to_json
    end

    def compute_signature
      OpenSSL::HMAC.hexdigest('sha256', ENV['NORAD_SECRET'], payload)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
norad_beacon-0.1.3 lib/norad_beacon/resultset.rb
norad_beacon-0.1.2 lib/norad_beacon/resultset.rb
norad_beacon-0.1.1 lib/norad_beacon/resultset.rb