Class: CardDAV
- 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
- DAV_NAMESPACE =
'DAV:'- DAV_PROPERTY_NAMES =
%w{displayname getcontenttype getetag getlastmodified resourcetype}
- DEFAULT_REPORT_PROPERTIES =
%w{getetag address-data}
- NAMESPACE =
'urn:ietf:params:xml:ns:carddav'- VERSION =
'0.1.0'
Instance Method Summary collapse
- #addressbook_home_set(principal = current_user_principal) ⇒ Object
-
#addressbook_multiget(path, hrefs: nil, body: nil, properties: DEFAULT_REPORT_PROPERTIES, depth: '0') ⇒ Object
RFC 6352 §8.7.
-
#addressbook_query(path, body: nil, properties: DEFAULT_REPORT_PROPERTIES, depth: '1') ⇒ Object
RFC 6352 §8.6.
- #addressbooks(home = addressbook_home_set) ⇒ Object
-
#current_user_principal(path = discovery_path) ⇒ Object
Discovery helpers.
-
#mkcol(path, body: nil) ⇒ Object
RFC 6352 §6.3.1.
Instance Method Details
#addressbook_home_set(principal = current_user_principal) ⇒ Object
55 56 57 58 |
# File 'lib/carddav.rb', line 55 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, hrefs: nil, body: nil, properties: DEFAULT_REPORT_PROPERTIES, depth: '0') ⇒ Object
RFC 6352 §8.7. REPORT with a <c:addressbook-multiget> body. When no body is given, one is constructed from hrefs: and properties:.
40 41 42 |
# File 'lib/carddav.rb', line 40 def addressbook_multiget(path, hrefs: nil, body: nil, properties: DEFAULT_REPORT_PROPERTIES, depth: '0') report_as_carddav(path, body: body || addressbook_multiget_body(hrefs, properties), depth: depth) end |
#addressbook_query(path, body: nil, properties: DEFAULT_REPORT_PROPERTIES, depth: '1') ⇒ Object
RFC 6352 §8.6. REPORT with a <c:addressbook-query> body. When no body is given, a filterless prop-request body is constructed from properties:, so the common "return every card" query needs no caller XML. The filter grammar (prop-filter/text-match) remains 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.
34 35 36 |
# File 'lib/carddav.rb', line 34 def addressbook_query(path, body: nil, properties: DEFAULT_REPORT_PROPERTIES, depth: '1') report_as_carddav(path, body: body || addressbook_query_body(properties), depth: depth) end |
#addressbooks(home = addressbook_home_set) ⇒ Object
60 61 62 63 |
# File 'lib/carddav.rb', line 60 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.
50 51 52 53 |
# File 'lib/carddav.rb', line 50 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.
23 24 25 26 |
# File 'lib/carddav.rb', line 23 def mkcol(path, body: nil) response = request(:mkcol, path, body: body) handle_response(response) end |