class Supercast::Client::RequestLogContext

RequestLogContext stores information about a request that's begin made so that we can log certain information. It's useful because it means that we don't have to pass around as many parameters.

Attributes

account[RW]
api_key[RW]
api_version[RW]
body[RW]
idempotency_key[RW]
method[RW]
path[RW]
query_params[RW]

Public Instance Methods

dup_from_response(resp) click to toggle source

The idea with this method is that we might want to update some of context information because a response that we've received from the API contains information that's more authoritative than what we started with for a request. For example, we should trust whatever came back in a `Supercast-Version` header beyond what configuration information that we might have had available.

# File lib/supercast/client.rb, line 476
def dup_from_response(resp)
  return self if resp.nil?

  # Faraday's API is a little unusual. Normally it'll produce a response
  # object with a `headers` method, but on error what it puts into
  # `e.response` is an untyped `Hash`.
  headers = if resp.is_a?(Faraday::Response)
              resp.headers
            else
              resp[:headers]
            end

  context = dup
  context.account = headers['Supercast-Account']
  context.api_version = headers['Supercast-Version']
  context.idempotency_key = headers['Idempotency-Key']
  context
end