arunthampi-injour 0.1.2 → 0.2.0

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.
@@ -8,10 +8,17 @@ An evolution of the In/Out app which 37Signals uses. A distributed In/Out, if yo
8
8
  sudo gem install arunthampi-injour --source=http://gems.github.com
9
9
 
10
10
  == Installation from Source (More reliable)
11
+ sudo gem install dnssd
11
12
  git clone git://github.com/arunthampi/injour.git
12
13
  cd injour
13
14
  rake install
14
15
 
16
+ == Useful bash aliases the author recommends
17
+ # To be put in your ~/.bash_profile
18
+ alias ise='injour serve &'
19
+ alias ist='injour st'
20
+ alias ils='injour ls'
21
+
15
22
  == Usage
16
23
 
17
24
  alice$ injour serve # Starts up publishing your statuses
data/bin/injour CHANGED
@@ -7,18 +7,16 @@ begin
7
7
  cmd = ARGV.shift
8
8
 
9
9
  case cmd
10
- when "status"
10
+ when 'status', 'st'
11
11
  Injour.set_status(ARGV.join(' '))
12
- when "st"
13
- Injour.set_status(ARGV.join(' '))
14
- when "serve"
12
+ when 'serve'
15
13
  Injour.serve(*ARGV)
16
- when "list"
14
+ when 'list', 'ls'
17
15
  Injour.list(*ARGV)
18
- when "ls"
19
- Injour.list(*ARGV)
20
- when "show"
21
- Injour.get(*ARGV)
16
+ when 'show'
17
+ Injour.get(*ARGV)
18
+ else
19
+ Injour.usage
22
20
  end
23
21
  rescue => e
24
22
  puts "ERROR: running '#{cmd}': #{e.message} (#{e.class})\n"
@@ -5,6 +5,8 @@ require "dnssd"
5
5
  require "set"
6
6
  require "socket"
7
7
  require "webrick"
8
+ require 'net/http'
9
+ require 'uri'
8
10
 
9
11
  require "injour/version"
10
12
 
@@ -37,7 +39,11 @@ show user
37
39
  HELP
38
40
  end
39
41
 
40
- def self.get(name)
42
+ def self.retrieve_status_using_http(host, port, limit)
43
+ Net::HTTP.get_response(URI.parse("http://#{host}:#{port}/?number=#{limit}")).body
44
+ end
45
+
46
+ def self.get(name, limit = 10)
41
47
  hosts = find(name)
42
48
 
43
49
  if hosts.empty?
@@ -50,23 +56,20 @@ show user
50
56
  else
51
57
  # Set is weird. There is no #[] or #at
52
58
  hosts.each do |host|
53
- sock = TCPSocket.open host.host, host.port
54
- puts sock.read
59
+ puts retrieve_status_using_http(host.host, host.port, limit)
55
60
  end
56
61
  end
57
62
  end
58
63
 
59
64
  def self.list(name = nil)
60
- return show(name) if name
65
+ return get(name) if name
61
66
  hosts = []
62
67
 
63
- waiting = Thread.current
64
-
65
68
  service = DNSSD.browse(SERVICE) do |reply|
66
69
  DNSSD.resolve(reply.name, reply.type, reply.domain) do |rr|
67
70
  host = Server.new(reply.name, rr.target, rr.port)
68
71
  unless hosts.include? host
69
- puts "#{host.name} (#{host.host}:#{host.port})"
72
+ puts "#{host.name} (#{host.host}:#{host.port}) -> #{retrieve_status_using_http(host.host, host.port, 1)}"
70
73
  hosts << host
71
74
  end
72
75
  end
@@ -78,6 +81,11 @@ show user
78
81
 
79
82
  def self.set_status(message)
80
83
  File.open(INJOUR_STATUS, 'a') { |file| file.puts("[#{Time.now.strftime("%d-%b-%Y %I:%M %p")}] #{message}") }
84
+ if message !~ /\S/
85
+ puts 'Your status has been cleared.'
86
+ else
87
+ puts "Your status has been set to '#{message}'."
88
+ end
81
89
  end
82
90
 
83
91
  def self.find(name, first=true)
@@ -96,14 +104,19 @@ show user
96
104
 
97
105
  sleep 5
98
106
  service.stop
99
-
100
107
  hosts
101
108
  end
102
109
 
103
- def self.get_status(limit = 3)
110
+ def self.get_status(limit = 5)
104
111
  File.read(INJOUR_STATUS).split("\n").reverse.slice(0, limit).join("\n")
105
112
  end
106
113
 
114
+ def self.get_limit(query_string)
115
+ (query_string.match(/number=(\d+)/)[1]).to_i || 5
116
+ rescue
117
+ 5
118
+ end
119
+
107
120
  def self.serve(name="", port=PORT)
108
121
  name = ENV['USER'] if name.empty?
109
122
 
@@ -114,20 +127,27 @@ show user
114
127
  puts "#{name}'s In/Out Records..."
115
128
  end
116
129
 
117
- log = WEBrick::Log.new(true) # true fools it
118
- def log.log(*anything); end # send it to the abyss
119
-
120
- # Open webrick babeh
121
- server = WEBrick::GenericServer.new(:Port => port.to_i, :Logger => log)
122
- # Get the latest status
130
+ # Don't log anything, everything goes in an abyss
131
+ log = WEBrick::Log.new(true)
132
+ def log.log(*anything); end
133
+ server = WEBrick::HTTPServer.new(:Port => port.to_i, :Logger => log)
134
+
135
+ # Open up a servlet, so that status can be viewed in a browser
136
+ server.mount_proc("/") do |req, res|
137
+ @logger = log
138
+ limit = get_limit(req.query_string)
139
+ res.body = get_status(limit)
140
+ res['Content-Type'] = "text/plain"
141
+ end
142
+ # Ctrl+C must quit it
123
143
  %w(INT TERM).each do |signal|
124
144
  trap signal do
125
145
  server.shutdown
126
146
  exit!
127
147
  end
128
148
  end
129
- # Get the latest status
130
- server.start { |socket| socket.print(get_status) }
149
+ # Start the server
150
+ server.start
131
151
  end
132
152
 
133
153
  end
@@ -1,3 +1,3 @@
1
1
  module Injour
2
- VERSION = "0.1.2".freeze
2
+ VERSION = "0.2.0".freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arunthampi-injour
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arun Thampi
@@ -9,7 +9,7 @@ autorequire: injour
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-06-18 00:00:00 -07:00
12
+ date: 2008-06-20 00:00:00 -07:00
13
13
  default_executable: injour
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency