class SabredavClient::Principal

Attributes

client[RW]

Public Class Methods

new(data) click to toggle source
# File lib/sabredav_client/principal.rb, line 6
def initialize(data)
  @client = SabredavClient::Client.new(data)
end

Public Instance Methods

create(email, displayname = nil) click to toggle source
# File lib/sabredav_client/principal.rb, line 10
def create(email, displayname = nil)
  header  = {content_type: "text/xml", depth: "1"}
  body    = SabredavClient::XmlRequestBuilder::MkcolPrincipal.new(email, displayname).to_xml
  req     = client.create_request(:mkcol, header: header, body: body)

  res = req.run
  if res.code.to_i.between?(200,299)
    true
  else
    SabredavClient::Errors::errorhandling(res)
  end
end
delete() click to toggle source
# File lib/sabredav_client/principal.rb, line 38
def delete
  #FIXME seems like deleting a principal is forbidden by sabredav
  req = client.create_request(:delete)
  res = req.run

  if res.code.to_i.between?(200,299)
    true
  else
    SabredavClient::Errors::errorhandling(res)
  end
end
update(email: "", displayname: "") click to toggle source
# File lib/sabredav_client/principal.rb, line 23
def update(email: "", displayname: "")
  header  = {content_type: "application/xml"}
  body    = SabredavClient::XmlRequestBuilder::ProppatchPrincipal.new(email, displayname).to_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