playback 1.1.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -4
- data/lib/playback.rb +0 -4
- data/lib/playback/request.rb +23 -44
- data/lib/playback/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 047d1f2495190a640bc69a27cac7ccd8c947b410
|
4
|
+
data.tar.gz: 78ce24836ece75f735de0480260204ee7740574b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ee385541f2c0c9256f87043c08ac1da99835716d94054191be0d610d698306404492d3a8b208a14d91aeb2eb6ce58545808dba6c9b09274db5684c157f87d97e
|
7
|
+
data.tar.gz: 62b0f255d0cc4933564fcacec00ee53ecb8472fac52450d97852361dd600d04dab010c21650d2ce862192b3155584342192d784bdac1468b19bb732e9d8c8db0
|
data/README.md
CHANGED
@@ -1,6 +1,5 @@
|
|
1
|
-
# Playback
|
2
|
-
|
3
|
-
Execute http request from apache access log
|
1
|
+
# Playback [![Build Status](https://travis-ci.org/takady/playback.svg?branch=master)](https://travis-ci.org/takady/playback) [![Code Climate](https://codeclimate.com/github/takady/playback/badges/gpa.svg)](https://codeclimate.com/github/takady/playback)
|
2
|
+
Execute http request from apache access log
|
4
3
|
|
5
4
|
## Installation
|
6
5
|
|
@@ -10,7 +9,7 @@ Execute http request from apache access log
|
|
10
9
|
|
11
10
|
### as a command line tool
|
12
11
|
```sh
|
13
|
-
playback 'http://httpbin.org' /path/to/access.log
|
12
|
+
$ playback 'http://httpbin.org' /path/to/access.log
|
14
13
|
#=> { "method": "GET", "path": "/get", "status": 200 }
|
15
14
|
#=> { "method": "POST", "path": "/post?hoge=1", "status": 404 }
|
16
15
|
#=> { "method": "PUT", "path": "/put?foo=bar", "status": 200 }
|
data/lib/playback.rb
CHANGED
data/lib/playback/request.rb
CHANGED
@@ -7,74 +7,53 @@ module Playback
|
|
7
7
|
DEFAULT_CONTENT_TYPE = 'application/text'
|
8
8
|
DEFAULT_USER_AGENT = 'From Playback rubygems'
|
9
9
|
|
10
|
+
PARSER = ApacheLog::Parser
|
11
|
+
|
12
|
+
REQUEST_WITHOUT_BODY = %w(GET DELETE HEAD)
|
13
|
+
REQUEST_WITH_BODY = %w(POST PUT PATCH)
|
14
|
+
|
10
15
|
def initialize(base_uri)
|
11
16
|
@base_uri = base_uri
|
12
|
-
@common_parser =
|
13
|
-
@combined_parser =
|
17
|
+
@common_parser = PARSER.new('common')
|
18
|
+
@combined_parser = PARSER.new('combined')
|
14
19
|
end
|
15
20
|
|
16
21
|
def run(line, return_type='')
|
17
|
-
parsed_line =
|
18
|
-
method = parsed_line[:request][:method]
|
19
|
-
path = parsed_line[:request][:path]
|
20
|
-
referer = parsed_line[:referer] ||= ''
|
21
|
-
user_agent = parsed_line[:user_agent] ||= DEFAULT_USER_AGENT
|
22
|
+
parsed_line = parse_log(line)
|
22
23
|
|
23
|
-
|
24
|
+
method = parsed_line[:request][:method]
|
25
|
+
path = parsed_line[:request][:path]
|
26
|
+
referer = parsed_line[:referer] ||= ''
|
27
|
+
user_agent = parsed_line[:user_agent] ||= DEFAULT_USER_AGENT
|
24
28
|
|
25
|
-
|
26
|
-
result = {
|
27
|
-
method: method,
|
28
|
-
path: path,
|
29
|
-
status: res.code.to_i,
|
30
|
-
}
|
31
|
-
res = JSON.generate(result)
|
32
|
-
end
|
29
|
+
response = request(method, path, referer, user_agent)
|
33
30
|
|
34
|
-
|
31
|
+
return response if return_type == 'net-http'
|
35
32
|
|
33
|
+
{method: method, path: path, status: response.code.to_i}.to_json
|
36
34
|
rescue => e
|
37
35
|
e.message
|
38
36
|
end
|
39
37
|
|
40
38
|
private
|
41
39
|
|
42
|
-
def
|
40
|
+
def parse_log(line)
|
43
41
|
begin
|
44
42
|
@combined_parser.parse(line.chomp)
|
45
43
|
rescue
|
46
|
-
|
47
|
-
@common_parser.parse(line.chomp)
|
48
|
-
rescue => e
|
49
|
-
raise e
|
50
|
-
end
|
44
|
+
@common_parser.parse(line.chomp)
|
51
45
|
end
|
52
46
|
end
|
53
47
|
|
54
48
|
def request(method, path, referer, user_agent)
|
55
|
-
|
56
|
-
uri = URI.parse(@base_uri + path)
|
57
|
-
rescue
|
58
|
-
raise "it can not be recognized as a uri: <#{@base_uri + path}>"
|
59
|
-
end
|
60
|
-
|
49
|
+
uri = URI.parse("#{@base_uri}#{path}")
|
61
50
|
http = Net::HTTP.new(uri.host, uri.port)
|
62
|
-
|
63
|
-
data = {'Content-Type' => DEFAULT_CONTENT_TYPE, 'Referer' => referer, 'User-Agent' => user_agent}
|
51
|
+
header = {'Content-Type' => DEFAULT_CONTENT_TYPE, 'Referer' => referer, 'User-Agent' => user_agent}
|
64
52
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
http.post(uri.path, query, data)
|
70
|
-
when 'PUT'
|
71
|
-
http.put(uri.path, query, data)
|
72
|
-
when 'DELETE'
|
73
|
-
http.delete(path, data)
|
74
|
-
when 'PATCH'
|
75
|
-
http.patch(uri.path, query, data)
|
76
|
-
when 'HEAD'
|
77
|
-
http.head(path, data)
|
53
|
+
if REQUEST_WITHOUT_BODY.include?(method)
|
54
|
+
http.send(method.downcase, path, header)
|
55
|
+
elsif REQUEST_WITH_BODY.include?(method)
|
56
|
+
http.send(method.downcase, uri.path, uri.query, header)
|
78
57
|
else
|
79
58
|
raise "it is not supported http method: <#{method}>"
|
80
59
|
end
|
data/lib/playback/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: playback
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yuichi Takada
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-06-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -108,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
108
108
|
version: '0'
|
109
109
|
requirements: []
|
110
110
|
rubyforge_project:
|
111
|
-
rubygems_version: 2.
|
111
|
+
rubygems_version: 2.4.5
|
112
112
|
signing_key:
|
113
113
|
specification_version: 4
|
114
114
|
summary: Execute http request from apache access log
|