#!/usr/bin/env ruby
#
# $Id: ct_test,v 1.7 2002/09/25 09:38:50 ianmacd Exp $
#
# simple program to retrieve the capabilities of a CorporateTime server
#
# Copyright (C) 2002 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("Corporate time Ruby module v%s\n\n", CTime::VERSION)

print "Server name: "
server = gets.chomp

print "User name: "
user = gets.chomp

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

ct = CTime.new(server, user, passwd)

unless ct.error == "CAPI_STAT_OK"
  $stderr.puts "Failed to connect to #{server} as #{user}"
  exit 1
end

puts <<EOF

Capabilities of #{server}:

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

ct.quit
