sabredav_client 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -3
  3. data/.rspec +1 -1
  4. data/CHANGELOG.rdoc +8 -8
  5. data/Gemfile +3 -3
  6. data/Gemfile.lock +38 -39
  7. data/README.md +49 -49
  8. data/Rakefile +5 -5
  9. data/lib/sabredav_client.rb +10 -10
  10. data/lib/sabredav_client/calendar.rb +174 -171
  11. data/lib/sabredav_client/client.rb +57 -57
  12. data/lib/sabredav_client/errors/errors.rb +41 -41
  13. data/lib/sabredav_client/events.rb +106 -106
  14. data/lib/sabredav_client/net.rb +15 -15
  15. data/lib/sabredav_client/principal.rb +51 -51
  16. data/lib/sabredav_client/request.rb +97 -97
  17. data/lib/sabredav_client/version.rb +3 -3
  18. data/lib/sabredav_client/xml_request_builder.rb +7 -7
  19. data/lib/sabredav_client/xml_request_builder/base.rb +17 -17
  20. data/lib/sabredav_client/xml_request_builder/mkcalendar.rb +25 -25
  21. data/lib/sabredav_client/xml_request_builder/mkcol_principal.rb +28 -28
  22. data/lib/sabredav_client/xml_request_builder/post_sharing.rb +41 -41
  23. data/lib/sabredav_client/xml_request_builder/propfind_calendar.rb +41 -41
  24. data/lib/sabredav_client/xml_request_builder/propfind_invite.rb +19 -19
  25. data/lib/sabredav_client/xml_request_builder/propfind_owner.rb +19 -19
  26. data/lib/sabredav_client/xml_request_builder/proppatch_calendar.rb +25 -25
  27. data/lib/sabredav_client/xml_request_builder/proppatch_events_owner.rb +23 -23
  28. data/lib/sabredav_client/xml_request_builder/proppatch_principal.rb +25 -25
  29. data/lib/sabredav_client/xml_request_builder/report_event_changes.rb +22 -22
  30. data/lib/sabredav_client/xml_request_builder/report_vevent.rb +30 -30
  31. data/lib/sabredav_client/xml_request_builder/report_vtodo.rb +20 -20
  32. data/sabredav_client.gemspec +31 -31
  33. data/spec/fixtures/calendar_fetch_changes.xml +26 -26
  34. data/spec/fixtures/calendar_info.xml +14 -14
  35. data/spec/fixtures/calendar_sharees.xml +35 -35
  36. data/spec/fixtures/calendar_sharees_without_common_name.xml +26 -26
  37. data/spec/fixtures/event.ics +23 -23
  38. data/spec/fixtures/events_find_multiple.xml +51 -51
  39. data/spec/fixtures/events_owner.xml +12 -12
  40. data/spec/fixtures/xml_request_builder/mkcalendar.xml +9 -9
  41. data/spec/fixtures/xml_request_builder/mkcol_principal.xml +12 -12
  42. data/spec/fixtures/xml_request_builder/post_sharing.xml +18 -18
  43. data/spec/fixtures/xml_request_builder/propfind_calendar/all_properties.xml +8 -8
  44. data/spec/fixtures/xml_request_builder/propfind_invite.xml +6 -6
  45. data/spec/fixtures/xml_request_builder/propfind_owner.xml +6 -6
  46. data/spec/fixtures/xml_request_builder/proppatch_calendar.xml +9 -9
  47. data/spec/fixtures/xml_request_builder/proppatch_events_owner.xml +8 -8
  48. data/spec/fixtures/xml_request_builder/proppatch_principal.xml +9 -9
  49. data/spec/fixtures/xml_request_builder/report_event_changes.xml +8 -8
  50. data/spec/sabredav_client/calendar_spec.rb +142 -142
  51. data/spec/sabredav_client/client_spec.rb +41 -41
  52. data/spec/sabredav_client/events_spec.rb +119 -119
  53. data/spec/sabredav_client/principal_spec.rb +51 -51
  54. data/spec/sabredav_client/request_spec.rb +55 -55
  55. data/spec/sabredav_client/xml_request_builder_specs/base_spec.rb +30 -30
  56. data/spec/sabredav_client/xml_request_builder_specs/mkcalendar_spec.rb +13 -13
  57. data/spec/sabredav_client/xml_request_builder_specs/mkcol_principal_spec.rb +13 -13
  58. data/spec/sabredav_client/xml_request_builder_specs/post_sharing_spec.rb +15 -15
  59. data/spec/sabredav_client/xml_request_builder_specs/propfind_calendar_spec.rb +24 -24
  60. data/spec/sabredav_client/xml_request_builder_specs/propfind_invite_spec.rb +14 -14
  61. data/spec/sabredav_client/xml_request_builder_specs/propfind_owner_spec.rb +14 -14
  62. data/spec/sabredav_client/xml_request_builder_specs/proppatch_calendar.rb +15 -15
  63. data/spec/sabredav_client/xml_request_builder_specs/proppatch_events_owner_spec.rb +14 -14
  64. data/spec/sabredav_client/xml_request_builder_specs/proppatch_principal_spec.rb +24 -24
  65. data/spec/sabredav_client/xml_request_builder_specs/report_event_changes_spec.rb +15 -15
  66. data/spec/spec.opts +4 -4
  67. data/spec/spec_helper.rb +8 -8
  68. metadata +6 -5
