Class: NewStoreApi::RequestContext

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/new_store_api/models/request_context.rb

Overview

The HTTP request that carried the audited change.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#check_for_conflict, #process_additional_properties, #process_array, #process_basic_value, #process_hash, #to_hash, #to_json

Constructor Details

#initialize(method = SKIP, path = SKIP, request_id = SKIP, source_ip = SKIP, trace_id = SKIP, user_agent = SKIP) ⇒ RequestContext

Returns a new instance of RequestContext.



65
66
67
68
69
70
71
72
73
# File 'lib/new_store_api/models/request_context.rb', line 65

def initialize(method = SKIP, path = SKIP, request_id = SKIP,
               source_ip = SKIP, trace_id = SKIP, user_agent = SKIP)
  @method = method unless method == SKIP
  @path = path unless path == SKIP
  @request_id = request_id unless request_id == SKIP
  @source_ip = source_ip unless source_ip == SKIP
  @trace_id = trace_id unless trace_id == SKIP
  @user_agent = user_agent unless user_agent == SKIP
end

Instance Attribute Details

#methodString

HTTP method.

Returns:

  • (String)


14
15
16
# File 'lib/new_store_api/models/request_context.rb', line 14

def method
  @method
end

#pathString

HTTP URL path.

Returns:

  • (String)


18
19
20
# File 'lib/new_store_api/models/request_context.rb', line 18

def path
  @path
end

#request_idString

X-Newstore-Request-Id header.

Returns:

  • (String)


22
23
24
# File 'lib/new_store_api/models/request_context.rb', line 22

def request_id
  @request_id
end

#source_ipString

Client IP (first X-Forwarded-For hop, else RemoteAddr).

Returns:

  • (String)


26
27
28
# File 'lib/new_store_api/models/request_context.rb', line 26

def source_ip
  @source_ip
end

#trace_idString

W3C traceparent trace-id segment.

Returns:

  • (String)


30
31
32
# File 'lib/new_store_api/models/request_context.rb', line 30

def trace_id
  @trace_id
end

#user_agentString

User-Agent header.

Returns:

  • (String)


34
35
36
# File 'lib/new_store_api/models/request_context.rb', line 34

def user_agent
  @user_agent
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/new_store_api/models/request_context.rb', line 76

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  method = hash.key?('method') ? hash['method'] : SKIP
  path = hash.key?('path') ? hash['path'] : SKIP
  request_id = hash.key?('request_id') ? hash['request_id'] : SKIP
  source_ip = hash.key?('source_ip') ? hash['source_ip'] : SKIP
  trace_id = hash.key?('trace_id') ? hash['trace_id'] : SKIP
  user_agent = hash.key?('user_agent') ? hash['user_agent'] : SKIP

  # Create object from extracted values.
  RequestContext.new(method,
                     path,
                     request_id,
                     source_ip,
                     trace_id,
                     user_agent)
end

.namesObject

A mapping from model property names to API property names.



37
38
39
40
41
42
43
44
45
46
# File 'lib/new_store_api/models/request_context.rb', line 37

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['method'] = 'method'
  @_hash['path'] = 'path'
  @_hash['request_id'] = 'request_id'
  @_hash['source_ip'] = 'source_ip'
  @_hash['trace_id'] = 'trace_id'
  @_hash['user_agent'] = 'user_agent'
  @_hash
end

.nullablesObject

An array for nullable fields



61
62
63
# File 'lib/new_store_api/models/request_context.rb', line 61

def self.nullables
  []
end

.optionalsObject

An array for optional fields



49
50
51
52
53
54
55
56
57
58
# File 'lib/new_store_api/models/request_context.rb', line 49

def self.optionals
  %w[
    method
    path
    request_id
    source_ip
    trace_id
    user_agent
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



104
105
106
107
108
109
# File 'lib/new_store_api/models/request_context.rb', line 104

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} method: #{@method.inspect}, path: #{@path.inspect}, request_id:"\
  " #{@request_id.inspect}, source_ip: #{@source_ip.inspect}, trace_id: #{@trace_id.inspect},"\
  " user_agent: #{@user_agent.inspect}>"
end

#to_sObject

Provides a human-readable string representation of the object.



97
98
99
100
101
# File 'lib/new_store_api/models/request_context.rb', line 97

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} method: #{@method}, path: #{@path}, request_id: #{@request_id}, source_ip:"\
  " #{@source_ip}, trace_id: #{@trace_id}, user_agent: #{@user_agent}>"
end