Class: Zaius::RequestLogContext

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



244
245
246
# File 'lib/zaius/zaius_client.rb', line 244

def 
  @account
end

#api_keyObject

Returns the value of attribute api_key.



245
246
247
# File 'lib/zaius/zaius_client.rb', line 245

def api_key
  @api_key
end

#api_versionObject

Returns the value of attribute api_version.



246
247
248
# File 'lib/zaius/zaius_client.rb', line 246

def api_version
  @api_version
end

#bodyObject

Returns the value of attribute body.



243
244
245
# File 'lib/zaius/zaius_client.rb', line 243

def body
  @body
end

#methodObject

Returns the value of attribute method.



247
248
249
# File 'lib/zaius/zaius_client.rb', line 247

def method
  @method
end

#pathObject

Returns the value of attribute path.



248
249
250
# File 'lib/zaius/zaius_client.rb', line 248

def path
  @path
end

#query_paramsObject

Returns the value of attribute query_params.



249
250
251
# File 'lib/zaius/zaius_client.rb', line 249

def query_params
  @query_params
end

#request_idObject

Returns the value of attribute request_id.



250
251
252
# File 'lib/zaius/zaius_client.rb', line 250

def request_id
  @request_id
end

#urlObject

Returns the value of attribute url.



251
252
253
# File 'lib/zaius/zaius_client.rb', line 251

def url
  @url
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.



257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
# File 'lib/zaius/zaius_client.rb', line 257

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