Class: RfLogger::RequestHeaders

Inherits:
Object
  • Object
show all
Defined in:
lib/rf_logger/request/request_headers.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type: "application/json", api_token: nil, request_id: self.class.request_id, other: {}, **other_key_headers) ⇒ RequestHeaders

Returns a new instance of RequestHeaders.



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/rf_logger/request/request_headers.rb', line 5

def initialize(type: "application/json",
               api_token: nil,
               request_id: self.class.request_id,
               other: {},
               **other_key_headers)
  @type              = type
  @api_token         = api_token
  @request_id        = request_id
  @content_type      = type
  @other             = other
  @other_key_headers = other_key_headers
end

Instance Attribute Details

#api_tokenObject (readonly)

Returns the value of attribute api_token.



3
4
5
# File 'lib/rf_logger/request/request_headers.rb', line 3

def api_token
  @api_token
end

#content_typeObject (readonly)

Returns the value of attribute content_type.



3
4
5
# File 'lib/rf_logger/request/request_headers.rb', line 3

def content_type
  @content_type
end

#otherObject (readonly)

Returns the value of attribute other.



3
4
5
# File 'lib/rf_logger/request/request_headers.rb', line 3

def other
  @other
end

#request_idObject (readonly)

Returns the value of attribute request_id.



3
4
5
# File 'lib/rf_logger/request/request_headers.rb', line 3

def request_id
  @request_id
end

#typeObject (readonly)

Returns the value of attribute type.



3
4
5
# File 'lib/rf_logger/request/request_headers.rb', line 3

def type
  @type
end

Class Method Details

.request_idObject



18
19
20
# File 'lib/rf_logger/request/request_headers.rb', line 18

def self.request_id
  (Thread.current.get_inheritable_attribute(:rf_logger_request_tags)||{})[:request_id]
end

Instance Method Details

#other_key_headersObject



30
31
32
# File 'lib/rf_logger/request/request_headers.rb', line 30

def other_key_headers
  @other_key_headers.each_with_object({}) { |(k, v), h| h[k.to_s.split("_").map(&:capitalize).join("-")] = v }
end

#to_hashObject



22
23
24
25
26
27
28
# File 'lib/rf_logger/request/request_headers.rb', line 22

def to_hash
  {
    "Content-Type" => content_type,
    "Api-Token"    => api_token,
    "X-Request-Id" => request_id
  }.merge(other_key_headers).merge(other).reject { |_, v| v.nil? }
end