class SabredavClient::Calendar
Attributes
client[RW]
Public Class Methods
new(data)
click to toggle source
# File lib/sabredav_client/calendar.rb, line 6 def initialize(data) @client = SabredavClient::Client.new(data) end
Public Instance Methods
create(displayname: "", description: "")
click to toggle source
# File lib/sabredav_client/calendar.rb, line 31 def create(displayname: "", description: "") body = SabredavClient::XmlRequestBuilder::Mkcalendar.new(displayname, description).to_xml header = {dav: "resource-must-be-null", content_type: "application/xml"} req = client.create_request(:mkcalendar, header: header, body: body) res = req.run SabredavClient::Errors.errorhandling(res) info end
delete()
click to toggle source
# File lib/sabredav_client/calendar.rb, line 58 def delete req = client.create_request(:delete) res = req.run if res.code.to_i.between?(200,299) true else SabredavClient::Errors::errorhandling(res) end end
events()
click to toggle source
# File lib/sabredav_client/calendar.rb, line 10 def events @events ||= SabredavClient::Events.new(client) end
fetch_changes(sync_token)
click to toggle source
# File lib/sabredav_client/calendar.rb, line 134 def fetch_changes(sync_token) body = SabredavClient::XmlRequestBuilder::ReportEventChanges.new(sync_token).to_xml header = {content_type: "application/xml"} req = client.create_request(:report, header: header, body: body) res = req.run SabredavClient::Errors::errorhandling(res) changes = [] deletions = [] xml = REXML::Document.new(res.body) REXML::XPath.each(xml, "//d:response/", {"d"=> "DAV:"}) do |response| entry = REXML::Document.new.add(response) if (REXML::XPath.first(entry, "//d:status").text == "HTTP/1.1 404 Not Found") deletions.push( REXML::XPath.first(entry, "//d:href").text.to_s.split("/").last) else uri = REXML::XPath.first(entry, "//d:href").text.split("/").last etag = REXML::XPath.first(entry, "//d:getetag").text etag = %Q/#{etag.gsub(/\A['"]+|['"]+\Z/, "")}/ unless etag.nil? changes.push( { uri: uri, etag: etag }) end end { changes: changes, deletions: deletions, sync_token: REXML::XPath.first(xml, "//d:sync-token").text } end
info()
click to toggle source
# File lib/sabredav_client/calendar.rb, line 14 def info header = {content_type: "application/xml"} body = SabredavClient::XmlRequestBuilder::PROPFINDCalendar.new(properties: [:displayname, :sync_token, :getctag]).to_xml req = client.create_request(:propfind, header: header, body: body) res = req.run SabredavClient::Errors::errorhandling(res) xml = REXML::Document.new(res.body) { displayname: REXML::XPath.first(xml, "//d:displayname").text, ctag: REXML::XPath.first(xml, "//cs:getctag").text, sync_token: REXML::XPath.first(xml, "//d:sync-token").text } end
update(displayname: nil, description: nil)
click to toggle source
# File lib/sabredav_client/calendar.rb, line 43 def update(displayname: nil, description: nil) body = XmlRequestBuilder::ProppatchCalendar.new(displayname, description).to_xml header = {content_type: "application/xml"} req = client.create_request(:proppatch, header: header, body: body) res = req.run if res.code.to_i.between?(200,299) true else SabredavClient::Errors::errorhandling(res) end end