Sha256: 9c047370c52c0fd214009110feb961fff787474ca594c8fa9f53cf68c7a2e963

Contents?: true

Size: 622 Bytes

Versions: 4

Compression:

Stored size: 622 Bytes

Contents

# frozen_string_literal: true

module Peddler
  # Parses MWS-specific headers
  module Headers
    Quota = Struct.new(:max, :remaining, :resets_on)

    def quota
      return if headers.keys.none? { |key| key.include?('quota') }

      Quota.new(
        headers['x-mws-quota-max'].to_i,
        headers['x-mws-quota-remaining'].to_i,
        Time.parse(headers['x-mws-quota-resetsOn'])
      )
    end

    def request_id
      headers['x-mws-request-id']
    end

    def timestamp
      Time.parse(headers['x-mws-timestamp'])
    end

    def response_context
      headers['x-mws-response-context']
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
peddler-1.6.7 lib/peddler/headers.rb
peddler-1.6.6 lib/peddler/headers.rb
peddler-1.6.5 lib/peddler/headers.rb
peddler-1.6.4 lib/peddler/headers.rb