Class: CardDAV

Inherits:
WebDAV show all
Defined in:
lib/carddav.rb,
lib/CardDAV/VERSION.rb,
lib/CardDAV/Resource.rb,
lib/CardDAV/MultiStatus.rb

Defined Under Namespace

Classes: MultiStatus, Resource

Constant Summary collapse

NAMESPACE =
'urn:ietf:params:xml:ns:carddav'
DAV_NAMESPACE =
'DAV:'
VERSION =
'0.0.0'

Instance Method Summary collapse

Instance Method Details

#addressbook_home_set(principal = current_user_principal) ⇒ Object



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

def addressbook_home_set(principal = current_user_principal)
  resource = propfind_as_carddav(principal, body: addressbook_home_set_body, depth: '0').resources.first
  resource&.then{|r| href_property(r, NAMESPACE, 'addressbook-home-set')}
end

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

RFC 6352 §8.7. REPORT with a <c:addressbook-multiget> body.



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

def addressbook_multiget(path, body:, depth: '0')
  report_as_carddav(path, body: body, depth: depth)
end

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

RFC 6352 §8.6. REPORT with a <c:addressbook-query> body. The filter grammar (prop-filter/text-match) is the caller’s XML at Layer 1; a fluent filter builder — which would negotiate CARDDAV:supported-collation-set (§8.3.1) — is reserved for Layer 3.



30
31
32
# File 'lib/carddav.rb', line 30

def addressbook_query(path, body:, depth: '1')
  report_as_carddav(path, body: body, depth: depth)
end

#addressbooks(home = addressbook_home_set) ⇒ Object



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

def addressbooks(home = addressbook_home_set)
  resources = propfind_as_carddav(home, body: addressbooks_body, depth: '1').resources
  resources.select{|resource| resource.is_addressbook?}.collect{|resource| resource.href}
end

#current_user_principal(path = discovery_path) ⇒ Object

Discovery helpers. Return paths/strings. An object-oriented discovery API (Principal/Addressbook objects) is planned. The CARDDAV:principal-address property (§7.1.2), which identifies a principal’s own vCard, is a principal property — reserved for Layer 2 (Objects) alongside CardDAV::Principal, since Layer 1 has no discovery path returning a principal Resource to read it from.



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

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

#mkcol(path, body: nil) ⇒ Object

RFC 6352 §6.3.1. Extended MKCOL — creates an addressbook collection. CardDAV has no MKCARDDAV: an addressbook is made with a standard MKCOL carrying a body that sets resourcetype to include <c:addressbook/>. Overrides the inherited zero-body WebDAV#mkcol to add the optional body (a deliberate widening, not a shadow). Returns a WebDAV::Response.



21
22
23
24
# File 'lib/carddav.rb', line 21

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