webdav-client 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +3 -0
- data/lib/net/webdav/client.rb +78 -0
- data/lib/net/webdav/version.rb +5 -0
- data/webdav-client.gemspec +25 -0
- metadata +117 -0
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Nikita Vorobej
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'curb'
|
3
|
+
|
4
|
+
|
5
|
+
module Net
|
6
|
+
module Webdav
|
7
|
+
class Client
|
8
|
+
attr_reader :host, :username, :password, :url, :http_auth_types
|
9
|
+
|
10
|
+
def initialize url, options = {}
|
11
|
+
scheme, userinfo, hostname, port, registry, path, opaque, query, fragment = URI.split(url)
|
12
|
+
@host = "#{scheme}://#{hostname}#{port.nil? ? "" : ":" + port}"
|
13
|
+
@http_auth_types = options[:http_auth_types] || :basic
|
14
|
+
|
15
|
+
unless userinfo.nil?
|
16
|
+
@username, @password = userinfo.split(':')
|
17
|
+
else
|
18
|
+
@username = options[:username]
|
19
|
+
@password = options[:password]
|
20
|
+
end
|
21
|
+
|
22
|
+
@url = URI.join(@host, path)
|
23
|
+
end
|
24
|
+
|
25
|
+
def file_exists? path
|
26
|
+
response = Curl::Easy.http_head full_url(path)
|
27
|
+
response.response_code >= 200 && response.response_code <= 209
|
28
|
+
end
|
29
|
+
|
30
|
+
def get_file remote_file_path, local_file_path
|
31
|
+
Curl::Easy.download full_url(remote_file_path), local_file_path
|
32
|
+
end
|
33
|
+
|
34
|
+
def put_file path, file, create_path = false
|
35
|
+
response = Curl::Easy.http_put full_url(path), file, &method(:auth)
|
36
|
+
|
37
|
+
if create_path and response.response_code == 409 # conflict; parent path doesn't exist, try to create recursively
|
38
|
+
scheme, userinfo, hostname, port, registry, path, opaque, query, fragment = URI.split(full_url(path))
|
39
|
+
path_parts = path.split('/').reject {|s| s.nil? || s.empty?}
|
40
|
+
|
41
|
+
for i in 0..(path_parts.length - 2)
|
42
|
+
parent_path = path_parts[0..i].join('/')
|
43
|
+
url = URI.join("#{scheme}://#{hostname}#{(port.nil? || port == 80) ? "" : ":" + port}/", parent_path)
|
44
|
+
response = make_directory(url)
|
45
|
+
return response unless response.response_code == 201 || response.response_code == 405 # 201 Created or 405 Conflict (already exists)
|
46
|
+
end
|
47
|
+
|
48
|
+
response = Curl::Easy.http_put full_url(path), file, &method(:auth)
|
49
|
+
end
|
50
|
+
|
51
|
+
raise response.status unless (response.response_code == 201 || response.response_code == 204)
|
52
|
+
response
|
53
|
+
end
|
54
|
+
|
55
|
+
def delete_file path
|
56
|
+
Curl::Easy.http_delete full_url(path), &method(:auth)
|
57
|
+
end
|
58
|
+
|
59
|
+
def make_directory path
|
60
|
+
curl = Curl::Easy.new(full_url(path))
|
61
|
+
auth(curl)
|
62
|
+
curl.http(:MKCOL)
|
63
|
+
curl
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
def auth curl
|
68
|
+
curl.username = @username unless @username.nil?
|
69
|
+
curl.password = @password unless @password.nil?
|
70
|
+
curl.http_auth_types = @http_auth_types unless @http_auth_types.nil?
|
71
|
+
end
|
72
|
+
|
73
|
+
def full_url path
|
74
|
+
URI.join(@url, path).to_s
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'net/webdav/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "webdav-client"
|
8
|
+
gem.version = Net::Webdav::VERSION
|
9
|
+
gem.authors = ["Tom Canham"]
|
10
|
+
gem.email = ["alphasimian@gmail.com"]
|
11
|
+
gem.description = %q{Webdav client}
|
12
|
+
gem.summary = %q{Webdav client}
|
13
|
+
gem.homepage = "https://github.com/ETBD/webdav-client"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_dependency "curb"
|
21
|
+
|
22
|
+
gem.add_development_dependency "rspec"
|
23
|
+
gem.add_development_dependency "guard-rspec"
|
24
|
+
gem.add_development_dependency "rake"
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: webdav-client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Tom Canham
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-04-08 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: curb
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rspec
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: guard-rspec
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rake
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
description: Webdav client
|
79
|
+
email:
|
80
|
+
- alphasimian@gmail.com
|
81
|
+
executables: []
|
82
|
+
extensions: []
|
83
|
+
extra_rdoc_files: []
|
84
|
+
files:
|
85
|
+
- .gitignore
|
86
|
+
- .travis.yml
|
87
|
+
- Gemfile
|
88
|
+
- LICENSE.txt
|
89
|
+
- README.md
|
90
|
+
- lib/net/webdav/client.rb
|
91
|
+
- lib/net/webdav/version.rb
|
92
|
+
- webdav-client.gemspec
|
93
|
+
homepage: https://github.com/ETBD/webdav-client
|
94
|
+
licenses: []
|
95
|
+
post_install_message:
|
96
|
+
rdoc_options: []
|
97
|
+
require_paths:
|
98
|
+
- lib
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
+
none: false
|
101
|
+
requirements:
|
102
|
+
- - ! '>='
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
|
+
none: false
|
107
|
+
requirements:
|
108
|
+
- - ! '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
requirements: []
|
112
|
+
rubyforge_project:
|
113
|
+
rubygems_version: 1.8.24
|
114
|
+
signing_key:
|
115
|
+
specification_version: 3
|
116
|
+
summary: Webdav client
|
117
|
+
test_files: []
|