class Ocman::Dav

Attributes

connection[W]

Public Class Methods

base_uri() click to toggle source
# File lib/ocman/dav.rb, line 33
def self.base_uri
  Ocman.configuration.dav_base_uri || '/remote.php/webdav/'
end
url(path) click to toggle source
# File lib/ocman/dav.rb, line 37
def self.url(path)
  Ocman.configuration.base_url + (Ocman::Dav.base_uri + path).gsub(%r{/+}, '/')
end

Public Instance Methods

delete(path) click to toggle source
# File lib/ocman/dav.rb, line 25
def delete(path)
  connection.delete(uri(path))
end
ls(path, options = {}, &block) click to toggle source
# File lib/ocman/dav.rb, line 14
def ls(path, options = {}, &block)
  connection.find(uri(path), options, &block)
end
mkdir(path) click to toggle source
# File lib/ocman/dav.rb, line 10
def mkdir(path)
  connection.mkdir(uri(path))
end
move(source_path, destination_path) click to toggle source
# File lib/ocman/dav.rb, line 29
def move(source_path, destination_path)
  connection.move(uri(source_path), uri(destination_path))
end
put(file_path, path, options = {}) click to toggle source
# File lib/ocman/dav.rb, line 18
def put(file_path, path, options = {})
  filename = options[:filename] || File.basename(file_path)
  File.open(file_path, 'r') do |stream|
    connection.put(uri(path, filename), stream, File.size(file_path))
  end
end

Private Instance Methods

connection() click to toggle source
# File lib/ocman/dav.rb, line 56
def connection
  dav = Net::DAV.new(Ocman.configuration.base_url)
  dav.verify_server = true
  dav.credentials(Ocman.configuration.user_name, Ocman.configuration.password)
  dav
end
item_hash(item) click to toggle source
# File lib/ocman/dav.rb, line 43
def item_hash(item)
  {
    path: item.uri.path.gsub(Ocman::Dav.base_uri, '/'),
    type: item.type,
    size: item.size
  }
end
uri(path, filename = nil) click to toggle source
# File lib/ocman/dav.rb, line 51
def uri(path, filename = nil)
  filename = CGI.escape(filename) if filename
  [Ocman::Dav.base_uri, path, filename].compact.join('/').gsub(%r{/+}, '/')
end