class Calendav::Clients::CalendarsClient
Constants
- DEFAULT_ATTRIBUTES
Attributes
client[R]
credentials[R]
endpoint[R]
Public Class Methods
new(client, endpoint, credentials)
click to toggle source
# File lib/calendav/clients/calendars_client.rb, line 20 def initialize(client, endpoint, credentials) @client = client @endpoint = endpoint @credentials = credentials end
Public Instance Methods
create(identifier, attributes)
click to toggle source
# File lib/calendav/clients/calendars_client.rb, line 42 def create(identifier, attributes) request = Requests::MakeCalendar.call(attributes) url = merged_url(identifier) result = endpoint.mkcalendar(request.to_xml, url: url) result.headers["Location"] || url end
create?()
click to toggle source
# File lib/calendav/clients/calendars_client.rb, line 38 def create? options.include?("MKCOL") || options.include?("MKCALENDAR") end
delete(url)
click to toggle source
# File lib/calendav/clients/calendars_client.rb, line 50 def delete(url) endpoint.delete(url: url) end
find(url, attributes: DEFAULT_ATTRIBUTES, sync: false)
click to toggle source
# File lib/calendav/clients/calendars_client.rb, line 54 def find(url, attributes: DEFAULT_ATTRIBUTES, sync: false) attributes = (attributes.dup << :sync_token) if sync list(url, depth: 0, attributes: attributes).first end
home_url()
click to toggle source
# File lib/calendav/clients/calendars_client.rb, line 26 def home_url @home_url ||= begin request = Requests::CalendarHomeSet.call response = endpoint.propfind(request.to_xml, url: principal_url).first ContextualURL.call( credentials.host, response.xpath(".//caldav:calendar-home-set/dav:href").text ) end end
list(url = home_url, depth: 1, attributes: DEFAULT_ATTRIBUTES)
click to toggle source
# File lib/calendav/clients/calendars_client.rb, line 60 def list(url = home_url, depth: 1, attributes: DEFAULT_ATTRIBUTES) request = Requests::ListCalendars.call(attributes) calendar_xpath = ".//dav:resourcetype/caldav:calendar" endpoint .propfind(request.to_xml, url: url, depth: depth) .select { |node| node.xpath(calendar_xpath).any? } .collect { |node| Calendar.from_xml(home_url, node) } end
options()
click to toggle source
# File lib/calendav/clients/calendars_client.rb, line 70 def options endpoint .options(url: home_url) .headers["Allow"] .split(", ") end
sync(url, token)
click to toggle source
# File lib/calendav/clients/calendars_client.rb, line 77 def sync(url, token) request = Requests::SyncCollection.call(token) Parsers::SyncXML.call( url, endpoint.report(request.to_xml, url: url, depth: nil) ) end
update(url, attributes)
click to toggle source
# File lib/calendav/clients/calendars_client.rb, line 85 def update(url, attributes) request = Requests::UpdateCalendar.call(attributes) endpoint .proppatch(request.to_xml, url: url) .first .xpath(".//dav:status") .text["200 OK"] == "200 OK" end
Private Instance Methods
merged_url(identifier)
click to toggle source
# File lib/calendav/clients/calendars_client.rb, line 98 def merged_url(identifier) "#{home_url.delete_suffix('/')}/#{identifier.delete_suffix('/')}/" end
principal_url()
click to toggle source
# File lib/calendav/clients/calendars_client.rb, line 102 def principal_url client.principal_url end