Class: Telnyx::TelnyxClient::RequestLogContext

Inherits:
Object
  • Object
show all
Defined in:
lib/telnyx/telnyx_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

#api_keyObject

Returns the value of attribute api_key.



431
432
433
# File 'lib/telnyx/telnyx_client.rb', line 431

def api_key
  @api_key
end

#bodyObject

Returns the value of attribute body.



430
431
432
# File 'lib/telnyx/telnyx_client.rb', line 430

def body
  @body
end

#methodObject

Returns the value of attribute method.



432
433
434
# File 'lib/telnyx/telnyx_client.rb', line 432

def method
  @method
end

#pathObject

Returns the value of attribute path.



433
434
435
# File 'lib/telnyx/telnyx_client.rb', line 433

def path
  @path
end

#query_paramsObject

Returns the value of attribute query_params.



434
435
436
# File 'lib/telnyx/telnyx_client.rb', line 434

def query_params
  @query_params
end

#request_idObject

Returns the value of attribute request_id.



435
436
437
# File 'lib/telnyx/telnyx_client.rb', line 435

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 ‘Telnyx-Version` header beyond what configuration information that we might have had available.



443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
# File 'lib/telnyx/telnyx_client.rb', line 443

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.request_id = headers["X-Request-Id"]
  context
end