Saves remote SabreDAV calendars and address books to disk. Intended for use with the Backup gem (but it's not a requirement).
-
A SabreDAV server (tested with Baïkal)
-
For calendar exports, the iCalendar Export Plugin
-
For address book exports, the [vCard Export Plugin] (https://code.google.com/p/sabredav/wiki/VCFExportPlugin)
-
Ruby (tested with 1.9.3 and 2.1)
-
curl (for HTTP Digest Authentication)
Please add this to your Gemfile
:
gem 'sabredav_export', :git => '[email protected]:toddmazierski/sabredav-export.git', :ref => 'v0.0.2'
To configure, pass a block to SabreDAVExport.config
:
SabreDAVExport.config do |config|
config.caldav_url = 'https://example.com/cal.php'
config.carddav_url = 'https://example.com/card.php'
config.username = 'admin'
config.password = 'swordfish'
end
Please note that the username
in this context is for authentication purposes.
# Create a new instance.
address_book = SabreDAVExport::AddressBook.new('paul', 'geologists')
# => #<SabreDAVExport::AddressBook @name="geologists", @username="paul">
# Save the data to disk.
address_book.save
# => 27170
# Test the validity of the data.
address_book.test
# => true
# Here's the location on disk.
address_book.pathname
# => #<Pathname:/tmp/paul-geologists.vcard>
# Let's take a peek at the file.
address_book.pathname.open.lines.to_a[0..2]
# => ["BEGIN:VCARD\r\n",
# "VERSION:3.0\r\n",
# "PRODID:-//Apple Inc.//Address Book 6.1.2//EN\r\n"]
# Clean up what's saved to disk.
address_book.clean_up
# => 1
In this example:
-
Resources are saved and tested in the
before
hook -
Each
pathname
is added to an archive -
Finally, what's saved to disk is cleaned up in the
after
hook
Model.new(:baikal, 'Baïkal server backups') do
resources = [
SabreDAVExport::Calendar.new('paul', 'excavations'),
SabreDAVExport::AddressBook.new('paul', 'geologists')
]
before do
resources.each(&:save)
resources.each(&:test)
end
after { resources.each(&:clean_up) }
archive :backups do |archive|
resources.each do |resource|
archive.add resource.pathname
end
end
end