Class: CalDAV

Inherits:
WebDAV show all
Includes:
Extensions::Apple, Extensions::CalendarServer
Defined in:
lib/caldav.rb,
lib/CalDAV/VERSION.rb,
lib/CalDAV/Calendar.rb,
lib/CalDAV/Resource.rb,
lib/CalDAV/MultiStatus.rb,
lib/CalDAV/Extensions/Apple.rb,
lib/CalDAV/Extensions/CalendarServer.rb

Defined Under Namespace

Modules: Extensions Classes: Calendar, MultiStatus, Resource

Constant Summary collapse

NAMESPACE =
'urn:ietf:params:xml:ns:caldav'
DAV_NAMESPACE =
'DAV:'
VERSION =
'0.2.0'

Instance Method Summary collapse

Instance Method Details

#calendar_home_set(principal = current_user_principal) ⇒ Object



50
51
52
53
# File 'lib/caldav.rb', line 50

def calendar_home_set(principal = current_user_principal)
  resource = propfind_as_caldav(principal, body: calendar_home_set_body, depth: '0').resources.first
  resource&.then{|r| href_property(r, NAMESPACE, 'calendar-home-set')}
end

#calendar_multiget(path, body:, depth: '0') ⇒ Object

RFC 4791 §7.9. REPORT with a <c:calendar-multiget> body.



29
30
31
# File 'lib/caldav.rb', line 29

def calendar_multiget(path, body:, depth: '0')
  report_as_caldav(path, body: body, depth: depth)
end

#calendar_query(path, body:, depth: '1') ⇒ Object

RFC 4791 §7.8. REPORT with a <c:calendar-query> body.



24
25
26
# File 'lib/caldav.rb', line 24

def calendar_query(path, body:, depth: '1')
  report_as_caldav(path, body: body, depth: depth)
end

#calendars(home = calendar_home_set) ⇒ Object



55
56
57
58
# File 'lib/caldav.rb', line 55

def calendars(home = calendar_home_set)
  resources = propfind_as_caldav(home, body: calendars_body, depth: '1').resources
  resources.select{|resource| resource.is_calendar?}
end

#current_user_principal(path = discovery_path) ⇒ Object

Discovery helpers. current_user_principal and calendar_home_set return href strings; calendars returns CalDAV::Resource objects (the navigation surface), which the object layer (CalDAV::Calendar.all, via require 'CalDAV/Objects') maps into value objects.



45
46
47
48
# File 'lib/caldav.rb', line 45

def current_user_principal(path = discovery_path)
  resource = propfind_as_caldav(path, body: current_user_principal_body, depth: '0').resources.first
  resource&.then{|r| href_property(r, DAV_NAMESPACE, 'current-user-principal')}
end

#freebusy_query(path, body:, depth: '0') ⇒ Object

RFC 4791 §7.10. REPORT with a <c:free-busy-query> body. Asymmetric: returns the raw response carrying iCalendar VFREEBUSY data, not a multistatus.



35
36
37
38
# File 'lib/caldav.rb', line 35

def freebusy_query(path, body:, depth: '0')
  response = request(:report, path, body: body, headers: {'Depth' => depth})
  handle_response(response)
end

#mkcalendar(path, body: nil) ⇒ Object

RFC 4791 §5.3.1. Creates a calendar collection.



18
19
20
21
# File 'lib/caldav.rb', line 18

def mkcalendar(path, body: nil)
  response = request(:mkcalendar, path, body: body)
  handle_response(response)
end