Class: Vigiles::ConversationRecorders::ApplicationJson

Inherits:
Vigiles::ConversationRecorder show all
Includes:
Singleton
Defined in:
lib/vigiles/conversation_recorders/application_json.rb

Constant Summary collapse

ConversationRecorder =
Vigiles::ConversationRecorder
ContentType =
Vigiles::Types::ContentType
Conversation =
Vigiles::Archive::Conversation
Response =
Vigiles::Archive::Response
Metadata =
Vigiles::Archive::Metadata
Request =
Vigiles::Archive::Request
Extras =
Vigiles::Archive::Extras

Instance Method Summary collapse

Instance Method Details

#record(req:, res:) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/vigiles/conversation_recorders/application_json.rb', line 28

def record(req:, res:)
  ensure_content_type_matches!(req)

  response = Response.from(res)
  request  = Request.from(req)
  Conversation.create!(
    request_content_type: request.content_type,
    request_user_agent: request.user_agent,
    request_timestamp: request.timestamp,
    request_remote_ip: request.remote_ip,
    request_protocol: request.protocol,
    request_headers: request.headers,
    request_origin: request.origin,
    request_payload: request.payload,
    request_method: request.http_method.serialize,
    request_path: request.path,
    request_url: request.url,
    request_id: request.id,
    response_content_type: response.content_type,
    response_headers: response.headers,
    response_payload: response.payload,
    response_status: response.status
  )
end