dav4rack_ext 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 22bc67021255d19795f35d47d0e9299ae1db9c91
4
- data.tar.gz: 3bd4d094d4eab7acae0ab1d1de74bdf4d5647968
3
+ metadata.gz: 7e9aba179c4d57f91f74b9a4ae41ff44d0290121
4
+ data.tar.gz: 6b0bf9822b2f75bccedc1d936570ba7b34d776ef
5
5
  SHA512:
6
- metadata.gz: 64e22e835a41c7895882f4194e73cc8df9d2748bfc330551821f9354cbd82c471a170fcb3217a3ac9d601bb22fb47cdbc29a3442ceb582c384ab42190c759c43
7
- data.tar.gz: ff0c650ca6eab05fccff13b2ad2e97f8da925ff9a10b10905e2b8449ae3c93aa13277f32c5c75e29258e19d79ac58dc0c9fd78323de64cf4801f74c56cd05444
6
+ metadata.gz: e7848ea5f4c8f6deab94e88ea184faaef5fe9e39e4733d6a094446c71f437c92323f90d0ba8b010f01714d562e347bce58c9d109cc9a3be2ba3f59048fdd7327
7
+ data.tar.gz: 6e37118a3554e3abaf02a3298f0fb7f314f0709868d7ee531c74ebc84d5142b598903e1db89d6625a157a597f89cd7f14695ed0d7aa294314e0da1995dc4ea9b
data/.travis.yml CHANGED
@@ -1,6 +1,4 @@
1
1
  env: TRAVIS_CI=1
2
2
  bundler_args: --without local
3
3
  rvm:
4
- - 1.9.3
5
- - 2.0.0
6
-
4
+ - 2.3.1
@@ -28,6 +28,8 @@ module DAV4Rack
28
28
  case request_document.root.name
29
29
  when 'addressbook-multiget'
30
30
  addressbook_multiget(request_document)
31
+ when 'addressbook-query'
32
+ addressbook_query(request_document)
31
33
  else
32
34
  render_xml(:error) do |xml|
33
35
  xml.send :'supported-report'
@@ -53,6 +55,30 @@ module DAV4Rack
53
55
  end
54
56
  "*[local-name()='#{name}' and namespace-uri()='#{ns_uri}']"
55
57
  end
58
+
59
+
60
+ def addressbook_query(request_document)
61
+
62
+ props = []
63
+ request_document.css("C|addressbook-query > D|prop", NAMESPACES).each do |el|
64
+ el.children.select(&:element?).each do |child|
65
+ props << to_element_hash(child)
66
+ end
67
+ end
68
+
69
+
70
+ contacts = resource.children
71
+
72
+ multistatus do |xml|
73
+ contacts.each do |contact|
74
+ xml.response do
75
+ xml.href contact.path
76
+ propstats(xml, get_properties(contact, props))
77
+ end
78
+ end
79
+ end
80
+ end
81
+
56
82
 
57
83
  def addressbook_multiget(request_document)
58
84
  # TODO: Include a DAV:error response
@@ -55,6 +55,12 @@ module DAV4Rack
55
55
  @address_book.updated_at
56
56
  end
57
57
 
58
+ explicit do
59
+ property('sync-token') do
60
+ @address_book.updated_at
61
+ end
62
+ end
63
+
58
64
  end
59
65
 
60
66
 
@@ -25,6 +25,13 @@ module DAV4Rack
25
25
  property('getlastmodified') do
26
26
  @contact.updated_at
27
27
  end
28
+
29
+ explicit do
30
+ property('sync-token') do
31
+ @contact.etag
32
+ end
33
+ end
34
+
28
35
  end
29
36
 
30
37
  define_properties(CARDAV_NS) do
@@ -78,6 +85,8 @@ module DAV4Rack
78
85
  raise Conflict if (want_new_contact and @contact)
79
86
 
80
87
  if if_match = request.env['HTTP_IF_MATCH']
88
+ # remove quotes if present
89
+ if_match = if_match.tr('"', '')
81
90
  # client wants to update a contact, return an error if no
82
91
  # contact was found
83
92
  if (if_match == '*') || !@contact
