sabredav_client 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 673012a844fcc49d9bdc6e0d3d26680e038a0d65
4
- data.tar.gz: 3ef7b59e3f3be1d4dd979b9a11565bdda0b18476
3
+ metadata.gz: 4cc0b05832228bea29085253b712b72cd9c3332b
4
+ data.tar.gz: 98a50476b735fbdc9b664e4e8dc42de3f2ba4855
5
5
  SHA512:
6
- metadata.gz: 5bde2b10dac16f4ae9115f1822a27244979e14234b9fb216a4b83b13b2fbd32877fc252c54d3ad2bffc7c03209661dd790b0dd293cb42eecf9a60e0df4bf3e6a
7
- data.tar.gz: 8dda7560901ade742fb28e5b7379f42a55ec9896d9ff341ffa979d43301bd60c3038034c50e440c4a3365d6b832b0941ee5d4f9a2b7011e572fd70b90fdb01fd
6
+ metadata.gz: c74076b2c3c17556c50ed4f80ff5659ae18b0ff79df53153fea7c394b951ceec412cf96cab45e3da4f22e36a8d43dc330f06ad913090d32c63957bbc83eb5da1
7
+ data.tar.gz: 67e6f8fa5b7c4433767d2a43b95f768d45f811ef3f949022ef4f6c9ecd3f86e4d3c7e1cae4617c72587d9a97741a3bd4e16e6bd983df87a79ae5bd4af3964301
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sabredav_client (0.1.1)
4
+ sabredav_client (0.1.2)
5
5
  builder (~> 3.2)
6
6
  net-http-digest_auth (~> 1.4)
7
7
 
@@ -97,9 +97,11 @@ module SabredavClient
97
97
  sharee[:status] = :accepted unless REXML::XPath.first(entry, "//cs:invite-accepted").nil?
98
98
  # URI depends on a custom plugin
99
99
  begin
100
- sharee[:uri] = REXML::XPath.first(entry, "//cs:uri").text
100
+ sharee[:uri] = REXML::XPath.first(entry, "//cs:uri").text
101
+ sharee[:principal] = REXML::XPath.first(entry, "//cs:principal").text
101
102
  rescue
102
103
  #sharee[:uri] = "Property not supported by SabreDAV server"
104
+ #sharee[:uri] = "Property not supported by SabreDAV server"
103
105
  end
104
106
  sharees.push(sharee)
105
107
  end
@@ -10,7 +10,7 @@ module SabredavClient
10
10
  def create(email, displayname = nil)
11
11
  header = {content_type: "text/xml", depth: "1"}
12
12
  body = SabredavClient::XmlRequestBuilder::MkcolPrincipal.new(email, displayname).to_xml
13
- req = client.create_request(:mkcol, header: header, body: body)
13
+ req = client.create_request(:mkcol, header: header, body: body)
14
14
 
15
15
  res = req.run
16
16
  if res.code.to_i.between?(200,299)
@@ -20,6 +20,21 @@ module SabredavClient
20
20
  end
21
21
  end
22
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
+
23
38
  def delete
24
39
  #FIXME seems like deleting a principal is forbidden by sabredav
25
40
  req = client.create_request(:delete)
@@ -1,3 +1,3 @@
1
1
  module SabredavClient
2
- VERSION="0.1.2"
2
+ VERSION="0.1.3"
3
3
  end
@@ -0,0 +1,25 @@
1
+ module SabredavClient
2
+ module XmlRequestBuilder
3
+
4
+ class ProppatchPrincipal < Base
5
+ attr_accessor :email, :displayname
6
+
7
+ def initialize(email, displayname)
8
+ @email = email
9
+ @displayname = displayname
10
+ super()
11
+ end
12
+
13
+ def to_xml
14
+ xml.d :propertyupdate, SB_NAMESPACES do
15
+ xml.d :set do
16
+ xml.d :prop do
17
+ xml.tag! "sb:email-address", email unless email.empty?
18
+ xml.d :displayname, displayname unless displayname.empty?
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ 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', 'propfind_invite.rb'].each do |f|
4
+ 'report_event_changes.rb', 'propfind_owner.rb', 'proppatch_owner.rb', 'propfind_invite.rb', 'proppatch_principal.rb'].each do |f|
5
5
  require File.join( File.dirname(__FILE__), 'xml_request_builder', f )
