wsio 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (8) hide show
  1. data.tar.gz.sig +0 -0
  2. data/README +16 -6
  3. data/Rakefile +1 -1
  4. data/bin/wsio +1 -0
  5. data/lib/wsio.rb +12 -14
  6. data/wsio.gemspec +1 -1
  7. metadata +2 -2
  8. 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. Example:
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* behind a NAT to watch the logs:
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
- wsio -l somehost/log
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
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
  require 'rake'
3
3
  require 'echoe'
4
4
 
5
- Echoe.new('wsio', '0.0.3') do |p|
5
+ Echoe.new('wsio', '0.0.4') do |p|
6
6
  p.description = "Web stream input/output tool"
7
7
  p.url = "http://github.com/progrium/wsio"
8
8
  p.author = "Jeff Lindsay"
data/bin/wsio CHANGED
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'rubygems'
3
3
  require 'wsio'
4
+ #require 'lib/wsio'
4
5
 
5
6
  help =<<EOF
6
7
  Usage: wsio [options] [user[:pass]@][hostname][path]
@@ -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
- c = HTTPClient.new
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 = {"Content-Type" => "application/json"}
40
+ headers["Content-Type"] = "application/json"
37
41
  elsif obj.is_a? Array
38
42
  body = obj.first.to_s
39
- headers = {"Content-Type" => "text/plain"}
43
+ headers["Content-Type"] = "text/plain"
40
44
  else
41
45
  body = obj.to_s
42
- headers = {"Content-Type" => "text/plain"}
46
+ headers["Content-Type"] = "text/plain"
43
47
  end
44
48
  rescue JSON::ParserError
45
49
  body = line.strip
46
- if body.split('&').collect{|m| /^[^&^=]+=[^&^=]+$/.match(m) }.all?
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
- c = HTTPClient.new
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
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{wsio}
5
- s.version = "0.0.3"
5
+ s.version = "0.0.4"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Jeff Lindsay"]
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 3
9
- version: 0.0.3
8
+ - 4
9
+ version: 0.0.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - Jeff Lindsay
metadata.gz.sig CHANGED
Binary file