#!/usr/bin/env ruby
#
# $Id: ct_test,v 1.12 2004/12/14 03:13:56 ianmacd Exp $
#
# simple program to retrieve the capabilities of a CorporateTime server
#
# Copyright (C) 2002-2004 Ian Macdonald
#
#   This program is free software; you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation; either version 2, or (at your option)
#   any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program; if not, write to the Free Software Foundation,
#   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

begin
  require 'password'
rescue LoadError
  $stderr.puts "This program requires Ruby/Password: http://www.caliban.org/ruby/"
  exit 1
end

require 'ctime'

printf("CorporateTime Ruby module v%s\n\n", CTime::VERSION)

print "Server name and port (e.g. foo.example.com:5730): "
server = gets.chomp

print "User name: "
user = gets.chomp

passwd = Password.getc("CorporateTime password: ")

CTime.new.connect(server, user, passwd) do |ct|
  caps = ct.capabilities

  puts <<EOF

Capabilities of #{server}:

Authentication: #{caps['authentication'].join(', ')}
Compression: #{caps['compression'].join(', ')}
Encryption: #{caps['encryption'].join(', ')}
Maximum date: #{caps['max_date']}
CAPI version: #{caps['capi_version']}
Version: #{caps['version']}
Server version: #{caps['server_version']}
Unsupported iCalendar properties: #{caps['unsupported_ical_prop'].join(', ')}
Unsupported iCalendar components: #{caps['unsupported_ical_comp'].join(', ')}
EOF

end
