Sha256: 0e81af05003495935c613211d8d68bf5c40f961bbfb987a50c86859cc28af81a

Contents?: true

Size: 416 Bytes

Versions: 2

Compression:

Stored size: 416 Bytes

Contents

# frozen_string_literal: true

module Mergent
  class RequestValidator
    def initialize(api_key)
      @api_key = api_key || Mergent.api_key
    end

    def build_signature(body)
      digest = OpenSSL::Digest.new("sha1")
      Base64.strict_encode64(OpenSSL::HMAC.digest(digest, @api_key, body || ""))
    end

    def valid_signature?(body, signature)
      build_signature(body) == signature
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mergent-1.0.0 lib/mergent/request_validator.rb
mergent-0.2.2 lib/mergent/request_validator.rb