Class: LogSpy::Payload

Inherits:
Object
  • Object
show all
Defined in:
lib/log_spy/payload.rb

Instance Method Summary collapse

Constructor Details

#initialize(req, res, begin_at, error = nil) ⇒ Payload

Returns a new instance of Payload.



3
4
5
6
7
8
# File 'lib/log_spy/payload.rb', line 3

def initialize req, res, begin_at, error = nil
  @req = req
  @res = res
  @error = error
  @begin_at = begin_at
end

Instance Method Details

#to_jsonObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/log_spy/payload.rb', line 10

def to_json
  hash = {
    :path => @req.path,
    :status => @res.status,
    :execution_time => @res.duration,
    :begin_at => @begin_at,
    :request => {
      :content_type => @req.content_type,
      :request_method => @req.request_method,
      :ip => @req.ip,
      :query_string => @req.query_string,
      :cookies => @req.cookies,
      :body => request_body
    }
  }

  append_error_if_exists(hash)
  append_controller_action_if_exists(hash)

  hash.to_json
end