@@ -1,97 +1,97 @@
1
- module SabredavClient
2
- class Request
3
- attr_accessor :path
4
- attr_reader :client, :request, :http
5
-
6
- def initialize(method, client, path)
7
- @client = client
8
- @path = "#{client.base_path}/#{path}"
9
- @http = build_http
10
- @request = build_request(method)
11
-
12
- add_auth
13
- end
14
-
15
- def add_body(body)
16
- request.body = body
17
- end
18
-
19
- def add_header(data)
20
- request['Content-Length'] = data[:content_length] if data[:content_length]
21
- request['If-Match'] = data[:if_match] if data[:if_match]
22
- request['Content-Type'] = data[:content_type] if data[:content_type]
23
- request['DAV'] = data[:dav] if data[:dav]
24
- end
25
-
26
- def run
27
- @http.request(request)
28
- end
29
-
30
- private
31
-
32
- def build_http
33
- unless client.proxy_uri
34
- http = Net::HTTP.new(client.host, client.port)
35
- else
36
- http = Net::HTTP.new(client.host, client.port, client.proxy_host, client.proxy_port)
37
- end
38
-
39
- if client.ssl
40
- http.use_ssl = client.ssl
41
- http.verify_mode = OpenSSL::SSL::VERIFY_NONE
42
- end
43
-
44
- http
45
- end
46
-
47
- def build_request(method)
48
- case method
49
- when :get
50
- Net::HTTP::Get.new(path)
51
- when :post
52
- Net::HTTP::Post.new(path)
53
- when :put
54
- Net::HTTP::Put.new(path)
55
- when :delete
56
- Net::HTTP::Delete.new(path)
57
- when :propfind
58
- Net::HTTP::Propfind.new(path)
59
- when :proppatch
60
- Net::HTTP::Proppatch.new(path)
61
- when :report
62
- Net::HTTP::Report.new(path)
63
- when :mkcalendar
64
- Net::HTTP::Mkcalendar.new(path)
65
- when :mkcol
66
- Net::HTTP::Mkcol.new(path)
67
- else
68
- raise SabredavClient::Errors::HTTPMethodNotSupportedError, method
69
- end
70
- end
71
-
72
- def add_auth
73
- unless client.authtype == 'digest'
74
- request.basic_auth client.user, client.password
75
- else
76
- request.add_field 'Authorization', digestauth(method.to_s.upcase)
77
- end
78
- end
79
-
80
- def digestauth
81
- h = Net::HTTP.new client.duri.host, client.duri.port
82
-
83
- if client.ssl
84
- h.use_ssl = client.ssl
85
- h.verify_mode = OpenSSL::SSL::VERIFY_NONE
86
- end
87
-
88
- req = Net::HTTP::Get.new client.duri.request_uri
89
- res = h.request req
90
- # res is a 401 response with a WWW-Authenticate header
91
-
92
- auth = client.digest_auth.auth_header client.duri, res['www-authenticate'], method
93
-
94
- return auth
95
- end
96
- end
97
- end
1
+ module SabredavClient
2
+ class Request
3
+ attr_accessor :path
4
+ attr_reader :client, :request, :http
5
+
6
+ def initialize(method, client, path)
7
+ @client = client
8
+ @path = "#{client.base_path}/#{path}"
9
+ @http = build_http
10
+ @request = build_request(method)
11
+
12
+ add_auth
13
+ end
14
+
15
+ def add_body(body)
16
+ request.body = body
17
+ end
18
+
19
+ def add_header(data)
20
+ request['Content-Length'] = data[:content_length] if data[:content_length]
21
+ request['If-Match'] = data[:if_match] if data[:if_match]
22
+ request['Content-Type'] = data[:content_type] if data[:content_type]
23
+ request['DAV'] = data[:dav] if data[:dav]
24
+ end
25
+
26
+ def run
27
+ @http.request(request)
28
+ end
29
+
30
+ private
31
+
32
+ def build_http
33
+ unless client.proxy_uri
34
+ http = Net::HTTP.new(client.host, client.port)
35
+ else
36
+ http = Net::HTTP.new(client.host, client.port, client.proxy_host, client.proxy_port)
37
+ end
38
+
39
+ if client.ssl
40
+ http.use_ssl = client.ssl
41
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
42
+ end
43
+
44
+ http
45
+ end
46
+
47
+ def build_request(method)
48
+ case method
49
+ when :get
50
+ Net::HTTP::Get.new(path)
51
+ when :post
52
+ Net::HTTP::Post.new(path)
53
+ when :put
54
+ Net::HTTP::Put.new(path)
55
+ when :delete
56
+ Net::HTTP::Delete.new(path)
57
+ when :propfind
58
+ Net::HTTP::Propfind.new(path)
59
+ when :proppatch
60
+ Net::HTTP::Proppatch.new(path)
61
+ when :report
62
+ Net::HTTP::Report.new(path)
63
+ when :mkcalendar
64
+ Net::HTTP::Mkcalendar.new(path)
65
+ when :mkcol
66
+ Net::HTTP::Mkcol.new(path)
67
+ else
68
+ raise SabredavClient::Errors::HTTPMethodNotSupportedError, method
69
+ end
70
+ end
71
+
72
+ def add_auth
73
+ unless client.authtype == 'digest'
74
+ request.basic_auth client.user, client.password
75
+ else
76
+ request.add_field 'Authorization', digestauth(method.to_s.upcase)
77
+ end
78
+ end
79
+
80
+ def digestauth
81
+ h = Net::HTTP.new client.duri.host, client.duri.port
82
+
83
+ if client.ssl
84
+ h.use_ssl = client.ssl
85
+ h.verify_mode = OpenSSL::SSL::VERIFY_NONE
86
+ end
87
+
88
+ req = Net::HTTP::Get.new client.duri.request_uri
89
+ res = h.request req
90
+ # res is a 401 response with a WWW-Authenticate header
91
+
92
+ auth = client.digest_auth.auth_header client.duri, res['www-authenticate'], method
93
+
94
+ return auth
95
+ end
96
+ end
97
+ end
@@ -1,3 +1,3 @@
1
- module SabredavClient
2
- VERSION="0.2.1"
3
- end
1
+ module SabredavClient
2
+ VERSION="0.2.2"
3
+ end
@@ -1,7 +1,7 @@
1
- require 'builder'
2
-
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_events_owner.rb', 'propfind_invite.rb', 'proppatch_principal.rb',
5
- 'proppatch_calendar.rb'].each do |f|
6
- require File.join( File.dirname(__FILE__), 'xml_request_builder', f )
7
- end
1
+ require 'builder'
2
+
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_events_owner.rb', 'propfind_invite.rb', 'proppatch_principal.rb',
5
+ 'proppatch_calendar.rb'].each do |f|
6
+ require File.join( File.dirname(__FILE__), 'xml_request_builder', f )
7
+ end
@@ -1,17 +1,17 @@
1
- module SabredavClient
2
- module XmlRequestBuilder
3
-
4
- NAMESPACE = {"xmlns:d" => 'DAV:'}
5
- C_NAMESPACES = {"xmlns:d" => 'DAV:', "xmlns:c" => "urn:ietf:params:xml:ns:caldav"}
6
- CS_NAMESPACES = {"xmlns:d" => 'DAV:', "xmlns:cs" => "http://calendarserver.org/ns/"}
7
- SB_NAMESPACES = {"xmlns:d" => 'DAV:', "xmlns:sb" => "http://sabredav.org/ns"}
8
-
9
- class Base
10
- def initialize
11
- @xml = Builder::XmlMarkup.new(indent: 2)
12
- @xml.instruct!
13
- end
14
- attr :xml
15
- end
16
- end
17
- end
1
+ module SabredavClient
2
+ module XmlRequestBuilder
3
+
4
+ NAMESPACE = {"xmlns:d" => 'DAV:'}
5
+ C_NAMESPACES = {"xmlns:d" => 'DAV:', "xmlns:c" => "urn:ietf:params:xml:ns:caldav"}
6
+ CS_NAMESPACES = {"xmlns:d" => 'DAV:', "xmlns:cs" => "http://calendarserver.org/ns/"}
7
+ SB_NAMESPACES = {"xmlns:d" => 'DAV:', "xmlns:sb" => "http://sabredav.org/ns"}
8
+
9
+ class Base
10
+ def initialize
11
+ @xml = Builder::XmlMarkup.new(indent: 2)
12
+ @xml.instruct!
13
+ end
14
+ attr :xml
15
+ end
16
+ end
17
+ end
@@ -1,25 +1,25 @@
1
- module SabredavClient
2
- module XmlRequestBuilder
3
-
4
- class Mkcalendar < Base
5
- attr_accessor :displayname, :description
6
-
7
- def initialize(displayname = nil, description = nil)
8
- @displayname = displayname
9
- @description = description
10
- super()
11
- end
12
-
13
- def to_xml
14
- xml.c :mkcalendar, C_NAMESPACES do
15
- xml.d :set do
16
- xml.d :prop do
17
- xml.d :displayname, displayname unless displayname.to_s.empty?
18
- xml.tag! "c:calendar-description", description, "xml:lang" => "en" unless description.to_s.empty?
19
- end
20
- end
21
- end
22
- end
23
- end
24
- end
25
- end
1
+ module SabredavClient
2
+ module XmlRequestBuilder
3
+
4
+ class Mkcalendar < Base
5
+ attr_accessor :displayname, :description
6
+
7
+ def initialize(displayname = nil, description = nil)
8
+ @displayname = displayname
9
+ @description = description
10
+ super()
11
+ end
12
+
13
+ def to_xml
14
+ xml.c :mkcalendar, C_NAMESPACES do
15
+ xml.d :set do
16
+ xml.d :prop do
17
+ xml.d :displayname, displayname unless displayname.to_s.empty?
18
+ xml.tag! "c:calendar-description", description, "xml:lang" => "en" unless description.to_s.empty?
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -1,28 +1,28 @@
1
- module SabredavClient
2
- module XmlRequestBuilder
3
-
4
- class MkcolPrincipal < 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 :mkcol, SB_NAMESPACES do
15
- xml.d :set do
16
- xml.d :prop do
17
- xml.d :resourcetype do
18
- xml.d :principal
19
- end
20
- xml.d :displayname, displayname unless displayname.to_s.empty?
21
- xml.tag! "sb:email-address", email
22
- end
23
- end
24
- end
25
- end
26
- end
27
- end
28
- end
1
+ module SabredavClient
2
+ module XmlRequestBuilder
3
+
4
+ class MkcolPrincipal < 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 :mkcol, SB_NAMESPACES do
15
+ xml.d :set do
16
+ xml.d :prop do
17
+ xml.d :resourcetype do
18
+ xml.d :principal
19
+ end
20
+ xml.d :displayname, displayname unless displayname.to_s.empty?
21
+ xml.tag! "sb:email-address", email
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -1,41 +1,41 @@
1
- module SabredavClient
2
- module XmlRequestBuilder
3
-
4
- class PostSharing < Base
5
- attr_accessor :adds, :removes, :summary, :privilege, :common_name
6
-
7
- def initialize(adds, summary, common_name, privilege, removes)
8
- @adds = adds
9
- @summary = summary
10
- @privilege = privilege
11
- @common_name = common_name
12
- @removes = removes
13
- super()
14
- end
15
-
16
- def to_xml
17
- xml.cs :share, CS_NAMESPACES do
18
- unless adds.empty?
19
- adds.each do |add|
20
- add = "mailto:#{add}"
21
- xml.cs :set do
22
- xml.d :href, add
23
- xml.cs :summary, summary unless summary.nil?
24
- xml.tag! "cs:common-name", common_name unless common_name.nil?
25
- xml.tag! "cs:#{privilege}"
26
- end
27
- end
28
- end
29
- unless removes.empty?
30
- removes.each do |remove|
31
- remove = "mailto:#{remove}"
32
- xml.cs :remove do
33
- xml.d :href, remove
34
- end
35
- end
36
- end
37
- end
38
- end
39
- end
40
- end
41
- end
1
+ module SabredavClient
2
+ module XmlRequestBuilder
3
+
4
+ class PostSharing < Base
5
+ attr_accessor :adds, :removes, :summary, :privilege, :common_name
6
+
7
+ def initialize(adds, summary, common_name, privilege, removes)
8
+ @adds = adds
9
+ @summary = summary
10
+ @privilege = privilege
11
+ @common_name = common_name
12
+ @removes = removes
13
+ super()
14
+ end
15
+
16
+ def to_xml
17
+ xml.cs :share, CS_NAMESPACES do
18
+ unless adds.empty?
19
+ adds.each do |add|
20
+ add = "mailto:#{add}"
21
+ xml.cs :set do
22
+ xml.d :href, add
23
+ xml.cs :summary, summary unless summary.nil?
24
+ xml.tag! "cs:common-name", common_name unless common_name.nil?
25
+ xml.tag! "cs:#{privilege}"
26
+ end
27
+ end
28
+ end
29
+ unless removes.empty?
30
+ removes.each do |remove|
31
+ remove = "mailto:#{remove}"
32
+ xml.cs :remove do
33
+ xml.d :href, remove
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -1,41 +1,41 @@
1
- module SabredavClient
2
- module XmlRequestBuilder
3
- class PROPFINDCalendar < Base
4
- attr_reader :properties
5
-
6
- PROPERTIES = {
7
- displayname: :d,
8
- getctag: :cs,
9
- sync_token: :d
10
- }
11
-
12
- def initialize(properties:)
13
- @properties = properties
14
- super()
15
- end
16
-
17
- def to_xml
18
- xml.d :propfind, CS_NAMESPACES do
19
- xml.d :prop do
20
- build_properties
21
- end
22
- end
23
- end
24
-
25
- def build_properties
26
- properties.each do |property|
27
- raise SabredavClient::Errors::PropertyNotSupportedError, "Known properties are #{PROPERTIES}" unless PROPERTIES.keys.include?(property)
28
-
29
- readable_property = property.to_s.gsub('_', '-').to_sym
30
-
31
- case PROPERTIES[property]
32
- when :d
33
- xml.d readable_property
34
- when :cs
35
- xml.cs readable_property
36
- end
37
- end
38
- end
39
- end
40
- end
41
- end
1
+ module SabredavClient
2
+ module XmlRequestBuilder
3
+ class PROPFINDCalendar < Base
4
+ attr_reader :properties
5
+
6
+ PROPERTIES = {
7
+ displayname: :d,
8
+ getctag: :cs,
9
+ sync_token: :d
10
+ }
11
+
12
+ def initialize(properties:)
13
+ @properties = properties
14
+ super()
15
+ end
16
+
17
+ def to_xml
18
+ xml.d :propfind, CS_NAMESPACES do
19
+ xml.d :prop do
20
+ build_properties
21
+ end
22
+ end
23
+ end
24
+
25
+ def build_properties
26
+ properties.each do |property|
27
+ raise SabredavClient::Errors::PropertyNotSupportedError, "Known properties are #{PROPERTIES}" unless PROPERTIES.keys.include?(property)
28
+
29
+ readable_property = property.to_s.gsub('_', '-').to_sym
30
+
31
+ case PROPERTIES[property]
32
+ when :d
33
+ xml.d readable_property
34
+ when :cs
35
+ xml.cs readable_property
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end