crnixon-appjour 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +30 -0
- data/Rakefile +65 -0
- data/bin/appjour +38 -0
- data/lib/appjour.rb +99 -0
- data/lib/appjour/version.rb +3 -0
- metadata +66 -0
data/README.rdoc
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
= Appjour
|
2
|
+
|
3
|
+
Publish your app in the ether using Bonjour.
|
4
|
+
|
5
|
+
== Installation
|
6
|
+
|
7
|
+
sudo gem install dnssd
|
8
|
+
sudo gem install lachie-appjour --source=http://gems.github.com
|
9
|
+
|
10
|
+
== Usage
|
11
|
+
|
12
|
+
rincewind$ appjour leet_merb 4000
|
13
|
+
Publishing leet_merb on 4000
|
14
|
+
Announcing leet_merb...
|
15
|
+
|
16
|
+
death$ appjour leet_merb
|
17
|
+
# ... leet_merb pops up in web browser ...
|
18
|
+
|
19
|
+
death$ appjour
|
20
|
+
Searching for servers (3 seconds)
|
21
|
+
found web app called 'leet_merb'
|
22
|
+
|
23
|
+
# use the username if only the port is specified
|
24
|
+
rincewind$ appjour 4001
|
25
|
+
Publishing lachie on 4001
|
26
|
+
Announcing lachie...
|
27
|
+
|
28
|
+
== TODO
|
29
|
+
|
30
|
+
* make useable as Rails or Merb plugin for automatic publishing of apps
|
data/Rakefile
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
require "date"
|
2
|
+
require "fileutils"
|
3
|
+
require "rubygems"
|
4
|
+
require "rake/gempackagetask"
|
5
|
+
require "spec/rake/spectask"
|
6
|
+
|
7
|
+
require "./lib/appjour/version.rb"
|
8
|
+
|
9
|
+
appjour_gemspec = Gem::Specification.new do |s|
|
10
|
+
s.name = "appjour"
|
11
|
+
s.version = Appjour::VERSION
|
12
|
+
s.platform = Gem::Platform::RUBY
|
13
|
+
s.has_rdoc = true
|
14
|
+
s.extra_rdoc_files = ["README.rdoc"]
|
15
|
+
s.summary = "Announce an app over bonjour"
|
16
|
+
s.description = s.summary
|
17
|
+
s.authors = ["Lachie"]
|
18
|
+
s.email = "lachiec@gmail.com"
|
19
|
+
s.homepage = "http://github.com/lachie/appjour"
|
20
|
+
s.require_path = "lib"
|
21
|
+
s.autorequire = "appjour"
|
22
|
+
s.files = %w(README.rdoc Rakefile) + Dir.glob("{bin,lib,spec}/**/*")
|
23
|
+
s.executables = %w(appjour)
|
24
|
+
|
25
|
+
s.add_dependency "dnssd", ">= 0.6.0"
|
26
|
+
end
|
27
|
+
|
28
|
+
Rake::GemPackageTask.new(appjour_gemspec) do |pkg|
|
29
|
+
pkg.gem_spec = appjour_gemspec
|
30
|
+
end
|
31
|
+
|
32
|
+
namespace :gem do
|
33
|
+
namespace :spec do
|
34
|
+
desc "Update appjour.gemspec"
|
35
|
+
task :generate do
|
36
|
+
File.open("appjour.gemspec", "w") do |f|
|
37
|
+
f.puts(appjour_gemspec.to_ruby)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
desc "test spec in github cleanroom"
|
42
|
+
task :test do
|
43
|
+
require 'rubygems/specification'
|
44
|
+
data = File.read('appjour.gemspec')
|
45
|
+
spec = nil
|
46
|
+
Thread.new { spec = eval("$SAFE = 3\n#{data}") }.join
|
47
|
+
puts spec
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
task :install => :package do
|
53
|
+
sh %{sudo gem install pkg/appjour-#{Appjour::VERSION}}
|
54
|
+
end
|
55
|
+
|
56
|
+
desc "Run all specs"
|
57
|
+
Spec::Rake::SpecTask.new do |t|
|
58
|
+
t.spec_files = FileList["spec/**/*_spec.rb"]
|
59
|
+
t.spec_opts = ["--options", "spec/spec.opts"]
|
60
|
+
end
|
61
|
+
|
62
|
+
task :default => :spec
|
63
|
+
|
64
|
+
desc "Remove all generated artifacts"
|
65
|
+
task :clean => :clobber_package
|
data/bin/appjour
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# $:.unshift File.dirname(__FILE__)+"/../lib"
|
4
|
+
|
5
|
+
require "rubygems"
|
6
|
+
require "appjour"
|
7
|
+
|
8
|
+
|
9
|
+
help = ARGV.delete("-h")
|
10
|
+
|
11
|
+
|
12
|
+
name = ARGV.shift
|
13
|
+
port = ARGV.shift
|
14
|
+
|
15
|
+
if name && !port
|
16
|
+
begin
|
17
|
+
port = Integer(name)
|
18
|
+
name = ENV["USER"]
|
19
|
+
rescue ArgumentError
|
20
|
+
port = nil
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
if help
|
25
|
+
puts <<-EOH
|
26
|
+
appjour look for apps
|
27
|
+
appjour [NAME] open the app NAME
|
28
|
+
appjour [NAME] [PORT] publish your app as NAME on PORT
|
29
|
+
appjour [PORT] publish your app as $USER on PORT
|
30
|
+
|
31
|
+
EOH
|
32
|
+
elsif name && port
|
33
|
+
Appjour.publish(name, port)
|
34
|
+
elsif name
|
35
|
+
Appjour.open(name)
|
36
|
+
else
|
37
|
+
Appjour.list
|
38
|
+
end
|
data/lib/appjour.rb
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
begin
|
2
|
+
require 'dnssd'
|
3
|
+
rescue LoadError
|
4
|
+
require 'net/dns/mdns-sd'
|
5
|
+
DNSSD = Net::DNS::MDNSSD
|
6
|
+
end
|
7
|
+
|
8
|
+
require 'set'
|
9
|
+
require 'pp'
|
10
|
+
|
11
|
+
Thread.abort_on_exception = true
|
12
|
+
module Appjour
|
13
|
+
|
14
|
+
SERVICE = "_http._tcp"
|
15
|
+
App = Struct.new(:name, :host, :port)
|
16
|
+
|
17
|
+
|
18
|
+
def self.list
|
19
|
+
servers = {}
|
20
|
+
service = DNSSD.browse(SERVICE) do |reply|
|
21
|
+
servers[reply.name] ||= reply
|
22
|
+
end
|
23
|
+
STDERR.puts "Searching for servers (3 seconds)"
|
24
|
+
# Wait for something to happen
|
25
|
+
sleep 3
|
26
|
+
service.stop
|
27
|
+
servers.each { |string,obj|
|
28
|
+
name, port = string.split ":"
|
29
|
+
STDERR.puts "Found web app called '#{name}'"
|
30
|
+
}
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
def self.find(name,first=nil)
|
35
|
+
hosts = Set.new
|
36
|
+
|
37
|
+
waiting = Thread.current
|
38
|
+
|
39
|
+
STDERR.puts "searching for #{name}"
|
40
|
+
|
41
|
+
service = DNSSD.browse(SERVICE) do |reply|
|
42
|
+
if name === reply.name
|
43
|
+
DNSSD.resolve(reply.name, reply.type, reply.domain) do |rr|
|
44
|
+
hosts << App.new(reply.name, rr.target, rr.port)
|
45
|
+
waiting.run if first
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# wait to resolve multiple apps
|
51
|
+
sleep 5
|
52
|
+
service.stop
|
53
|
+
|
54
|
+
hosts
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.open(name)
|
58
|
+
host = find(name,true).to_a[0]
|
59
|
+
|
60
|
+
unless host
|
61
|
+
STDERR.puts "unable to find #{name}"
|
62
|
+
else
|
63
|
+
system "open 'http://#{host.host}:#{host.port}'"
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
# TODO
|
68
|
+
# divine app port numbers
|
69
|
+
# mongrel: http://www.caboo.se/articles/2006/11/14/configure-mongrel-rails-logger-per-port
|
70
|
+
def self.publish(name,port=:guess)
|
71
|
+
STDERR.puts "Publishing #{name} on #{port}"
|
72
|
+
|
73
|
+
if port.is_a?(Symbol)
|
74
|
+
port = guess_port(port)
|
75
|
+
else
|
76
|
+
port = port.to_i
|
77
|
+
end
|
78
|
+
|
79
|
+
begin
|
80
|
+
tr = DNSSD::TextRecord.new
|
81
|
+
tr["description"] = "An app."
|
82
|
+
dnssd_args = tr.encode
|
83
|
+
rescue NameError
|
84
|
+
dnssd_args = { 'description' => 'An app.' }
|
85
|
+
end
|
86
|
+
|
87
|
+
DNSSD.register(name, SERVICE, "local", port.to_i, dnssd_args) do |reply|
|
88
|
+
STDERR.puts "Announcing #{name}..."
|
89
|
+
end
|
90
|
+
|
91
|
+
sleep
|
92
|
+
end
|
93
|
+
|
94
|
+
def self.guess_port(kind)
|
95
|
+
case kind
|
96
|
+
when :mongrel
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
metadata
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: crnixon-appjour
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Lachie
|
8
|
+
autorequire: appjour
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-06-18 00:00:00 -07:00
|
13
|
+
default_executable: appjour
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: net-mdns
|
17
|
+
version_requirement:
|
18
|
+
version_requirements: !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 0.4.0
|
23
|
+
version:
|
24
|
+
description: Announce an app over bonjour
|
25
|
+
email: lachiec@gmail.com
|
26
|
+
executables:
|
27
|
+
- appjour
|
28
|
+
extensions: []
|
29
|
+
|
30
|
+
extra_rdoc_files:
|
31
|
+
- README.rdoc
|
32
|
+
files:
|
33
|
+
- README.rdoc
|
34
|
+
- Rakefile
|
35
|
+
- bin/appjour
|
36
|
+
- lib/appjour
|
37
|
+
- lib/appjour/version.rb
|
38
|
+
- lib/appjour.rb
|
39
|
+
has_rdoc: true
|
40
|
+
homepage: http://github.com/lachie/appjour
|
41
|
+
post_install_message:
|
42
|
+
rdoc_options: []
|
43
|
+
|
44
|
+
require_paths:
|
45
|
+
- lib
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: "0"
|
51
|
+
version:
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: "0"
|
57
|
+
version:
|
58
|
+
requirements: []
|
59
|
+
|
60
|
+
rubyforge_project:
|
61
|
+
rubygems_version: 1.0.1
|
62
|
+
signing_key:
|
63
|
+
specification_version: 2
|
64
|
+
summary: Announce an app over bonjour
|
65
|
+
test_files: []
|
66
|
+
|