@@ -1,3 +1,3 @@
1
1
  module Dav4rackExt
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
@@ -1,4 +1,34 @@
1
1
  module HTTPDAVTest
2
+ def report(url, properties = [], opts = {})
3
+ namespaces = {
4
+ 'DAV:' => 'D',
5
+ 'urn:ietf:params:xml:ns:carddav' => 'C'
6
+ }
7
+
8
+ fields_list = properties.map do |prop_name|
9
+ %{<C:prop name="#{prop_name}"/>}
10
+ end.join("\n")
11
+
12
+ body = <<~EOS
13
+ <D:prop>
14
+ <D:getetag/>
15
+ <C:address-data>
16
+ #{fields_list}
17
+ </C:address-data>
18
+ </D:prop>
19
+ <C:filter/>
20
+ EOS
21
+
22
+ data = <<~EOS
23
+ <?xml version="1.0" encoding="UTF-8"?>
24
+ <C:addressbook-query xmlns:D="DAV:" xmlns:C="urn:ietf:params:xml:ns:carddav">
25
+ #{body}
26
+ </C:addressbook-query>
27
+ EOS
28
+
29
+ request('REPORT', url, opts.merge(input: data))
30
+ end
31
+
2
32
  def propfind(url, properties = :all, opts = {})
3
33
  namespaces = {
4
34
  'DAV:' => 'D',
@@ -182,6 +182,20 @@ END:VCARD
182
182
  value.should == :empty
183
183
  end
184
184
 
185
+ it 'DAV:sync-token', focus: true do
186
+ response = propfind('/books/castor', [
187
+ ['displayname', @dav_ns],
188
+ ['sync-token', @dav_ns]
189
+ ])
190
+
191
+ response.status.should == 207
192
+
193
+ puts response.body
194
+
195
+ value = element_content(response, 'D|sync-token', 'D' => @carddav_ns)
196
+ value.should == 'TOTO'
197
+
198
+ end
185
199
  end
186
200
 
187
201
 
@@ -218,15 +232,30 @@ END:VCARD
218
232
  end
219
233
  end
220
234
 
221
- it '[8.6] CARDDAV:addressbook-query Report' do
222
- # unsupported for now
235
+ describe '[8.6] CARDDAV:addressbook-query Report' do
236
+ before do
237
+ # @contact1 = FactoryGirl.build(:contact, uid: '1234-5678-9000-1')
238
+ # @contact2 = FactoryGirl.build(:contact, uid: '1234-5678-9000-2')
239
+ end
240
+
241
+ should 'return results' do
242
+ response = report('/books/castor', %w(UID EMAIL FN))
243
+ # puts response.body
244
+ elements = ensure_element_exists(response, 'D|multistatus > D|response', 'D' => @dav_ns)
245
+
246
+ elements[0].tap do |el|
247
+ el.css('D|href', 'D' => @dav_ns).first.content.should == "/books/castor/1234-5678-9000-1"
248
+ el.css('D|getetag', 'D' => @dav_ns).first.content.should == "ETAG"
249
+ end
250
+
251
+ end
223
252
  end
224
253
 
225
254
 
226
255
  describe '[8.7] CARDDAV:addressbook-multiget Report' do
227
256
  before do
228
- @contact = FactoryGirl.build(:contact, uid: '1234-5678-9000-1')
229
- @contact.stubs(:vcard).returns(@parsed_vcard)
257
+ # @contact = FactoryGirl.build(:contact, uid: '1234-5678-9000-1')
258
+ # @contact.stubs(:vcard).returns(@parsed_vcard)
230
259
 
231
260
 
232
261
  @raw_query = <<-EOS
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dav4rack_ext
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julien Ammous
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-18 00:00:00.000000000 Z
11
+ date: 2018-04-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dav4rack
@@ -115,7 +115,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
115
115
  version: '0'
116
116
  requirements: []
117
117
  rubyforge_project:
118
- rubygems_version: 2.5.1
118
+ rubygems_version: 2.6.8
119
119
  signing_key:
120
120
  specification_version: 4
121
121
  summary: CardDAV / CalDAV implementation.