Class: Supercast::Client::RequestLogContext

Inherits:
Object
  • Object
show all
Defined in:
lib/supercast/client.rb

Overview

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.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#accountObject

Returns the value of attribute account.



462
463
464
# File 'lib/supercast/client.rb', line 462

def 
  @account
end

#api_keyObject

Returns the value of attribute api_key.



463
464
465
# File 'lib/supercast/client.rb', line 463

def api_key
  @api_key
end

#api_versionObject

Returns the value of attribute api_version.



464
465
466
# File 'lib/supercast/client.rb', line 464

def api_version
  @api_version
end

#bodyObject

Returns the value of attribute body.



461
462
463
# File 'lib/supercast/client.rb', line 461

def body
  @body
end

#idempotency_keyObject

Returns the value of attribute idempotency_key.



465
466
467
# File 'lib/supercast/client.rb', line 465

def idempotency_key
  @idempotency_key
end

#methodObject

Returns the value of attribute method.



466
467
468
# File 'lib/supercast/client.rb', line 466

def method
  @method
end

#pathObject

Returns the value of attribute path.



467
468
469
# File 'lib/supercast/client.rb', line 467

def path
  @path
end

#query_paramsObject

Returns the value of attribute query_params.



468
469
470
# File 'lib/supercast/client.rb', line 468

def query_params
  @query_params
end

Instance Method Details

#dup_from_response(resp) ⇒ Object

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.



476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
# 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. = headers['Supercast-Account']
  context.api_version = headers['Supercast-Version']
  context.idempotency_key = headers['Idempotency-Key']
  context
end