Class: Playback::Request

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

Constant Summary collapse

DEFAULT_CONTENT_TYPE =
'application/text'
DEFAULT_USER_AGENT =
'From Playback rubygems'
PARSER =
ApacheLog::Parser
REQUEST_WITHOUT_BODY =
%w(GET DELETE HEAD)
REQUEST_WITH_BODY =
%w(POST PUT PATCH)

Instance Method Summary collapse

Constructor Details

#initialize(base_uri) ⇒ Request

Returns a new instance of Request.


15
16
17
18
19
# File 'lib/playback/request.rb', line 15

def initialize(base_uri)
  @base_uri = base_uri
  @common_parser = PARSER.new('common')
  @combined_parser = PARSER.new('combined')
end

Instance Method Details

#run(line, return_type = '') ⇒ Object


21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/playback/request.rb', line 21

def run(line, return_type='')
  parsed_line = parse_log(line)

  method     = parsed_line[:request][:method]
  path       = parsed_line[:request][:path]
  referer    = parsed_line[:referer] ||= ''
  user_agent = parsed_line[:user_agent] ||= DEFAULT_USER_AGENT

  response = request(method, path, referer, user_agent)

  return response if return_type == 'net-http'

  {method: method, path: path, status: response.code.to_i}.to_json
rescue => e
  e.message
end