Class: Helio::HelioClient::RequestLogContext
- Inherits:
-
Object
- Object
- Helio::HelioClient::RequestLogContext
- Defined in:
- lib/helio/helio_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
-
#api_id ⇒ Object
Returns the value of attribute api_id.
-
#api_token ⇒ Object
Returns the value of attribute api_token.
-
#api_version ⇒ Object
Returns the value of attribute api_version.
-
#body ⇒ Object
Returns the value of attribute body.
-
#idempotency_key ⇒ Object
Returns the value of attribute idempotency_key.
-
#method ⇒ Object
Returns the value of attribute method.
-
#path ⇒ Object
Returns the value of attribute path.
-
#query_params ⇒ Object
Returns the value of attribute query_params.
-
#request_id ⇒ Object
Returns the value of attribute request_id.
Instance Method Summary collapse
-
#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.
Instance Attribute Details
#api_id ⇒ Object
Returns the value of attribute api_id.
452 453 454 |
# File 'lib/helio/helio_client.rb', line 452 def api_id @api_id end |
#api_token ⇒ Object
Returns the value of attribute api_token.
453 454 455 |
# File 'lib/helio/helio_client.rb', line 453 def api_token @api_token end |
#api_version ⇒ Object
Returns the value of attribute api_version.
454 455 456 |
# File 'lib/helio/helio_client.rb', line 454 def api_version @api_version end |
#body ⇒ Object
Returns the value of attribute body.
451 452 453 |
# File 'lib/helio/helio_client.rb', line 451 def body @body end |
#idempotency_key ⇒ Object
Returns the value of attribute idempotency_key.
455 456 457 |
# File 'lib/helio/helio_client.rb', line 455 def idempotency_key @idempotency_key end |
#method ⇒ Object
Returns the value of attribute method.
456 457 458 |
# File 'lib/helio/helio_client.rb', line 456 def method @method end |
#path ⇒ Object
Returns the value of attribute path.
457 458 459 |
# File 'lib/helio/helio_client.rb', line 457 def path @path end |
#query_params ⇒ Object
Returns the value of attribute query_params.
458 459 460 |
# File 'lib/helio/helio_client.rb', line 458 def query_params @query_params end |
#request_id ⇒ Object
Returns the value of attribute request_id.
459 460 461 |
# File 'lib/helio/helio_client.rb', line 459 def request_id @request_id 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 Helio-Version header beyond what configuration information that we might have had available.
467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 |
# File 'lib/helio/helio_client.rb', line 467 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.api_id = headers["X-API-ID"] context.api_version = headers["Helio-Version"] context.idempotency_key = headers["Idempotency-Key"] context.request_id = headers["Request-Id"] context end |