sabredav_client 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/sabredav_client/calendar.rb +43 -0
- data/lib/sabredav_client/events.rb +5 -1
- data/lib/sabredav_client/version.rb +1 -1
- data/lib/sabredav_client/xml_request_builder/propfind_invite.rb +19 -0
- data/lib/sabredav_client/xml_request_builder/propfind_owner.rb +2 -2
- data/lib/sabredav_client/xml_request_builder/proppatch_owner.rb +2 -2
- data/lib/sabredav_client/xml_request_builder.rb +1 -1
- data/spec/fixtures/calendar_sharees.xml +35 -0
- data/spec/fixtures/events_owner.xml +1 -1
- data/spec/fixtures/xml_request_builder/propfind_invite.xml +6 -0
- data/spec/fixtures/xml_request_builder/propfind_owner.xml +2 -2
- data/spec/fixtures/xml_request_builder/proppatch_owner.xml +2 -2
- data/spec/sabredav_client/calendar_spec.rb +14 -1
- data/spec/sabredav_client/xml_request_builder_specs/propfind_invite_spec.rb +14 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 673012a844fcc49d9bdc6e0d3d26680e038a0d65
|
4
|
+
data.tar.gz: 3ef7b59e3f3be1d4dd979b9a11565bdda0b18476
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5bde2b10dac16f4ae9115f1822a27244979e14234b9fb216a4b83b13b2fbd32877fc252c54d3ad2bffc7c03209661dd790b0dd293cb42eecf9a60e0df4bf3e6a
|
7
|
+
data.tar.gz: 8dda7560901ade742fb28e5b7379f42a55ec9896d9ff341ffa979d43301bd60c3038034c50e440c4a3365d6b832b0941ee5d4f9a2b7011e572fd70b90fdb01fd
|
data/Gemfile.lock
CHANGED
@@ -71,6 +71,49 @@ module SabredavClient
|
|
71
71
|
end
|
72
72
|
end
|
73
73
|
|
74
|
+
def fetch_sharees
|
75
|
+
body = SabredavClient::XmlRequestBuilder::PropfindInvite.new.to_xml
|
76
|
+
header = {content_type: "application/xml", depth: "0"}
|
77
|
+
|
78
|
+
req = client.create_request(:propfind, header: header, body: body)
|
79
|
+
|
80
|
+
res = req.run
|
81
|
+
|
82
|
+
SabredavClient::Errors::errorhandling(res)
|
83
|
+
|
84
|
+
sharees = []
|
85
|
+
xml = REXML::Document.new(res.body)
|
86
|
+
|
87
|
+
REXML::XPath.each(xml, "//cs:user/", {"cs"=> "http://calendarserver.org/ns/"}) do |user|
|
88
|
+
entry = REXML::Document.new.add(user)
|
89
|
+
sharee = {
|
90
|
+
href: REXML::XPath.first(entry, "//d:href").text,
|
91
|
+
common_name: REXML::XPath.first(entry, "//d:common-name").text
|
92
|
+
}
|
93
|
+
access = REXML::XPath.first(entry, "//d:access").elements[1].to_s
|
94
|
+
sharee[:access] = access.gsub(/\A[<cs:]+|[\/>]+\Z/, "")
|
95
|
+
|
96
|
+
# So far Sabredav accepts every invite by default
|
97
|
+
sharee[:status] = :accepted unless REXML::XPath.first(entry, "//cs:invite-accepted").nil?
|
98
|
+
# URI depends on a custom plugin
|
99
|
+
begin
|
100
|
+
sharee[:uri] = REXML::XPath.first(entry, "//cs:uri").text
|
101
|
+
rescue
|
102
|
+
#sharee[:uri] = "Property not supported by SabreDAV server"
|
103
|
+
end
|
104
|
+
sharees.push(sharee)
|
105
|
+
end
|
106
|
+
|
107
|
+
{
|
108
|
+
sharees: sharees,
|
109
|
+
organizer: {
|
110
|
+
href: REXML::XPath.first(xml, "//cs:organizer").elements[2].text,
|
111
|
+
uri: REXML::XPath.first(xml, "//cs:uri").text
|
112
|
+
}
|
113
|
+
}
|
114
|
+
|
115
|
+
end
|
116
|
+
|
74
117
|
def fetch_changes(sync_token)
|
75
118
|
|
76
119
|
body = SabredavClient::XmlRequestBuilder::ReportEventChanges.new(sync_token).to_xml
|
@@ -40,6 +40,8 @@ module SabredavClient
|
|
40
40
|
end
|
41
41
|
|
42
42
|
def owner(uri)
|
43
|
+
# Warning: This is not a standard request. It only works if your sabredav
|
44
|
+
# server uses a certain OwnerPlugin
|
43
45
|
header = {content_type: "application/xml"}
|
44
46
|
body = XmlRequestBuilder::PropfindOwner.new.to_xml
|
45
47
|
req = client.create_request(:propfind, path: uri, header: header, body: body)
|
@@ -47,10 +49,12 @@ module SabredavClient
|
|
47
49
|
|
48
50
|
SabredavClient::Errors::errorhandling(res)
|
49
51
|
xml = REXML::Document.new(res.body)
|
50
|
-
REXML::XPath.first(xml, "//
|
52
|
+
REXML::XPath.first(xml, "//cs:objectOwner").text
|
51
53
|
end
|
52
54
|
|
53
55
|
def update_owner(uri, owner)
|
56
|
+
# Warning: This is not a standard request. It only works if your sabredav
|
57
|
+
# server uses a certain OwnerPlugin
|
54
58
|
header = {content_type: "application/xml"}
|
55
59
|
body = XmlRequestBuilder::ProppatchOwner.new(owner).to_xml
|
56
60
|
req = client.create_request(:proppatch, path: uri, header: header, body: body)
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module SabredavClient
|
2
|
+
module XmlRequestBuilder
|
3
|
+
|
4
|
+
class PropfindInvite < Base
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
super()
|
8
|
+
end
|
9
|
+
|
10
|
+
def to_xml
|
11
|
+
xml.d :propfind, CS_NAMESPACES do
|
12
|
+
xml.d :prop do
|
13
|
+
xml.cs :invite
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'builder'
|
2
2
|
|
3
3
|
['base.rb', 'propfind_calendar.rb', 'mkcalendar.rb', 'post_sharing.rb', 'report_vevent.rb', 'report_vtodo.rb', 'mkcol_principal.rb',
|
4
|
-
'report_event_changes.rb', 'propfind_owner.rb', 'proppatch_owner.rb'].each do |f|
|
4
|
+
'report_event_changes.rb', 'propfind_owner.rb', 'proppatch_owner.rb', 'propfind_invite.rb'].each do |f|
|
5
5
|
require File.join( File.dirname(__FILE__), 'xml_request_builder', f )
|
6
6
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
<?xml version="1.0"?>
|
2
|
+
<d:multistatus xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns" xmlns:cal="urn:ietf:params:xml:ns:caldav" xmlns:cs="http://calendarserver.org/ns/">
|
3
|
+
<d:response>
|
4
|
+
<d:href>/caldav/server.php/user/calendar/</d:href>
|
5
|
+
<d:propstat>
|
6
|
+
<d:prop>
|
7
|
+
<cs:invite>
|
8
|
+
<cs:organizer>
|
9
|
+
<cs:uri>D8D498E2-4A98-4DC7-B421-BC49261168AF</cs:uri>
|
10
|
+
<d:href>/caldav/server.php/principals/user</d:href>
|
11
|
+
</cs:organizer>
|
12
|
+
<cs:user>
|
13
|
+
<cs:invite-accepted/>
|
14
|
+
<cs:access>
|
15
|
+
<cs:read/>
|
16
|
+
</cs:access>
|
17
|
+
<cs:uri>5bffa09e-7220-4688-a13f-088714a98783</cs:uri>
|
18
|
+
<d:href>mailto:sharee1@njiuko.com</d:href>
|
19
|
+
<cs:common-name>sharee1</cs:common-name>
|
20
|
+
</cs:user>
|
21
|
+
<cs:user>
|
22
|
+
<cs:invite-accepted/>
|
23
|
+
<cs:access>
|
24
|
+
<cs:write-read/>
|
25
|
+
</cs:access>
|
26
|
+
<cs:uri>f176b400-f0e4-4a57-bd92-0c307810ce12</cs:uri>
|
27
|
+
<d:href>mailto:sharee2@protonet.info</d:href>
|
28
|
+
<cs:common-name>sharee2</cs:common-name>
|
29
|
+
</cs:user>
|
30
|
+
</cs:invite>
|
31
|
+
</d:prop>
|
32
|
+
<d:status>HTTP/1.1 200 OK</d:status>
|
33
|
+
</d:propstat>
|
34
|
+
</d:response>
|
35
|
+
</d:multistatus>
|
@@ -1,8 +1,8 @@
|
|
1
1
|
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
-
<d:propertyupdate xmlns:d="DAV:">
|
2
|
+
<d:propertyupdate xmlns:d="DAV:" xmlns:cs="http://calendarserver.org/ns/">
|
3
3
|
<d:set>
|
4
4
|
<d:prop>
|
5
|
-
<
|
5
|
+
<cs:objectOwner>principals/usertest</cs:objectOwner>
|
6
6
|
</d:prop>
|
7
7
|
</d:set>
|
8
8
|
</d:propertyupdate>
|
@@ -52,7 +52,7 @@ describe SabredavClient::Calendar do
|
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
55
|
-
describe "
|
55
|
+
describe "sharing" do
|
56
56
|
FakeWeb.register_uri(:post, "http://user@localhost:5232/user/calendar/", [{status: ["200", "OK"]},
|
57
57
|
{status: ["200", "OK"]}])
|
58
58
|
it "is type email" do
|
@@ -72,6 +72,19 @@ describe SabredavClient::Calendar do
|
|
72
72
|
r = calendar.share(adds: ["test@test.de"], privilege: "write-read")
|
73
73
|
expect(r).to be(true)
|
74
74
|
end
|
75
|
+
|
76
|
+
it "fetch_sharees" do
|
77
|
+
FakeWeb.register_uri(:propfind, "http://user@localhost:5232/user/calendar/", body: File.open('spec/fixtures/calendar_sharees.xml') )
|
78
|
+
|
79
|
+
organizer = {href: "/caldav/server.php/principals/user", uri: "D8D498E2-4A98-4DC7-B421-BC49261168AF"}
|
80
|
+
sharees =
|
81
|
+
[{href: "mailto:sharee1@njiuko.com", common_name: "sharee1", access: "read", status: :accepted, uri: "5bffa09e-7220-4688-a13f-088714a98783"},
|
82
|
+
{href: "mailto:sharee2@protonet.info", common_name: "sharee2", access: "write-read", status: :accepted, uri: "f176b400-f0e4-4a57-bd92-0c307810ce12"}]
|
83
|
+
expected_result = {sharees: sharees, organizer: organizer}
|
84
|
+
|
85
|
+
r = calendar.fetch_sharees
|
86
|
+
expect(r).to eq(expected_result)
|
87
|
+
end
|
75
88
|
end
|
76
89
|
|
77
90
|
describe "info" do
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe SabredavClient::XmlRequestBuilder::PropfindInvite do
|
4
|
+
|
5
|
+
let(:propfind) { described_class.new }
|
6
|
+
|
7
|
+
describe "#to_xml" do
|
8
|
+
let(:expected_xml) { File.read('spec/fixtures/xml_request_builder/propfind_invite.xml') }
|
9
|
+
|
10
|
+
it "returns a valid xml" do
|
11
|
+
expect(propfind.to_xml).to eq(expected_xml)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sabredav_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nicolas Schwartau
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-08-
|
11
|
+
date: 2016-08-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: builder
|
@@ -96,6 +96,7 @@ files:
|
|
96
96
|
- lib/sabredav_client/xml_request_builder/mkcol_principal.rb
|
97
97
|
- lib/sabredav_client/xml_request_builder/post_sharing.rb
|
98
98
|
- lib/sabredav_client/xml_request_builder/propfind_calendar.rb
|
99
|
+
- lib/sabredav_client/xml_request_builder/propfind_invite.rb
|
99
100
|
- lib/sabredav_client/xml_request_builder/propfind_owner.rb
|
100
101
|
- lib/sabredav_client/xml_request_builder/proppatch_owner.rb
|
101
102
|
- lib/sabredav_client/xml_request_builder/report_event_changes.rb
|
@@ -104,6 +105,7 @@ files:
|
|
104
105
|
- sabredav_client.gemspec
|
105
106
|
- spec/fixtures/calendar_fetch_changes.xml
|
106
107
|
- spec/fixtures/calendar_info.xml
|
108
|
+
- spec/fixtures/calendar_sharees.xml
|
107
109
|
- spec/fixtures/event.ics
|
108
110
|
- spec/fixtures/events_find_multiple.xml
|
109
111
|
- spec/fixtures/events_owner.xml
|
@@ -111,6 +113,7 @@ files:
|
|
111
113
|
- spec/fixtures/xml_request_builder/mkcol_principal.xml
|
112
114
|
- spec/fixtures/xml_request_builder/post_sharing.xml
|
113
115
|
- spec/fixtures/xml_request_builder/propfind_calendar/all_properties.xml
|
116
|
+
- spec/fixtures/xml_request_builder/propfind_invite.xml
|
114
117
|
- spec/fixtures/xml_request_builder/propfind_owner.xml
|
115
118
|
- spec/fixtures/xml_request_builder/proppatch_owner.xml
|
116
119
|
- spec/fixtures/xml_request_builder/report_event_changes.xml
|
@@ -124,6 +127,7 @@ files:
|
|
124
127
|
- spec/sabredav_client/xml_request_builder_specs/mkcol_principal_spec.rb
|
125
128
|
- spec/sabredav_client/xml_request_builder_specs/post_sharing_spec.rb
|
126
129
|
- spec/sabredav_client/xml_request_builder_specs/propfind_calendar_spec.rb
|
130
|
+
- spec/sabredav_client/xml_request_builder_specs/propfind_invite_spec.rb
|
127
131
|
- spec/sabredav_client/xml_request_builder_specs/propfind_owner_spec.rb
|
128
132
|
- spec/sabredav_client/xml_request_builder_specs/proppatch_owner_spec.rb
|
129
133
|
- spec/sabredav_client/xml_request_builder_specs/report_event_changes_spec.rb
|