Class: Coinbase::Correlation

Inherits:
Faraday::Middleware
  • Object
show all
Defined in:
lib/coinbase/correlation.rb

Overview

A middleware that injects correlation data into the request headers.

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Correlation

Initializes the Correlation middleware.

Parameters:

  • app (Faraday::Connection)

    The Faraday connection



11
12
13
14
# File 'lib/coinbase/correlation.rb', line 11

def initialize(app)
  super(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object

Processes the request by adding the Correlation Data to the request headers.

Parameters:

  • env (Faraday::Env)

    The Faraday request environment



18
19
20
21
# File 'lib/coinbase/correlation.rb', line 18

def call(env)
  env.request_headers['Correlation-Context'] = correlation_data
  @app.call(env)
end

#correlation_dataObject



23
24
25
26
27
28
# File 'lib/coinbase/correlation.rb', line 23

def correlation_data
  @correlation_data ||= {
    sdk_version: Coinbase::VERSION,
    sdk_language: 'ruby'
  }.map { |key, val| "#{key}=#{CGI.escape(val)}" }.join(',')
end