siuying-cardjour 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt ADDED
@@ -0,0 +1,3 @@
1
+ == 0.1.0 2008-09-07
2
+
3
+ * First release. Basic listing and publishing feature.
data/License.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 FIXME full name
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Manifest.txt ADDED
@@ -0,0 +1,31 @@
1
+ History.txt
2
+ License.txt
3
+ Manifest.txt
4
+ PostInstall.txt
5
+ README.txt
6
+ Rakefile
7
+ bin/cardjour
8
+ config/hoe.rb
9
+ config/requirements.rb
10
+ lib/cardjour.rb
11
+ lib/cardjour/application.rb
12
+ lib/cardjour/command/help.rb
13
+ lib/cardjour/command/list.rb
14
+ lib/cardjour/command/publish.rb
15
+ lib/cardjour/service.rb
16
+ lib/cardjour/version.rb
17
+ script/console
18
+ script/destroy
19
+ script/generate
20
+ script/txt2html
21
+ setup.rb
22
+ tasks/deployment.rake
23
+ tasks/environment.rake
24
+ tasks/website.rake
25
+ test/test_cardjour.rb
26
+ test/test_helper.rb
27
+ website/index.html
28
+ website/index.txt
29
+ website/javascripts/rounded_corners_lite.inc.js
30
+ website/stylesheets/screen.css
31
+ website/template.html.erb
data/PostInstall.txt ADDED
@@ -0,0 +1,3 @@
1
+ For more information on cardjour, see http://www.reality.hk/cardjour
2
+
3
+
data/README.txt ADDED
@@ -0,0 +1,51 @@
1
+ = cardjour
2
+
3
+ * card.reality.hk
4
+
5
+ == DESCRIPTION:
6
+
7
+ Share and discover business card (VCard) with others in a LAN, using
8
+ Bonjour.
9
+
10
+ == FEATURES/PROBLEMS:
11
+
12
+ NONE YET.
13
+
14
+ == SYNOPSIS:
15
+
16
+ % cardjour list
17
+ % cardjour publish <vcard-file> [port] [description]"
18
+
19
+ == REQUIREMENTS:
20
+
21
+ * dnssd
22
+ * vpim
23
+
24
+ == INSTALL:
25
+
26
+ sudo gem install cardjour
27
+
28
+ == LICENSE:
29
+
30
+ (The MIT License)
31
+
32
+ Copyright (c) 2008 FIXME full name
33
+
34
+ Permission is hereby granted, free of charge, to any person obtaining
35
+ a copy of this software and associated documentation files (the
36
+ 'Software'), to deal in the Software without restriction, including
37
+ without limitation the rights to use, copy, modify, merge, publish,
38
+ distribute, sublicense, and/or sell copies of the Software, and to
39
+ permit persons to whom the Software is furnished to do so, subject to
40
+ the following conditions:
41
+
42
+ The above copyright notice and this permission notice shall be
43
+ included in all copies or substantial portions of the Software.
44
+
45
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
46
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
47
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
48
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
49
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
50
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
51
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ require 'config/requirements'
2
+ require 'config/hoe' # setup Hoe + all gem configuration
3
+
4
+ Dir['tasks/**/*.rake'].each { |rake| load rake }
data/bin/cardjour ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+ #require 'rubygems'
3
+ require 'cardjour'
4
+
5
+ trap "INT" do
6
+ exit!
7
+ end
8
+
9
+ Cardjour::Application.run(*ARGV)
data/config/hoe.rb ADDED
@@ -0,0 +1,73 @@
1
+ require 'cardjour/version'
2
+
3
+ AUTHOR = 'Francis CHONG' # can also be an array of Authors
4
+ EMAIL = "siu [dot] ying [at] reality [dot] hk"
5
+ DESCRIPTION = "Share business card (VCard) with others in LAN, using Bonjour"
6
+ GEM_NAME = 'cardjour' # what ppl will type to install your gem
7
+ RUBYFORGE_PROJECT = 'cardjour' # The unix name for your project
8
+ HOMEPATH = "http://cardjour.rubyforge.org"
9
+ DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
10
+ EXTRA_DEPENDENCIES = [
11
+ ['vpim', '>= 0.0.0'],
12
+ ['net-mdns', '>= 0.0.0']
13
+ ] # An array of rubygem dependencies [name, version]
14
+
15
+ @config_file = "~/.rubyforge/user-config.yml"
16
+ @config = nil
17
+ RUBYFORGE_USERNAME = "siuying"
18
+ def rubyforge_username
19
+ unless @config
20
+ begin
21
+ @config = YAML.load(File.read(File.expand_path(@config_file)))
22
+ rescue
23
+ puts <<-EOS
24
+ ERROR: No rubyforge config file found: #{@config_file}
25
+ Run 'rubyforge setup' to prepare your env for access to Rubyforge
26
+ - See http://newgem.rubyforge.org/rubyforge.html for more details
27
+ EOS
28
+ exit
29
+ end
30
+ end
31
+ RUBYFORGE_USERNAME.replace @config["username"]
32
+ end
33
+
34
+ REV = nil
35
+ # UNCOMMENT IF REQUIRED:
36
+ # REV = YAML.load(`svn info`)['Revision']
37
+ VERS = Cardjour::VERSION::STRING + (REV ? ".#{REV}" : "")
38
+ RDOC_OPTS = ['--quiet', '--title', 'cardjour2 documentation',
39
+ "--opname", "index.html",
40
+ "--line-numbers",
41
+ "--main", "README",
42
+ "--inline-source"]
43
+
44
+ class Hoe
45
+ def extra_deps
46
+ @extra_deps.reject! { |x| Array(x).first == 'hoe' }
47
+ @extra_deps
48
+ end
49
+ end
50
+
51
+ # Generate all the Rake tasks
52
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
53
+ $hoe = Hoe.new(GEM_NAME, VERS) do |p|
54
+ p.developer(AUTHOR, EMAIL)
55
+ p.description = DESCRIPTION
56
+ p.summary = DESCRIPTION
57
+ p.url = HOMEPATH
58
+ p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
59
+ p.test_globs = ["test/**/test_*.rb"]
60
+ p.clean_globs |= ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store'] #An array of file patterns to delete on clean.
61
+
62
+ # == Optional
63
+ p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
64
+ #p.extra_deps = EXTRA_DEPENDENCIES
65
+
66
+ #p.spec_extras = {} # A hash of extra values to set in the gemspec.
67
+ end
68
+
69
+ CHANGES = $hoe.paragraphs_of('History.txt', 0..1).join("\\n\\n")
70
+ PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
71
+ $hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
72
+ $hoe.rsync_args = '-av --delete --ignore-errors'
73
+ $hoe.spec.post_install_message = File.open(File.dirname(__FILE__) + "/../PostInstall.txt").read rescue ""
@@ -0,0 +1,15 @@
1
+ require 'fileutils'
2
+ include FileUtils
3
+
4
+ require 'rubygems'
5
+ %w[rake hoe newgem rubigen].each do |req_gem|
6
+ begin
7
+ require req_gem
8
+ rescue LoadError
9
+ puts "This Rakefile requires the '#{req_gem}' RubyGem."
10
+ puts "Installation: gem install #{req_gem} -y"
11
+ exit
12
+ end
13
+ end
14
+
15
+ $:.unshift(File.join(File.dirname(__FILE__), %w[.. lib]))
data/lib/cardjour.rb ADDED
@@ -0,0 +1,7 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless
2
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
+
4
+ require 'cardjour/application'
5
+
6
+ module Cardjour
7
+ end
@@ -0,0 +1,34 @@
1
+ require 'rubygems'
2
+ require 'net/dns/mdns-sd'
3
+ require 'cardjour/service'
4
+ require 'cardjour/command/help'
5
+ require 'cardjour/command/list'
6
+ require 'cardjour/command/publish'
7
+
8
+ Thread.abort_on_exception = true
9
+ module Cardjour
10
+ CJ_SERVICE_NAME = "Cardjour"
11
+ CJ_BONJOUR_NAME = "_cardjour._tcp"
12
+ VCardService = Struct.new(:name, :host, :port, :description)
13
+ DNSSD = Net::DNS::MDNSSD
14
+
15
+ class Application
16
+ class << self
17
+ include Command::List
18
+ include Command::Publish
19
+ include Command::Help
20
+
21
+ # Entry point
22
+ def run(*args)
23
+ case args.shift
24
+ when "publish"
25
+ publish(*args)
26
+ when "list"
27
+ list
28
+ else
29
+ help
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,11 @@
1
+ module Cardjour
2
+ module Command
3
+ module Help
4
+ def help
5
+ puts "usage: cardjour publish <vcard-file> [port] [description]"
6
+ puts "usage: cardjour list"
7
+ end
8
+ module_function :help
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,52 @@
1
+ require 'set'
2
+
3
+ module Cardjour
4
+ module Command
5
+ module List
6
+ VCardService = Struct.new(:name, :host, :port, :description)
7
+
8
+ # List services to console
9
+ def list
10
+ service_list.each do |service|
11
+ puts "=== #{service.name} on #{service.host}:#{service.port} ==="
12
+ puts " #{service.description}"
13
+ puts " http://#{service.host}:#{service.port}/"
14
+ puts
15
+ end
16
+ end
17
+ module_function :list
18
+
19
+ private
20
+ # Discover and Retrieve list of services
21
+ def service_list
22
+ list = Set.new
23
+ discover { |obj| list << obj }
24
+ return list
25
+ end
26
+ module_function :service_list
27
+
28
+ # Discover list of services
29
+ def discover(timeout=5)
30
+ waiting_thread = Thread.current
31
+ dns = DNSSD.browse CJ_BONJOUR_NAME do |reply|
32
+ DNSSD.resolve reply.name, reply.type, reply.domain do |resolve_reply|
33
+ service = VCardService.new(reply.name,
34
+ resolve_reply.target,
35
+ resolve_reply.port,
36
+ resolve_reply.text_record['description'].to_s)
37
+ begin
38
+ yield service
39
+ rescue Done
40
+ waiting_thread.run
41
+ end
42
+ end
43
+ end
44
+ puts "Gathering for up to #{timeout} seconds..."
45
+ sleep timeout
46
+ dns.stop
47
+ end
48
+ module_function :discover
49
+
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,23 @@
1
+ require 'vpim/vcard'
2
+ require 'net/dns/mdns-sd'
3
+
4
+ module Cardjour
5
+ module Command
6
+ module Publish
7
+ # Publish the card service
8
+ def publish(card, *rest)
9
+ vcard = Vpim::Vcard.decode(open(card)).first
10
+ username = vcard.name.fullname rescue "Unknown"
11
+ port = rest.shift || 3300
12
+ description = rest.shift || "#{username}'s Cardjour"
13
+
14
+ DNSSD.register(username, CJ_BONJOUR_NAME, 'local', port.to_i, { "description" => description }) do |rr|
15
+ puts "Registered #{username} on port #{port}. Starting service."
16
+ end
17
+
18
+ Service.new(port.to_i, card).start
19
+ end
20
+ module_function :publish
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,26 @@
1
+ require 'webrick'
2
+ module Cardjour
3
+ class Service
4
+ def initialize(port, file)
5
+ @port = port
6
+ @file = file
7
+ @card = nil
8
+ end
9
+
10
+ def start
11
+ puts "serving at #{@port} with #{@file}"
12
+ http = WEBrick::HTTPServer.new(:Port => @port.to_i)
13
+ http.mount_proc("/") { |req, res| index(req, res) }
14
+ trap("INT") { http.shutdown }
15
+ t = Thread.new { http.start }
16
+ t.join
17
+ end
18
+
19
+ private
20
+ def index(req, res)
21
+ res['Content-Type'] = 'text/x-vCard'
22
+ res["Content-Disposition"] = "attachment; filename=#{File.basename(@file)}"
23
+ res.body = open(@file).read
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,9 @@
1
+ module Cardjour
2
+ module VERSION #:nodoc:
3
+ MAJOR = 0
4
+ MINOR = 1
5
+ TINY = 1
6
+
7
+ STRING = [MAJOR, MINOR, TINY].join('.')
8
+ end
9
+ end
data/script/console ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ # File: script/console
3
+ irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
4
+
5
+ libs = " -r irb/completion"
6
+ # Perhaps use a console_lib to store any extra methods I may want available in the cosole
7
+ # libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
8
+ libs << " -r #{File.dirname(__FILE__) + '/../lib/cardjour.rb'}"
9
+ puts "Loading cardjour gem"
10
+ exec "#{irb} #{libs} --simple-prompt"
data/script/destroy ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/destroy'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Destroy.new.run(ARGV)
data/script/generate ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/generate'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Generate.new.run(ARGV)