auger 1.3.1 → 1.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/bin/aug +0 -19
- data/lib/plugins/http.rb +51 -7
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.3.
|
1
|
+
1.3.2
|
data/bin/aug
CHANGED
@@ -55,25 +55,6 @@ cfg =
|
|
55
55
|
raise ArgumentError, "config #{ARGV[0]} not found"
|
56
56
|
end
|
57
57
|
|
58
|
-
## pretty ascii output for different result outcomes
|
59
|
-
def format_outcome(outcome)
|
60
|
-
case outcome
|
61
|
-
when TrueClass then
|
62
|
-
"\u2713".color(:green)
|
63
|
-
when MatchData then # boolean if no captures, otherwise list captures
|
64
|
-
(outcome.captures.empty? ? "\u2713" : outcome.captures.join(' '))
|
65
|
-
.color(:green)
|
66
|
-
when FalseClass then
|
67
|
-
"\u2717".color(:red)
|
68
|
-
when NilClass then
|
69
|
-
"nil".color(:red)
|
70
|
-
when Exception then
|
71
|
-
"#{outcome.class}: #{outcome.to_s}".color(:magenta)
|
72
|
-
else
|
73
|
-
outcome.to_s.color(:green)
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
58
|
## pretty-print Result object
|
78
59
|
module Auger
|
79
60
|
class Result
|
data/lib/plugins/http.rb
CHANGED
@@ -1,3 +1,23 @@
|
|
1
|
+
## HTTP plugin for auger; requests look like this:
|
2
|
+
##
|
3
|
+
## http 80 do
|
4
|
+
##
|
5
|
+
## get "/foo" do
|
6
|
+
## header "User-Agent: AugerExample/1.0"
|
7
|
+
## test "HTTP Status Code" do |r|
|
8
|
+
## Result r.code, r.code == 200
|
9
|
+
## end
|
10
|
+
## end
|
11
|
+
##
|
12
|
+
## post "/bar" do
|
13
|
+
## data :a => "hello", :b => "world"
|
14
|
+
## test "POST request body" do |r|
|
15
|
+
## r.body
|
16
|
+
## end
|
17
|
+
## end
|
18
|
+
##
|
19
|
+
## end
|
20
|
+
|
1
21
|
require "net/http"
|
2
22
|
|
3
23
|
module Auger
|
@@ -17,8 +37,11 @@ module Auger
|
|
17
37
|
|
18
38
|
class Http < Auger::Connection
|
19
39
|
def get(url, &block)
|
20
|
-
@
|
21
|
-
|
40
|
+
@requests << Auger::HttpGet.load(url, &block)
|
41
|
+
end
|
42
|
+
|
43
|
+
def post(url, &block)
|
44
|
+
@requests << Auger::HttpPost.load(url, &block)
|
22
45
|
end
|
23
46
|
|
24
47
|
def open(host, options)
|
@@ -38,13 +61,19 @@ module Auger
|
|
38
61
|
end
|
39
62
|
|
40
63
|
class HttpRequest < Auger::Request
|
41
|
-
attr_accessor :headers, :user, :password
|
64
|
+
attr_accessor :method, :headers, :user, :password, :data
|
42
65
|
|
43
66
|
def initialize(url)
|
67
|
+
@method ||= :get # default
|
44
68
|
@headers = {}
|
69
|
+
@data = {}
|
45
70
|
super
|
46
71
|
end
|
47
72
|
|
73
|
+
def data(hash)
|
74
|
+
@data = hash
|
75
|
+
end
|
76
|
+
|
48
77
|
def header(h)
|
49
78
|
key, value = h.split /\s*:\s*/
|
50
79
|
@headers[key] = value
|
@@ -59,12 +88,27 @@ module Auger
|
|
59
88
|
end
|
60
89
|
|
61
90
|
def run(http)
|
62
|
-
|
63
|
-
|
64
|
-
@headers.each { |k,v|
|
65
|
-
|
91
|
+
request = Net::HTTP::const_get(@method.capitalize).new(@arg) # e.g. Net::HTTP::Get
|
92
|
+
request.basic_auth(@user, @password || '') if @user
|
93
|
+
@headers.each { |k,v| request[k] = v }
|
94
|
+
request.set_form_data(@data)
|
95
|
+
http.request(request)
|
66
96
|
end
|
67
97
|
|
68
98
|
end
|
69
99
|
|
100
|
+
class HttpGet < Auger::HttpRequest
|
101
|
+
def initialize(url)
|
102
|
+
@method = :get
|
103
|
+
super
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
class HttpPost < Auger::HttpRequest
|
108
|
+
def initialize(url)
|
109
|
+
@method = :post
|
110
|
+
super
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
70
114
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: auger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-06-
|
13
|
+
date: 2012-06-26 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: json
|