sabredav_client 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -3
- data/.rspec +1 -1
- data/CHANGELOG.rdoc +8 -8
- data/Gemfile +3 -3
- data/Gemfile.lock +39 -38
- data/README.md +49 -49
- data/Rakefile +5 -5
- data/lib/sabredav_client.rb +10 -10
- data/lib/sabredav_client/calendar.rb +171 -171
- data/lib/sabredav_client/client.rb +57 -57
- data/lib/sabredav_client/errors/errors.rb +41 -41
- data/lib/sabredav_client/events.rb +106 -105
- data/lib/sabredav_client/net.rb +15 -15
- data/lib/sabredav_client/principal.rb +51 -51
- data/lib/sabredav_client/request.rb +97 -97
- data/lib/sabredav_client/version.rb +3 -3
- data/lib/sabredav_client/xml_request_builder.rb +7 -7
- data/lib/sabredav_client/xml_request_builder/base.rb +17 -17
- data/lib/sabredav_client/xml_request_builder/mkcalendar.rb +25 -25
- data/lib/sabredav_client/xml_request_builder/mkcol_principal.rb +28 -28
- data/lib/sabredav_client/xml_request_builder/post_sharing.rb +41 -41
- data/lib/sabredav_client/xml_request_builder/propfind_calendar.rb +41 -41
- data/lib/sabredav_client/xml_request_builder/propfind_invite.rb +19 -19
- data/lib/sabredav_client/xml_request_builder/propfind_owner.rb +19 -19
- data/lib/sabredav_client/xml_request_builder/proppatch_calendar.rb +25 -25
- data/lib/sabredav_client/xml_request_builder/proppatch_events_owner.rb +23 -23
- data/lib/sabredav_client/xml_request_builder/proppatch_principal.rb +25 -25
- data/lib/sabredav_client/xml_request_builder/report_event_changes.rb +22 -22
- data/lib/sabredav_client/xml_request_builder/report_vevent.rb +30 -30
- data/lib/sabredav_client/xml_request_builder/report_vtodo.rb +20 -20
- data/sabredav_client.gemspec +31 -31
- data/spec/fixtures/calendar_fetch_changes.xml +26 -26
- data/spec/fixtures/calendar_info.xml +14 -14
- data/spec/fixtures/calendar_sharees.xml +35 -35
- data/spec/fixtures/calendar_sharees_without_common_name.xml +26 -26
- data/spec/fixtures/event.ics +23 -23
- data/spec/fixtures/events_find_multiple.xml +51 -51
- data/spec/fixtures/events_owner.xml +12 -12
- data/spec/fixtures/xml_request_builder/mkcalendar.xml +9 -9
- data/spec/fixtures/xml_request_builder/mkcol_principal.xml +12 -12
- data/spec/fixtures/xml_request_builder/post_sharing.xml +18 -18
- data/spec/fixtures/xml_request_builder/propfind_calendar/all_properties.xml +8 -8
- data/spec/fixtures/xml_request_builder/propfind_invite.xml +6 -6
- data/spec/fixtures/xml_request_builder/propfind_owner.xml +6 -6
- data/spec/fixtures/xml_request_builder/proppatch_calendar.xml +9 -9
- data/spec/fixtures/xml_request_builder/proppatch_events_owner.xml +8 -8
- data/spec/fixtures/xml_request_builder/proppatch_principal.xml +9 -9
- data/spec/fixtures/xml_request_builder/report_event_changes.xml +8 -8
- data/spec/sabredav_client/calendar_spec.rb +142 -142
- data/spec/sabredav_client/client_spec.rb +41 -41
- data/spec/sabredav_client/events_spec.rb +119 -119
- data/spec/sabredav_client/principal_spec.rb +51 -51
- data/spec/sabredav_client/request_spec.rb +55 -55
- data/spec/sabredav_client/xml_request_builder_specs/base_spec.rb +30 -30
- data/spec/sabredav_client/xml_request_builder_specs/mkcalendar_spec.rb +13 -13
- data/spec/sabredav_client/xml_request_builder_specs/mkcol_principal_spec.rb +13 -13
- data/spec/sabredav_client/xml_request_builder_specs/post_sharing_spec.rb +15 -15
- data/spec/sabredav_client/xml_request_builder_specs/propfind_calendar_spec.rb +24 -24
- data/spec/sabredav_client/xml_request_builder_specs/propfind_invite_spec.rb +14 -14
- data/spec/sabredav_client/xml_request_builder_specs/propfind_owner_spec.rb +14 -14
- data/spec/sabredav_client/xml_request_builder_specs/proppatch_calendar.rb +15 -15
- data/spec/sabredav_client/xml_request_builder_specs/proppatch_events_owner_spec.rb +14 -14
- data/spec/sabredav_client/xml_request_builder_specs/proppatch_principal_spec.rb +24 -24
- data/spec/sabredav_client/xml_request_builder_specs/report_event_changes_spec.rb +15 -15
- data/spec/spec.opts +4 -4
- data/spec/spec_helper.rb +8 -8
- metadata +5 -5
@@ -1,57 +1,57 @@
|
|
1
|
-
module SabredavClient
|
2
|
-
class Client
|
3
|
-
attr_reader :authtype, :host, :port, :base_path, :user, :password, :ssl,
|
4
|
-
:digest_auth, :duri, :proxy_host, :proxy_uri, :proxy_port, :base_path
|
5
|
-
|
6
|
-
def format=(fmt)
|
7
|
-
@format = fmt
|
8
|
-
end
|
9
|
-
|
10
|
-
def format
|
11
|
-
@format ||= Format::Debug.new
|
12
|
-
end
|
13
|
-
|
14
|
-
def initialize(data)
|
15
|
-
unless data[:proxy_uri].nil?
|
16
|
-
proxy_uri = URI(data[:proxy_uri])
|
17
|
-
@proxy_host = proxy_uri.host
|
18
|
-
@proxy_port = proxy_uri.port.to_i
|
19
|
-
end
|
20
|
-
|
21
|
-
uri = URI(data[:uri])
|
22
|
-
|
23
|
-
@host = uri.host
|
24
|
-
@port = uri.port.to_i
|
25
|
-
@base_path = uri.path
|
26
|
-
@user = data[:user]
|
27
|
-
@password = data[:password]
|
28
|
-
@ssl = uri.scheme == 'https'
|
29
|
-
|
30
|
-
unless data[:authtype].nil?
|
31
|
-
@authtype = data[:authtype]
|
32
|
-
|
33
|
-
if @authtype == 'digest'
|
34
|
-
|
35
|
-
@digest_auth = Net::HTTP::DigestAuth.new
|
36
|
-
@duri = URI.parse data[:uri]
|
37
|
-
@duri.user = @user
|
38
|
-
@duri.password = @password
|
39
|
-
|
40
|
-
elsif @authtype == 'basic'
|
41
|
-
#Don't Raise or do anything else
|
42
|
-
else
|
43
|
-
raise "Authentication Type Specified Is Not Valid. Please use basic or digest"
|
44
|
-
end
|
45
|
-
else
|
46
|
-
@authtype = 'basic'
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
def create_request(method, header: {}, body: "", path: "")
|
51
|
-
request = SabredavClient::Request.new(method, self, path)
|
52
|
-
request.add_header(header) unless header.empty?
|
53
|
-
request.add_body(body) unless body.empty?
|
54
|
-
request
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
1
|
+
module SabredavClient
|
2
|
+
class Client
|
3
|
+
attr_reader :authtype, :host, :port, :base_path, :user, :password, :ssl,
|
4
|
+
:digest_auth, :duri, :proxy_host, :proxy_uri, :proxy_port, :base_path
|
5
|
+
|
6
|
+
def format=(fmt)
|
7
|
+
@format = fmt
|
8
|
+
end
|
9
|
+
|
10
|
+
def format
|
11
|
+
@format ||= Format::Debug.new
|
12
|
+
end
|
13
|
+
|
14
|
+
def initialize(data)
|
15
|
+
unless data[:proxy_uri].nil?
|
16
|
+
proxy_uri = URI(data[:proxy_uri])
|
17
|
+
@proxy_host = proxy_uri.host
|
18
|
+
@proxy_port = proxy_uri.port.to_i
|
19
|
+
end
|
20
|
+
|
21
|
+
uri = URI(data[:uri])
|
22
|
+
|
23
|
+
@host = uri.host
|
24
|
+
@port = uri.port.to_i
|
25
|
+
@base_path = uri.path
|
26
|
+
@user = data[:user]
|
27
|
+
@password = data[:password]
|
28
|
+
@ssl = uri.scheme == 'https'
|
29
|
+
|
30
|
+
unless data[:authtype].nil?
|
31
|
+
@authtype = data[:authtype]
|
32
|
+
|
33
|
+
if @authtype == 'digest'
|
34
|
+
|
35
|
+
@digest_auth = Net::HTTP::DigestAuth.new
|
36
|
+
@duri = URI.parse data[:uri]
|
37
|
+
@duri.user = @user
|
38
|
+
@duri.password = @password
|
39
|
+
|
40
|
+
elsif @authtype == 'basic'
|
41
|
+
#Don't Raise or do anything else
|
42
|
+
else
|
43
|
+
raise "Authentication Type Specified Is Not Valid. Please use basic or digest"
|
44
|
+
end
|
45
|
+
else
|
46
|
+
@authtype = 'basic'
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def create_request(method, header: {}, body: "", path: "")
|
51
|
+
request = SabredavClient::Request.new(method, self, path)
|
52
|
+
request.add_header(header) unless header.empty?
|
53
|
+
request.add_body(body) unless body.empty?
|
54
|
+
request
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -1,41 +1,41 @@
|
|
1
|
-
module SabredavClient
|
2
|
-
module Errors
|
3
|
-
|
4
|
-
def self.errorhandling response
|
5
|
-
case response.code.to_i
|
6
|
-
when 400
|
7
|
-
raise SabredavClient::Errors::BadRequestError
|
8
|
-
when 401
|
9
|
-
raise SabredavClient::Errors::AuthenticationError
|
10
|
-
when 403
|
11
|
-
raise SabredavClient::Errors::ForbiddenError
|
12
|
-
when 404
|
13
|
-
raise SabredavClient::Errors::NotFoundError
|
14
|
-
when 405
|
15
|
-
raise SabredavClient::Errors::NotAllowedError
|
16
|
-
when 410
|
17
|
-
raise SabredavClient::Errors::NotExistError
|
18
|
-
when 412
|
19
|
-
raise SabredavClient::Errors::PreconditionFailed
|
20
|
-
when 500
|
21
|
-
raise SabredavClient::Errors::APIError
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
class SabredavClientError < StandardError; end
|
26
|
-
|
27
|
-
class PropertyNotSupportedError < SabredavClientError; end
|
28
|
-
class ShareeTypeNotSupportedError < SabredavClientError; end
|
29
|
-
|
30
|
-
class HTTPMethodNotSupportedError < SabredavClientError; end
|
31
|
-
|
32
|
-
class APIError < SabredavClientError; end
|
33
|
-
class ForbiddenError < APIError; end
|
34
|
-
class NotFoundError < APIError; end
|
35
|
-
class PreconditionFailed < APIError; end
|
36
|
-
class NotAllowedError < APIError; end
|
37
|
-
class BadRequestError < APIError; end
|
38
|
-
class AuthenticationError < APIError; end
|
39
|
-
class NotExistError < APIError; end
|
40
|
-
end
|
41
|
-
end
|
1
|
+
module SabredavClient
|
2
|
+
module Errors
|
3
|
+
|
4
|
+
def self.errorhandling response
|
5
|
+
case response.code.to_i
|
6
|
+
when 400
|
7
|
+
raise SabredavClient::Errors::BadRequestError
|
8
|
+
when 401
|
9
|
+
raise SabredavClient::Errors::AuthenticationError
|
10
|
+
when 403
|
11
|
+
raise SabredavClient::Errors::ForbiddenError
|
12
|
+
when 404
|
13
|
+
raise SabredavClient::Errors::NotFoundError
|
14
|
+
when 405
|
15
|
+
raise SabredavClient::Errors::NotAllowedError
|
16
|
+
when 410
|
17
|
+
raise SabredavClient::Errors::NotExistError
|
18
|
+
when 412
|
19
|
+
raise SabredavClient::Errors::PreconditionFailed
|
20
|
+
when 500
|
21
|
+
raise SabredavClient::Errors::APIError
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class SabredavClientError < StandardError; end
|
26
|
+
|
27
|
+
class PropertyNotSupportedError < SabredavClientError; end
|
28
|
+
class ShareeTypeNotSupportedError < SabredavClientError; end
|
29
|
+
|
30
|
+
class HTTPMethodNotSupportedError < SabredavClientError; end
|
31
|
+
|
32
|
+
class APIError < SabredavClientError; end
|
33
|
+
class ForbiddenError < APIError; end
|
34
|
+
class NotFoundError < APIError; end
|
35
|
+
class PreconditionFailed < APIError; end
|
36
|
+
class NotAllowedError < APIError; end
|
37
|
+
class BadRequestError < APIError; end
|
38
|
+
class AuthenticationError < APIError; end
|
39
|
+
class NotExistError < APIError; end
|
40
|
+
end
|
41
|
+
end
|
@@ -1,105 +1,106 @@
|
|
1
|
-
module SabredavClient
|
2
|
-
|
3
|
-
class Events
|
4
|
-
attr_accessor :client
|
5
|
-
|
6
|
-
def initialize(client)
|
7
|
-
@client = client
|
8
|
-
end
|
9
|
-
|
10
|
-
def find(uri)
|
11
|
-
req = client.create_request(:get, path: uri)
|
12
|
-
res = req.run
|
13
|
-
|
14
|
-
SabredavClient::Errors::errorhandling(res)
|
15
|
-
|
16
|
-
etag = res.header["etag"]
|
17
|
-
etag = %Q/#{etag.gsub(/\A['"]+|['"]+\Z/, "")}/ unless etag.nil?
|
18
|
-
|
19
|
-
{
|
20
|
-
ics: res.body,
|
21
|
-
etag: etag
|
22
|
-
}
|
23
|
-
end
|
24
|
-
|
25
|
-
def find_multiple(starts: "", ends: "")
|
26
|
-
events = []
|
27
|
-
header = {depth: "1", content_type: "application/xml"}
|
28
|
-
|
29
|
-
if starts.is_a? Integer
|
30
|
-
body = SabredavClient::XmlRequestBuilder::ReportVEVENT.new(Time.at(starts).utc.strftime("%Y%m%dT%H%M%S"),
|
31
|
-
Time.at(ends).utc.strftime("%Y%m%dT%H%M%S") ).to_xml
|
32
|
-
else
|
33
|
-
body = SabredavClient::XmlRequestBuilder::ReportVEVENT.new(Time.parse(starts).utc.strftime("%Y%m%dT%H%M%S"),
|
34
|
-
Time.parse(ends).utc.strftime("%Y%m%dT%H%M%S") ).to_xml
|
35
|
-
end
|
36
|
-
|
37
|
-
req = client.create_request(:report, header: header)
|
38
|
-
res = req.run
|
39
|
-
|
40
|
-
SabredavClient::Errors::errorhandling(res)
|
41
|
-
result = ""
|
42
|
-
|
43
|
-
xml = REXML::Document.new(res.body)
|
44
|
-
REXML::XPath.each( xml, '//c:calendar-data/', {"c"=>"urn:ietf:params:xml:ns:caldav"} ){|c| result << c.text}
|
45
|
-
|
46
|
-
result
|
47
|
-
end
|
48
|
-
|
49
|
-
def owner(uri)
|
50
|
-
# Warning: This is not a standard request. It only works if your sabredav
|
51
|
-
# server uses a certain OwnerPlugin
|
52
|
-
header = {content_type: "application/xml"}
|
53
|
-
body = XmlRequestBuilder::PropfindOwner.new.to_xml
|
54
|
-
req = client.create_request(:propfind, path: uri, header: header, body: body)
|
55
|
-
res = req.run
|
56
|
-
|
57
|
-
SabredavClient::Errors::errorhandling(res)
|
58
|
-
xml = REXML::Document.new(res.body)
|
59
|
-
REXML::XPath.first(xml, "//cs:objectOwner").text
|
60
|
-
end
|
61
|
-
|
62
|
-
def update_owner(uri, owner)
|
63
|
-
# Warning: This is not a standard request. It only works if your sabredav
|
64
|
-
# server uses a certain OwnerPlugin
|
65
|
-
header = {content_type: "application/xml"}
|
66
|
-
body = XmlRequestBuilder::ProppatchEventsOwner.new(owner).to_xml
|
67
|
-
req = client.create_request(:proppatch, path: uri, header: header, body: body)
|
68
|
-
res = req.run
|
69
|
-
|
70
|
-
if res.code.to_i.between?(200,299)
|
71
|
-
true
|
72
|
-
else
|
73
|
-
SabredavClient::Errors::errorhandling(res)
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
def delete(uri)
|
78
|
-
raise SabredavClient::Errors::SabredavClientError if uri.nil? || !uri.end_with?(".ics")
|
79
|
-
|
80
|
-
req = client.create_request(:delete, path: uri)
|
81
|
-
res = req.run
|
82
|
-
|
83
|
-
if res.code.to_i.between?(200,299)
|
84
|
-
true
|
85
|
-
else
|
86
|
-
SabredavClient::Errors::errorhandling(res)
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
def create_update(uri, event_ics, etag = nil)
|
91
|
-
header = {content_type: "text/calendar"}
|
92
|
-
body = event_ics
|
93
|
-
|
94
|
-
if etag
|
95
|
-
header[:if_match] = %Q/"#{etag.gsub(/\A['"]+|['"]+\Z/, "")}"/
|
96
|
-
end
|
97
|
-
|
98
|
-
req = client.create_request(:put,header: header, body: body, path: uri)
|
99
|
-
res = req.run
|
100
|
-
|
101
|
-
SabredavClient::Errors::errorhandling(res)
|
102
|
-
res['etag']
|
103
|
-
|
104
|
-
|
105
|
-
end
|
1
|
+
module SabredavClient
|
2
|
+
|
3
|
+
class Events
|
4
|
+
attr_accessor :client
|
5
|
+
|
6
|
+
def initialize(client)
|
7
|
+
@client = client
|
8
|
+
end
|
9
|
+
|
10
|
+
def find(uri)
|
11
|
+
req = client.create_request(:get, path: uri)
|
12
|
+
res = req.run
|
13
|
+
|
14
|
+
SabredavClient::Errors::errorhandling(res)
|
15
|
+
|
16
|
+
etag = res.header["etag"]
|
17
|
+
etag = %Q/#{etag.gsub(/\A['"]+|['"]+\Z/, "")}/ unless etag.nil?
|
18
|
+
|
19
|
+
{
|
20
|
+
ics: res.body,
|
21
|
+
etag: etag
|
22
|
+
}
|
23
|
+
end
|
24
|
+
|
25
|
+
def find_multiple(starts: "", ends: "")
|
26
|
+
events = []
|
27
|
+
header = {depth: "1", content_type: "application/xml"}
|
28
|
+
|
29
|
+
if starts.is_a? Integer
|
30
|
+
body = SabredavClient::XmlRequestBuilder::ReportVEVENT.new(Time.at(starts).utc.strftime("%Y%m%dT%H%M%S"),
|
31
|
+
Time.at(ends).utc.strftime("%Y%m%dT%H%M%S") ).to_xml
|
32
|
+
else
|
33
|
+
body = SabredavClient::XmlRequestBuilder::ReportVEVENT.new(Time.parse(starts).utc.strftime("%Y%m%dT%H%M%S"),
|
34
|
+
Time.parse(ends).utc.strftime("%Y%m%dT%H%M%S") ).to_xml
|
35
|
+
end
|
36
|
+
|
37
|
+
req = client.create_request(:report, header: header)
|
38
|
+
res = req.run
|
39
|
+
|
40
|
+
SabredavClient::Errors::errorhandling(res)
|
41
|
+
result = ""
|
42
|
+
|
43
|
+
xml = REXML::Document.new(res.body)
|
44
|
+
REXML::XPath.each( xml, '//c:calendar-data/', {"c"=>"urn:ietf:params:xml:ns:caldav"} ){|c| result << c.text}
|
45
|
+
|
46
|
+
result
|
47
|
+
end
|
48
|
+
|
49
|
+
def owner(uri)
|
50
|
+
# Warning: This is not a standard request. It only works if your sabredav
|
51
|
+
# server uses a certain OwnerPlugin
|
52
|
+
header = {content_type: "application/xml"}
|
53
|
+
body = XmlRequestBuilder::PropfindOwner.new.to_xml
|
54
|
+
req = client.create_request(:propfind, path: uri, header: header, body: body)
|
55
|
+
res = req.run
|
56
|
+
|
57
|
+
SabredavClient::Errors::errorhandling(res)
|
58
|
+
xml = REXML::Document.new(res.body)
|
59
|
+
REXML::XPath.first(xml, "//cs:objectOwner").text
|
60
|
+
end
|
61
|
+
|
62
|
+
def update_owner(uri, owner)
|
63
|
+
# Warning: This is not a standard request. It only works if your sabredav
|
64
|
+
# server uses a certain OwnerPlugin
|
65
|
+
header = {content_type: "application/xml"}
|
66
|
+
body = XmlRequestBuilder::ProppatchEventsOwner.new(owner).to_xml
|
67
|
+
req = client.create_request(:proppatch, path: uri, header: header, body: body)
|
68
|
+
res = req.run
|
69
|
+
|
70
|
+
if res.code.to_i.between?(200,299)
|
71
|
+
true
|
72
|
+
else
|
73
|
+
SabredavClient::Errors::errorhandling(res)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def delete(uri)
|
78
|
+
raise SabredavClient::Errors::SabredavClientError if uri.nil? || !uri.end_with?(".ics")
|
79
|
+
|
80
|
+
req = client.create_request(:delete, path: uri)
|
81
|
+
res = req.run
|
82
|
+
|
83
|
+
if res.code.to_i.between?(200,299)
|
84
|
+
true
|
85
|
+
else
|
86
|
+
SabredavClient::Errors::errorhandling(res)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def create_update(uri, event_ics, etag = nil)
|
91
|
+
header = {content_type: "text/calendar"}
|
92
|
+
body = event_ics
|
93
|
+
|
94
|
+
if etag
|
95
|
+
header[:if_match] = %Q/"#{etag.gsub(/\A['"]+|['"]+\Z/, "")}"/
|
96
|
+
end
|
97
|
+
|
98
|
+
req = client.create_request(:put,header: header, body: body, path: uri)
|
99
|
+
res = req.run
|
100
|
+
|
101
|
+
SabredavClient::Errors::errorhandling(res)
|
102
|
+
etag = res['etag']
|
103
|
+
%Q/#{etag.gsub(/\A['"]+|['"]+\Z/, "")}/ unless etag.nil?
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
data/lib/sabredav_client/net.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
|
-
module Net
|
2
|
-
class HTTP
|
3
|
-
class Report < HTTPRequest
|
4
|
-
METHOD = 'REPORT'
|
5
|
-
REQUEST_HAS_BODY = true
|
6
|
-
RESPONSE_HAS_BODY = true
|
7
|
-
end
|
8
|
-
|
9
|
-
class Mkcalendar < HTTPRequest
|
10
|
-
METHOD = 'MKCALENDAR'
|
11
|
-
REQUEST_HAS_BODY = true
|
12
|
-
RESPONSE_HAS_BODY = true
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
1
|
+
module Net
|
2
|
+
class HTTP
|
3
|
+
class Report < HTTPRequest
|
4
|
+
METHOD = 'REPORT'
|
5
|
+
REQUEST_HAS_BODY = true
|
6
|
+
RESPONSE_HAS_BODY = true
|
7
|
+
end
|
8
|
+
|
9
|
+
class Mkcalendar < HTTPRequest
|
10
|
+
METHOD = 'MKCALENDAR'
|
11
|
+
REQUEST_HAS_BODY = true
|
12
|
+
RESPONSE_HAS_BODY = true
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -1,51 +1,51 @@
|
|
1
|
-
module SabredavClient
|
2
|
-
|
3
|
-
class Principal
|
4
|
-
attr_accessor :client
|
5
|
-
|
6
|
-
def initialize(data)
|
7
|
-
@client = SabredavClient::Client.new(data)
|
8
|
-
end
|
9
|
-
|
10
|
-
def create(email, displayname = nil)
|
11
|
-
header = {content_type: "text/xml", depth: "1"}
|
12
|
-
body = SabredavClient::XmlRequestBuilder::MkcolPrincipal.new(email, displayname).to_xml
|
13
|
-
req = client.create_request(:mkcol, header: header, body: body)
|
14
|
-
|
15
|
-
res = req.run
|
16
|
-
if res.code.to_i.between?(200,299)
|
17
|
-
true
|
18
|
-
else
|
19
|
-
SabredavClient::Errors::errorhandling(res)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def update(email: "", displayname: "")
|
24
|
-
header = {content_type: "application/xml"}
|
25
|
-
body = SabredavClient::XmlRequestBuilder::ProppatchPrincipal.new(email, displayname).to_xml
|
26
|
-
req = client.create_request(:proppatch, header: header, body: body)
|
27
|
-
|
28
|
-
res = req.run
|
29
|
-
|
30
|
-
if res.code.to_i.between?(200,299)
|
31
|
-
true
|
32
|
-
else
|
33
|
-
SabredavClient::Errors::errorhandling(res)
|
34
|
-
end
|
35
|
-
|
36
|
-
end
|
37
|
-
|
38
|
-
def delete
|
39
|
-
#FIXME seems like deleting a principal is forbidden by sabredav
|
40
|
-
req = client.create_request(:delete)
|
41
|
-
res = req.run
|
42
|
-
|
43
|
-
if res.code.to_i.between?(200,299)
|
44
|
-
true
|
45
|
-
else
|
46
|
-
SabredavClient::Errors::errorhandling(res)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
end
|
51
|
-
end
|
1
|
+
module SabredavClient
|
2
|
+
|
3
|
+
class Principal
|
4
|
+
attr_accessor :client
|
5
|
+
|
6
|
+
def initialize(data)
|
7
|
+
@client = SabredavClient::Client.new(data)
|
8
|
+
end
|
9
|
+
|
10
|
+
def create(email, displayname = nil)
|
11
|
+
header = {content_type: "text/xml", depth: "1"}
|
12
|
+
body = SabredavClient::XmlRequestBuilder::MkcolPrincipal.new(email, displayname).to_xml
|
13
|
+
req = client.create_request(:mkcol, header: header, body: body)
|
14
|
+
|
15
|
+
res = req.run
|
16
|
+
if res.code.to_i.between?(200,299)
|
17
|
+
true
|
18
|
+
else
|
19
|
+
SabredavClient::Errors::errorhandling(res)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def update(email: "", displayname: "")
|
24
|
+
header = {content_type: "application/xml"}
|
25
|
+
body = SabredavClient::XmlRequestBuilder::ProppatchPrincipal.new(email, displayname).to_xml
|
26
|
+
req = client.create_request(:proppatch, header: header, body: body)
|
27
|
+
|
28
|
+
res = req.run
|
29
|
+
|
30
|
+
if res.code.to_i.between?(200,299)
|
31
|
+
true
|
32
|
+
else
|
33
|
+
SabredavClient::Errors::errorhandling(res)
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
def delete
|
39
|
+
#FIXME seems like deleting a principal is forbidden by sabredav
|
40
|
+
req = client.create_request(:delete)
|
41
|
+
res = req.run
|
42
|
+
|
43
|
+
if res.code.to_i.between?(200,299)
|
44
|
+
true
|
45
|
+
else
|
46
|
+
SabredavClient::Errors::errorhandling(res)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|