Created
August 28, 2015 10:19
-
-
Save testzugang/6aa0b43b47d9b49e0bbf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'net/dav' | |
class WebDavWorker | |
attr_reader :uri, :username, :password, :errors | |
attr_accessor :connection | |
def self.connect_to_uri uri, username, password | |
worker = WebDavWorker.new(uri, username, password) | |
begin | |
connection = Net::DAV.new(uri) | |
connection.verify_server = false | |
connection.credentials(username, password) | |
connection.find('.') { } | |
worker.connection = connection | |
rescue Exception => e | |
worker.connection = nil | |
worker.errors << e.message | |
end | |
worker | |
end | |
def get dataroom, filename | |
@errors = [] | |
if @connection | |
begin | |
path = [dataroom, filename].reject(&:empty?).join(File::Separator) | |
@connection.get(path) | |
rescue Exception => e | |
@errors << e.message | |
nil | |
end | |
else | |
@errors << "No connection" | |
nil | |
end | |
end | |
def verify_path path | |
@errors = [] | |
if @connection | |
begin | |
return @connection.exists?(path) | |
rescue Exception => e | |
@errors << e.message | |
end | |
else | |
@errors << "No connection" | |
end | |
FALSE | |
end | |
private | |
def initialize uri, username, password | |
@uri = uri | |
@username = username | |
@password = password | |
@errors = [] | |
@connection = nil | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment