forked from 4fthawaiian/ruby-caldav
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathcaldavtest.rb
100 lines (78 loc) · 2.79 KB
/
caldavtest.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
require './lib/caldav.rb'
class CalDAVTester
def initialize
$caldav = {
:host => 'mail.server.com',
:port => 443,
:url => '/caldav.php/[email protected]/test',
:user => '[email protected]',
:password => 'yourpassword'
}
begin
require '~/.caldav_cred.rb'
rescue LoadError
end
@cal = CalDAV::Client.new $caldav[:host], $caldav[:port], $caldav[:url], $caldav[:user], $caldav[:password]
end
attr :cal
def test_create_event
myevent = Event.new
myevent.dtstart = DateTime.parse( '2012/08/11 09:45')
myevent.dtend = DateTime.parse( '2012/08/11 10:45')
myevent.summary = "Jo?"
uuid, response = cal.create myevent
puts "CREATE Response #{response.code} #{response.message}: #{response.body}"
puts "UUID: #{uuid}"
return uuid
end
def test_delete_event( uuid )
response = cal.delete uuid
puts "DETELE Response #{response.code} #{response.message}: #{response.body}"
end
def test_get_event( uuid )
#ev, response = cal.get uuid
ev = cal.get( uuid )
#puts "GET Response #{response.code} #{response.message}: #{response.body}"
puts ev
end
def test_read_todo
puts '*' * 20 + ' TODO ' + '*' * 20
res = cal.todo
res.each{ |todo|
p todo
}
end
def test_report
puts '*' * 20 + ' EVENTS ' + '*' * 20
p cal.report "20111201T000000", "20131231T000000"
end
def test_query0
puts CalDAV::Query.event.to_xml
time1 = DateTime.parse('2011/08/08 09:45')
time2 = DateTime.parse('2012/08/08 10:45')
puts CalDAV::Query.event(time1..time2).to_xml
puts CalDAV::Query.event.uid( UUID.generate ).to_xml
#puts CalDAV::Query.todo.alarm(time1..time2).to_xml
#puts CalDAV::Query.event.attendee(email).partstat('NEEDS-ACTION').to_xml
#puts CalDAV::Query.todo.completed(false).status(:cancelled => false).to_xml
end
def test_query
p cal.query( CalDAV::Query.event ) #=> All events
p cal.query( CalDAV::Query.event(time1..time2) )
p cal.query( CalDAV::Query.event.uid("UID") )
p cal.query( CalDAV::Query.todo.alarm(time1..time2) )
p cal.query( CalDAV::Query.event.attendee(email).partstat('NEEDS-ACTION') )
p cal.query( CalDAV::Query.todo.completed(false).status(:cancelled => false) )
end
end
#r = CalDAV::Request::Report.new( "20111201T000000", "20131231T000000" )
#puts r.to_xml
#exit
t = CalDAVTester.new
t.test_query0
uuid = t.test_create_event
t.test_get_event( uuid )
t.test_delete_event( uuid )
t.test_report
t.test_read_todo
#t.test_query