Class: Mirakl::MiraklClient::RequestLogContext

Inherits:
Object
  • Object
show all
Defined in:
lib/mirakl/mirakl_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.



445
446
447
# File 'lib/mirakl/mirakl_client.rb', line 445

def api_key
  @api_key
end

#bodyObject

Returns the value of attribute body.



444
445
446
# File 'lib/mirakl/mirakl_client.rb', line 444

def body
  @body
end

#methodObject

Returns the value of attribute method.



446
447
448
# File 'lib/mirakl/mirakl_client.rb', line 446

def method
  @method
end

#pathObject

Returns the value of attribute path.



447
448
449
# File 'lib/mirakl/mirakl_client.rb', line 447

def path
  @path
end

#query_paramsObject

Returns the value of attribute query_params.



448
449
450
# File 'lib/mirakl/mirakl_client.rb', line 448

def query_params
  @query_params
end

#request_idObject

Returns the value of attribute request_id.



449
450
451
# File 'lib/mirakl/mirakl_client.rb', line 449

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



457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
# File 'lib/mirakl/mirakl_client.rb', line 457

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
end