Sha256: 5732e74c0247e72712fbf262269c9c71b2fbecf5eae2c4124e319618613f194d

Contents?: true

Size: 892 Bytes

Versions: 1

Compression:

Stored size: 892 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.now.utc.to_i
        }
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
api_signature-0.1.5 lib/api_signature/spec_support/headers_builder.rb