Class: YandexClient::Dav
Overview
tech.yandex.ru/disk/doc/dg/reference/put-docpage/
Chainable client:
YandexClient::Dav
.put('1.txt', '/a/b/c/1.txt')
.put(File.open('1.txt', 'rb'), '/path/to/1.txt')
.put(Tempfile.new.tap { |t| t.write('say ni'); t.rewind }, '/path/to/tmp.txt')
.delete('/a/b/c/1.txt')
.mkcol('/a/b/c')
.propfind('/a/dip.yml', depth: 0)
.propfind('/a', depth: 1)
.propfind.to_a
Defined Under Namespace
Classes: PropFindResponse
Constant Summary
collapse
- ACTION_URL =
'https://webdav.yandex.ru'
- PROPFIND_QUERY =
'<?xml version="1.0" encoding="utf-8"?><propfind xmlns="DAV:"></propfind>'
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
included
Constructor Details
#initialize(token) ⇒ Dav
Returns a new instance of Dav.
38
39
40
|
# File 'lib/yandex_client/dav.rb', line 38
def initialize(token)
@token = token
end
|
Instance Attribute Details
#token ⇒ Object
Returns the value of attribute token.
28
29
30
|
# File 'lib/yandex_client/dav.rb', line 28
def token
@token
end
|
Class Method Details
.with_token(token) ⇒ Object
Also known as:
[]
31
32
33
|
# File 'lib/yandex_client/dav.rb', line 31
def with_token(token)
new(token)
end
|
Instance Method Details
#delete(dest) ⇒ Object
55
56
57
58
59
60
|
# File 'lib/yandex_client/dav.rb', line 55
def delete(dest)
process_response with_config.delete(
url_for(dest),
headers:
)
end
|
#mkcol(dest) ⇒ Object
62
63
64
65
66
67
68
|
# File 'lib/yandex_client/dav.rb', line 62
def mkcol(dest)
process_response with_config.request(
:mkcol,
url_for(dest),
headers:
)
end
|
#move(source, dest, overwrite: false) ⇒ Object
71
72
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/yandex_client/dav.rb', line 71
def move(source, dest, overwrite: false)
= .merge!(
'Destination' => absolute_path(dest),
'Overwrite' => overwrite ? 'T' : 'F'
)
process_response with_config.request(
:move,
url_for(source),
headers:
)
end
|
#propfind(dest = '', depth = 1) ⇒ Object
84
85
86
87
88
89
90
91
92
93
94
95
|
# File 'lib/yandex_client/dav.rb', line 84
def propfind(dest = '', depth = 1)
= .merge!(
Depth: depth.to_s,
'Content-Type' => 'application/x-www-form-urlencoded',
'Content-Length' => PROPFIND_QUERY.length
)
response = with_config.request(:propfind, url_for(dest), headers: , body: PROPFIND_QUERY)
process_response(response)
PropFindResponse.new(response.body.to_s)
end
|
#put(file, dest, etag: nil, sha256: nil, size: nil) ⇒ Object
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/yandex_client/dav.rb', line 42
def put(file, dest, etag: nil, sha256: nil, size: nil)
io = file.is_a?(String) ? File.open(file, 'rb') : file
= .merge!(
'Etag' => etag || Digest::MD5.file(io.path),
'Sha256' => sha256 || Digest::SHA256.file(io.path),
'Expect' => '100-continue',
'Content-Length' => (size || File.size(io.path)).to_s
)
process_response with_config.put(url_for(dest), body: io, headers: )
end
|