30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/frilans_finans_api/parse_log.rb', line 30
def self.call(filename)
lines = []
File.foreach(filename) do |log_line|
next unless log_line.index('[FrilansFinansAPI::Request]')
body_match = 'BODY: '
body_match_index = log_line.index(body_match)
body_content_index = body_match_index + body_match.length
body_json = log_line[body_content_index..-1].strip
body = JSON.parse(body_json)
status = string_between_markers(log_line, ' STATUS: ', ' BODY: ')
json_string = string_between_markers(log_line, ' PARAMS: ', ' STATUS: ')
params = JSON.parse(json_string)
uri = string_between_markers(log_line, ' URI: ', ' PARAMS: ')
lines << LogRequest.new(uri: uri, params: params, body: body, status: status)
end
lines
end
|