wsio 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +0 -0
- data/README +16 -6
- data/Rakefile +1 -1
- data/bin/wsio +1 -0
- data/lib/wsio.rb +12 -14
- data/wsio.gemspec +1 -1
- metadata +2 -2
- metadata.gz.sig +0 -0
data.tar.gz.sig
CHANGED
Binary file
|
data/README
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
wsio -- web stream input/output tool
|
2
2
|
|
3
|
+
Install: gem install wsio
|
4
|
+
|
3
5
|
Usage: wsio [options] [user[:pass]@][hostname][path]
|
4
6
|
-l Listen to stream and print to STDOUT
|
5
7
|
-s Use HTTPS
|
@@ -11,10 +13,7 @@ This tool is similar to netcat in that it's intended to be used with STDIN and
|
|
11
13
|
STDOUT, making it perfect for command pipelining. However, instead of direct
|
12
14
|
point to point TCP/UDP connections, it uses HTTP. Coupled with a server that
|
13
15
|
provides realtime pubsub over HTTP and you have one of the most magical tools
|
14
|
-
ever.
|
15
|
-
|
16
|
-
Log Aggregation
|
17
|
-
===============
|
16
|
+
ever. Here's a toy log aggregation example:
|
18
17
|
|
19
18
|
Run this on one or several machines:
|
20
19
|
|
@@ -24,6 +23,17 @@ Run this on your central aggregator:
|
|
24
23
|
|
25
24
|
wsio -l somehost/log > /var/log/aggregate
|
26
25
|
|
27
|
-
Run this on your *laptop
|
26
|
+
Run this on your *laptop behind a NAT* to watch the logs:
|
27
|
+
|
28
|
+
wsio -l somehost/log
|
29
|
+
|
30
|
+
|
31
|
+
Obviously there is a server-side component to this. It's not that complicated
|
32
|
+
and there are some servers that already implement streams this way.
|
33
|
+
|
34
|
+
For example, Twitter's Stream API:
|
35
|
+
|
36
|
+
wsio -l <user>:<pass>@stream.twitter.com/1/statuses/sample.json
|
28
37
|
|
29
|
-
|
38
|
+
However, wsio was made with a particular server-side component in mind. If you
|
39
|
+
are interested in this, please email me.
|
data/Rakefile
CHANGED
data/bin/wsio
CHANGED
data/lib/wsio.rb
CHANGED
@@ -17,9 +17,13 @@ def start(args)
|
|
17
17
|
args = args.join.gsub('-', '')
|
18
18
|
scheme = (args.include? 's') ? 'https' : 'http'
|
19
19
|
url = "#{scheme}://#{host_and_path}"
|
20
|
+
client = HTTPClient.new
|
21
|
+
client.ssl_config.verify_mode = nil if args.include? 'k'
|
22
|
+
#client.set_auth(url, 'user', 'pass') if user ## This doesn't work?
|
23
|
+
headers = {}
|
24
|
+
headers['Authorization'] = "Basic #{Base64.encode64([user,pass].join(':')).gsub("\n",'')}" if user # Fix set_auth
|
20
25
|
if args.include? 'l'
|
21
|
-
|
22
|
-
c.get_content(url) do |chunk|
|
26
|
+
client.get_content(url, nil, headers) do |chunk|
|
23
27
|
obj = JSON.parse(chunk)
|
24
28
|
if obj.is_a? Array
|
25
29
|
puts obj.first
|
@@ -33,27 +37,21 @@ def start(args)
|
|
33
37
|
obj = JSON.parse(line)
|
34
38
|
if obj.is_a? Hash
|
35
39
|
body = line
|
36
|
-
headers
|
40
|
+
headers["Content-Type"] = "application/json"
|
37
41
|
elsif obj.is_a? Array
|
38
42
|
body = obj.first.to_s
|
39
|
-
headers
|
43
|
+
headers["Content-Type"] = "text/plain"
|
40
44
|
else
|
41
45
|
body = obj.to_s
|
42
|
-
headers
|
46
|
+
headers["Content-Type"] = "text/plain"
|
43
47
|
end
|
44
48
|
rescue JSON::ParserError
|
45
49
|
body = line.strip
|
46
|
-
|
47
|
-
headers =
|
48
|
-
else
|
49
|
-
headers = {"Content-Type" => "text/plain"}
|
50
|
+
unless body.split('&').collect{|m| /^[^&^=]+=[^&^=]+$/.match(m) }.all?
|
51
|
+
headers["Content-Type"] = "text/plain"
|
50
52
|
end
|
51
53
|
end
|
52
|
-
|
53
|
-
#c.set_auth(url, 'user', 'pass') if user ## This doesn't work?
|
54
|
-
headers['Authorization'] = "Basic #{Base64.encode64([user,pass].join(':')).gsub("\n",'')}" if user # Fix set_auth
|
55
|
-
c.ssl_config.verify_mode = nil if args.include? 'k'
|
56
|
-
resp = c.post(url, body, headers)
|
54
|
+
resp = client.post(url, body, headers)
|
57
55
|
if resp.status != 200
|
58
56
|
puts resp.content
|
59
57
|
end
|
data/wsio.gemspec
CHANGED
metadata
CHANGED
metadata.gz.sig
CHANGED
Binary file
|