From 1023029663906bce26f78819db4028ce548ac11c Mon Sep 17 00:00:00 2001 From: Brandon Robins Date: Tue, 24 Oct 2017 22:41:10 -0500 Subject: [PATCH] Add Resource class --- lib/calligraphy.rb | 2 + lib/calligraphy/resource.rb | 97 +++++++++++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+) create mode 100644 lib/calligraphy/resource.rb diff --git a/lib/calligraphy.rb b/lib/calligraphy.rb index 1e8b516..dd9d2d4 100644 --- a/lib/calligraphy.rb +++ b/lib/calligraphy.rb @@ -6,6 +6,8 @@ require 'calligraphy/xml/namespace' require 'calligraphy/xml/node' require 'calligraphy/xml/utils' +require 'calligraphy/resource' + require 'calligraphy/web_dav_request' module Calligraphy diff --git a/lib/calligraphy/resource.rb b/lib/calligraphy/resource.rb new file mode 100644 index 0000000..62bdc4b --- /dev/null +++ b/lib/calligraphy/resource.rb @@ -0,0 +1,97 @@ +module Calligraphy + class Resource + attr_accessor :contents + + attr_reader :full_request_path + attr_reader :mount_point + attr_reader :request_body + attr_reader :request_path + + def initialize(resource: nil, req: nil, mount: nil) + @full_request_path = req&.original_url + @mount_point = mount || req&.path&.tap { |s| s.slice! resource } + @request_body = req&.body&.read || '' + @request_path = mount.nil? ? resource : resource.split(mount)[-1] + end + + def ancestor_exist? + raise NotImplemented + end + + def can_copy?(options) + raise NotImplemented + end + + def collection? + raise NotImplemented + end + + def copy(options) + raise NotImplemented + end + + def create_collection + raise NotImplemented + end + + def delete_collection + raise NotImplemented + end + + def etag + raise NotImplemented + end + + def exists? + raise NotImplemented + end + + def lock(nodes, depth='infinity') + raise NotImplemented + end + + def lock_is_exclusive? + raise NotImplemented + end + + def lock_tokens + raise NotImplemented + end + + def locked? + raise NotImplemented + end + + def locked_to_user?(headers=nil) + raise NotImplemented + end + + def propfind(nodes) + raise NotImplemented + end + + def proppatch(nodes) + raise NotImplemented + end + + def read + raise NotImplemented + end + + def readable? + exists? && !collection? + end + + def refresh_lock + raise NotImplemented + end + + def unlock(token) + raise NotImplemented + end + + def write(contents=@request_body.to_s) + raise NotImplemented + end + end +end