6
6
  end
@@ -0,0 +1,9 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <d:propertyupdate xmlns:d="DAV:" xmlns:sb="http://sabredav.org/ns">
3
+ <d:set>
4
+ <d:prop>
5
+ <sb:email-address>update@test.de</sb:email-address>
6
+ <d:displayname>David B.</d:displayname>
7
+ </d:prop>
8
+ </d:set>
9
+ </d:propertyupdate>
@@ -12,7 +12,7 @@ describe SabredavClient::Client do
12
12
  end
13
13
  end
14
14
 
15
- describe "principal" do
15
+ describe "create" do
16
16
  email = "test@mail.de"
17
17
  description = "a random description"
18
18
 
@@ -35,4 +35,17 @@ describe SabredavClient::Client do
35
35
  }.to raise_error(SabredavClient::Errors::NotAllowedError)
36
36
  end
37
37
  end
38
+
39
+ describe "update" do
40
+
41
+ it "updates email and displayname" do
42
+ email = "update@test.de"
43
+ displayname = "David B."
44
+ FakeWeb.register_uri(:proppatch, "http://user@localhost:5232/user/principals/user/", status: ["207", "OK"])
45
+
46
+ result = principal.update(email: email, displayname: displayname)
47
+ expect(result).to be
48
+
49
+ end
50
+ end
38
51
  end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe SabredavClient::XmlRequestBuilder::ProppatchPrincipal do
4
+
5
+ let(:proppatch) { described_class.new(email = "update@test.de", diplayname = "David B." ) }
6
+
7
+ describe "#to_xml" do
8
+ let(:expected_xml) { File.read('spec/fixtures/xml_request_builder/proppatch_principal.xml') }
9
+
10
+ it "returns a valid xml" do
11
+ expect(proppatch.to_xml).to eq(expected_xml)
12
+ end
13
+
14
+ it "returns a valid xml without email address" do
15
+ proppatch.email = ""
16
+ expect(proppatch.to_xml).not_to include("sb:email-address")
17
+ end
18
+
19
+ it "returns a valid xml without displayname" do
20
+ proppatch.displayname = ""
21
+ expect(proppatch.to_xml).not_to include("d:displayname")
22
+ end
23
+ end
24
+ 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.2
4
+ version: 0.1.3
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-26 00:00:00.000000000 Z
11
+ date: 2016-08-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: builder
@@ -99,6 +99,7 @@ files:
99
99
  - lib/sabredav_client/xml_request_builder/propfind_invite.rb
100
100
  - lib/sabredav_client/xml_request_builder/propfind_owner.rb
101
101
  - lib/sabredav_client/xml_request_builder/proppatch_owner.rb
102
+ - lib/sabredav_client/xml_request_builder/proppatch_principal.rb
102
103
  - lib/sabredav_client/xml_request_builder/report_event_changes.rb
103
104
  - lib/sabredav_client/xml_request_builder/report_vevent.rb
104
105
  - lib/sabredav_client/xml_request_builder/report_vtodo.rb
@@ -116,6 +117,7 @@ files:
116
117
  - spec/fixtures/xml_request_builder/propfind_invite.xml
117
118
  - spec/fixtures/xml_request_builder/propfind_owner.xml
118
119
  - spec/fixtures/xml_request_builder/proppatch_owner.xml
120
+ - spec/fixtures/xml_request_builder/proppatch_principal.xml
119
121
  - spec/fixtures/xml_request_builder/report_event_changes.xml
120
122
  - spec/sabredav_client/calendar_spec.rb
121
123
  - spec/sabredav_client/client_spec.rb
@@ -130,6 +132,7 @@ files:
130
132
  - spec/sabredav_client/xml_request_builder_specs/propfind_invite_spec.rb
131
133
  - spec/sabredav_client/xml_request_builder_specs/propfind_owner_spec.rb
132
134
  - spec/sabredav_client/xml_request_builder_specs/proppatch_owner_spec.rb
135
+ - spec/sabredav_client/xml_request_builder_specs/proppatch_principal_spec.rb
133
136
  - spec/sabredav_client/xml_request_builder_specs/report_event_changes_spec.rb
134
137
  - spec/spec.opts
135
138
  - spec/spec_helper.rb