yandex-disk 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/yandex/disk/backup/storage.rb +1 -1
- data/lib/yandex/disk/client.rb +86 -51
- data/lib/yandex/disk/version.rb +1 -1
- data/test/yandex_dist_test.rb +23 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 57ed5ceebc98623641748f8f16b410c8b66118c4
|
4
|
+
data.tar.gz: c832f15ada10ebdbb3c770138d34941a25c6e518
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f592e2c576488414f639f3985ece832deac747078e47f30987f562556027b9faa7e7094eeb55e3d9a0a287d68dc53a60ccc13cf17c2865a30b689fd479cae910
|
7
|
+
data.tar.gz: fc156a49408e7235bda13f34c566235df523acef5a6bbda78bcad32890c7a2c9d6bbd149e7941623c28d1edab4ff8283c66cd98930db2482bdec0d05c4aebaae
|
data/lib/yandex/disk/client.rb
CHANGED
@@ -7,77 +7,112 @@ module Yandex
|
|
7
7
|
module Disk
|
8
8
|
class Client
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
def initialize options={}
|
11
|
+
@http = Faraday.new(:url => 'https://webdav.yandex.ru') do |builder|
|
12
|
+
builder.request :authorization, "OAuth", options[:access_token]
|
13
13
|
|
14
|
-
|
14
|
+
builder.response :follow_redirects
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
16
|
+
if faraday_configurator = options[:faraday_configurator]
|
17
|
+
faraday_configurator.call(builder)
|
18
|
+
else
|
19
|
+
builder.adapter :excon
|
20
|
+
end
|
20
21
|
end
|
21
22
|
end
|
22
|
-
end
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
req.url dest
|
27
|
-
req.headers['Content-Type'] = 'application/binary'
|
28
|
-
req.body = File.open(src)
|
24
|
+
def put src, dest
|
25
|
+
put_response(src, dest).success?
|
29
26
|
end
|
30
|
-
res.success?
|
31
|
-
end
|
32
27
|
|
33
|
-
|
34
|
-
|
35
|
-
|
28
|
+
def put! src, dest
|
29
|
+
res = put_response(src, dest)
|
30
|
+
raise res.body unless res.success?
|
36
31
|
end
|
37
32
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
end
|
33
|
+
def mkcol path
|
34
|
+
mkcol_response(path).success?
|
35
|
+
end
|
42
36
|
|
43
|
-
|
37
|
+
def mkcol!
|
38
|
+
res = mkcol_response(path)
|
39
|
+
raise res.body unless res.success?
|
40
|
+
end
|
44
41
|
|
45
|
-
|
46
|
-
|
47
|
-
path.split('/').each do |part|
|
48
|
-
path_parts << part
|
49
|
-
mkdir(path_parts.join('/'))
|
42
|
+
def get path
|
43
|
+
@http.get(path)
|
50
44
|
end
|
51
|
-
end
|
52
45
|
|
53
|
-
|
54
|
-
@http.get(path)
|
55
|
-
end
|
46
|
+
alias_method :mkdir, :mkcol
|
56
47
|
|
57
|
-
|
58
|
-
|
59
|
-
|
48
|
+
def mkdir_p path
|
49
|
+
path_parts = []
|
50
|
+
path.split('/').each do |part|
|
51
|
+
path_parts << part
|
52
|
+
mkdir(path_parts.join('/'))
|
53
|
+
end
|
54
|
+
end
|
60
55
|
|
61
|
-
|
62
|
-
|
63
|
-
|
56
|
+
def copy src, dest
|
57
|
+
file_operation_response('COPY', src, dest).success?
|
58
|
+
end
|
64
59
|
|
65
|
-
|
66
|
-
|
67
|
-
|
60
|
+
def copy! src, dest
|
61
|
+
res = file_operation_response('COPY', src, dest)
|
62
|
+
raise res.body unless res.success?
|
63
|
+
end
|
64
|
+
|
65
|
+
def move src, dest
|
66
|
+
file_operation_response('MOVE', src, dest).success?
|
67
|
+
end
|
68
68
|
|
69
|
-
|
69
|
+
def move! src, dest
|
70
|
+
res = file_operation_response('MOVE', src, dest)
|
71
|
+
raise res.body unless res.success?
|
72
|
+
end
|
70
73
|
|
71
|
-
|
72
|
-
|
73
|
-
req.url(path)
|
74
|
-
req.headers['Destination'] = dest
|
74
|
+
def delete path
|
75
|
+
delete_response(path).success?
|
75
76
|
end
|
76
77
|
|
77
|
-
|
78
|
-
|
79
|
-
|
78
|
+
def delete! path
|
79
|
+
res = delete_response(path)
|
80
|
+
raise res.body unless res.success?
|
81
|
+
end
|
82
|
+
|
83
|
+
private
|
84
|
+
|
85
|
+
def put_response src, dest
|
86
|
+
@http.put do |req|
|
87
|
+
req.url dest
|
88
|
+
req.headers['Content-Type'] = 'application/binary'
|
89
|
+
req.body = File.open(src)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def mkcol_response path
|
94
|
+
request = @http.build_request('MKCOL') do |req|
|
95
|
+
req.url(path)
|
96
|
+
end
|
97
|
+
|
98
|
+
env = request.to_env(@http)
|
99
|
+
@http.app.call(env)
|
100
|
+
end
|
101
|
+
|
102
|
+
def file_operation_response op, src, dest
|
103
|
+
request = @http.build_request(op) do |req|
|
104
|
+
req.url(path)
|
105
|
+
req.headers['Destination'] = dest
|
106
|
+
end
|
107
|
+
|
108
|
+
env = request.to_env(@http)
|
109
|
+
res = @http.app.call(env)
|
110
|
+
res.success?
|
111
|
+
end
|
112
|
+
|
113
|
+
def delete_response path
|
114
|
+
@http.delete(path)
|
115
|
+
end
|
80
116
|
end
|
81
117
|
end
|
82
|
-
end
|
83
118
|
end
|
data/lib/yandex/disk/version.rb
CHANGED
data/test/yandex_dist_test.rb
CHANGED
@@ -17,6 +17,17 @@ class YandexDiskTest < MiniTest::Unit::TestCase
|
|
17
17
|
assert_equal File.read('README.md'), remote.body
|
18
18
|
end
|
19
19
|
|
20
|
+
def test_put!
|
21
|
+
assert_raises RuntimeError do
|
22
|
+
begin
|
23
|
+
@disk.put!('README.md', '/folder/that/doesnt/exists/README.md')
|
24
|
+
rescue RuntimeError => e
|
25
|
+
assert_equal 'store: parent folder was not found', e.message
|
26
|
+
raise e
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
20
31
|
def test_delete_and_mkdir
|
21
32
|
@disk.delete('/a')
|
22
33
|
assert !@disk.mkdir('/a/b')
|
@@ -25,6 +36,18 @@ class YandexDiskTest < MiniTest::Unit::TestCase
|
|
25
36
|
assert @disk.delete('/a')
|
26
37
|
end
|
27
38
|
|
39
|
+
def test_delete!
|
40
|
+
@disk.delete('/a')
|
41
|
+
assert_raises RuntimeError do
|
42
|
+
begin
|
43
|
+
@disk.delete!('/a')
|
44
|
+
rescue RuntimeError => e
|
45
|
+
assert_equal 'resource not found', e.message
|
46
|
+
raise e
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
28
51
|
def test_put_in_nested_folder
|
29
52
|
assert !@disk.put('README.md', '/new_folder/README.md')
|
30
53
|
end
|