lib/playback/request.rb in playback-1.0.0 vs lib/playback/request.rb in playback-1.1.0
- old
+ new
@@ -1,17 +1,18 @@
-require "playback/parser"
+require 'apache_log/parser'
require 'net/http'
require 'json'
module Playback
class Request
DEFAULT_CONTENT_TYPE = 'application/text'
DEFAULT_USER_AGENT = 'From Playback rubygems'
def initialize(base_uri)
@base_uri = base_uri
- @parser = Playback::Parser
+ @common_parser = ApacheLog::Parser.new('common')
+ @combined_parser = ApacheLog::Parser.new('combined')
end
def run(line, return_type='')
parsed_line = parse(line)
method = parsed_line[:request][:method]
@@ -25,25 +26,27 @@
result = {
method: method,
path: path,
status: res.code.to_i,
}
- res = JSON.generate result
+ res = JSON.generate(result)
end
res
rescue => e
e.message
end
+ private
+
def parse(line)
begin
- @parser.parse(line.chomp, 'combined')
+ @combined_parser.parse(line.chomp)
rescue
begin
- @parser.parse(line.chomp, 'common')
+ @common_parser.parse(line.chomp)
rescue => e
raise e
end
end
end
@@ -74,9 +77,7 @@
http.head(path, data)
else
raise "it is not supported http method: <#{method}>"
end
end
-
- private :parse, :request
end
end