Sha256: 4dadb9026278dd61db9eceec38c947f27831fb4a8f9e6c0f394e08e9ee2ade84

Contents?: true

Size: 893 Bytes

Versions: 4

Compression:

Stored size: 893 Bytes

Contents

# frozen_string_literal: true

module ApiSignature
  module SpecSupport
    class HeadersBuilder
      attr_reader :access_key, :secret, :http_method, :path

      def initialize(access_key, secret, http_method, path)
        @access_key = access_key
        @secret = secret
        @http_method = http_method
        @path = path
      end

      def headers
        {
          'HTTP_X_ACCESS_KEY' => access_key,
          'HTTP_X_TIMESTAMP' => options[:timestamp],
          'HTTP_X_SIGNATURE' => generator.generate_signature(secret)
        }
      end

      private

      def generator
        @generator ||= ::ApiSignature::Generator.new(options)
      end

      def options
        @options ||= {
          request_method: http_method.to_s.upcase,
          path: path,
          access_key: access_key,
          timestamp: Time.zone.now.to_i
        }
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
api_signature-0.1.4 lib/api_signature/spec_support/headers_builder.rb
api_signature-0.1.3 lib/api_signature/spec_support/headers_builder.rb
api_signature-0.1.2 lib/api_signature/spec_support/headers_builder.rb
api_signature-0.1.1 lib/api_signature/spec_support/headers_builder.rb