yandex_disk 1.1.2 → 1.1.3
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/api.rb +62 -58
- data/lib/yandex_disk/cfg.rb +1 -1
- data/spec/spec_helper.rb +18 -2
- data/spec/yandex_disk_spec.rb +72 -61
- metadata +26 -14
- data/spec/files/README +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fcd90ff877dff1f9ba39c538cc228afd5339b91a
|
4
|
+
data.tar.gz: c8bfaefc0d556bbaeca172978028b0bdeab0261f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 43c252cc77324eeb9ce358a6b767fdb450d329aa714afdde7a3428dfe1cc37117499b375cbe225e91d96b80599e52520e045bc621dd55bb05f0d65c8664a4d3c
|
7
|
+
data.tar.gz: 5c212a92e6b578082006623796c1648a1716dabb14625a1bf5350935847a79c6b00df7579ef5aa23876227802b7766385f285d711e8c4ebd1564925ee53f4b1b
|
data/lib/yandex_disk/api.rb
CHANGED
@@ -11,6 +11,7 @@ require 'yandex_disk/chunked'
|
|
11
11
|
|
12
12
|
module YandexDisk
|
13
13
|
class RequestError < Exception; end
|
14
|
+
class BadFormat < Exception; end
|
14
15
|
|
15
16
|
class Api
|
16
17
|
|
@@ -24,7 +25,7 @@ module YandexDisk
|
|
24
25
|
#
|
25
26
|
# Arguments:
|
26
27
|
# file: path to file
|
27
|
-
# path: path to yandex disk directory
|
28
|
+
# path: path to yandex disk directory. If path not present - save to root
|
28
29
|
# options:
|
29
30
|
# chunk_size: file chunk size (default is 100)
|
30
31
|
# force: create path structure if not exist (raise <b>RequestError</b> if <b>path</b> not exist for default)
|
@@ -46,30 +47,33 @@ module YandexDisk
|
|
46
47
|
|
47
48
|
# Example:
|
48
49
|
# yd.download('/home/graph.pdf', '/home')
|
49
|
-
# => true
|
50
|
+
# => true (or file content)
|
50
51
|
#
|
51
52
|
# Arguments:
|
52
53
|
# file: path to yandex disk file
|
53
|
-
# save_path: path to save
|
54
|
-
def download(file, save_path)
|
54
|
+
# save_path: path to save. If save_path not present - return file content
|
55
|
+
def download(file, save_path = nil)
|
55
56
|
option = {:path => file,
|
56
57
|
:headers => {'TE' => 'chunked',
|
57
58
|
'Accept-Encoding' => 'gzip'}}
|
58
59
|
|
59
60
|
send_request(:get, option)
|
60
61
|
|
61
|
-
data = nil
|
62
62
|
# unzip if zipped
|
63
|
-
if @response.header['Content-Encoding']
|
63
|
+
if gzip?(@response.header['Content-Encoding'])
|
64
64
|
s_io = StringIO.new(@response.body)
|
65
65
|
gz = Zlib::GzipReader.new(s_io)
|
66
66
|
data = gz.read
|
67
67
|
else
|
68
68
|
data = @response.body
|
69
69
|
end
|
70
|
-
File.open(File.join(save_path, file.split('/').last), 'w'){|f| f.write(data)}
|
71
70
|
|
72
|
-
|
71
|
+
if save_path
|
72
|
+
File.open(File.join(save_path, file.split('/').last), 'w'){|f| f.write(data)}
|
73
|
+
return true
|
74
|
+
else
|
75
|
+
return data
|
76
|
+
end
|
73
77
|
end
|
74
78
|
|
75
79
|
# Example:
|
@@ -83,7 +87,7 @@ module YandexDisk
|
|
83
87
|
path.split('/').each do |p|
|
84
88
|
next if p.empty?
|
85
89
|
c_path << p + '/'
|
86
|
-
send_request(:mkcol,
|
90
|
+
send_request(:mkcol, :path => c_path)
|
87
91
|
end
|
88
92
|
end
|
89
93
|
alias_method :mkdir, :create_path
|
@@ -96,7 +100,7 @@ module YandexDisk
|
|
96
100
|
# readable: return size in human readable format e.g, 100K 128M 1G (false for default)
|
97
101
|
def size(options = {})
|
98
102
|
body = '<?xml version="1.0" encoding="utf-8"?><D:propfind xmlns:D="DAV:"><D:prop><D:quota-available-bytes/><D:quota-used-bytes/></D:prop></D:propfind>'
|
99
|
-
send_propfind(0,
|
103
|
+
send_propfind(0, :body => body)
|
100
104
|
xml = REXML::Document.new(@response.body)
|
101
105
|
prop = 'd:multistatus/d:response/d:propstat/d:prop/'
|
102
106
|
available_b = xml.elements[prop + 'd:quota-available-bytes'].text.to_i
|
@@ -114,8 +118,7 @@ module YandexDisk
|
|
114
118
|
# path: path to yandex disk directory or file
|
115
119
|
def exist?(path)
|
116
120
|
body = '<?xml version="1.0" encoding="utf-8"?><propfind xmlns="DAV:"><prop><displayname/></prop></propfind>'
|
117
|
-
send_propfind(0,
|
118
|
-
return true
|
121
|
+
send_propfind(0, :path => path, :body => body)
|
119
122
|
rescue RequestError
|
120
123
|
return false
|
121
124
|
end
|
@@ -136,7 +139,7 @@ module YandexDisk
|
|
136
139
|
# h_size: return size in human readable format e.g, 100K 128M 1G (false for default)
|
137
140
|
def properties(path, options = {})
|
138
141
|
body = '<?xml version="1.0" encoding="utf-8"?><propfind xmlns="DAV:"><prop><displayname/><creationdate/><getlastmodified/><getcontenttype/><getcontentlength/><public_url xmlns="urn:yandex:disk:meta"/></prop></propfind>'
|
139
|
-
send_propfind(0,
|
142
|
+
send_propfind(0, :path => path, :body => body)
|
140
143
|
prop = 'd:multistatus/d:response/d:propstat/d:prop/'
|
141
144
|
xml = REXML::Document.new(@response.body)
|
142
145
|
type = xml.elements[prop + 'd:getcontenttype'].text
|
@@ -166,14 +169,14 @@ module YandexDisk
|
|
166
169
|
# root: include information of root directory or not (<b>false</b> for default)
|
167
170
|
# h_size: return size in human readable format e.g, 100K 128M 1G (false for default)
|
168
171
|
def files(path = '', options = {})
|
169
|
-
send_propfind(1,
|
172
|
+
send_propfind(1, :path => path)
|
170
173
|
xml = REXML::Document.new(@response.body)
|
171
174
|
prop = 'd:propstat/d:prop/'
|
172
175
|
files = []
|
173
176
|
xml.elements.each('d:multistatus/d:response') do |res|
|
174
177
|
name = URI.decode(res.elements[prop + 'd:displayname'].text)
|
175
178
|
next if !options[:root] && path.split('/').last == name
|
176
|
-
size = res.elements[prop + 'd:getcontentlength'].text.to_i
|
179
|
+
size = res.elements[prop + 'd:getcontentlength'].text.to_i rescue 0
|
177
180
|
|
178
181
|
files << {:name => name,
|
179
182
|
:path => URI.decode(res.elements['d:href'].text),
|
@@ -217,7 +220,7 @@ module YandexDisk
|
|
217
220
|
# Arguments:
|
218
221
|
# path: path to yandex disk directory or file
|
219
222
|
def delete(path)
|
220
|
-
send_request(:delete,
|
223
|
+
send_request(:delete, :path => path)
|
221
224
|
end
|
222
225
|
alias_method :del, :delete
|
223
226
|
|
@@ -229,7 +232,7 @@ module YandexDisk
|
|
229
232
|
# path: path to yandex disk directory or file
|
230
233
|
def set_public(path)
|
231
234
|
body = '<propertyupdate xmlns="DAV:"><set><prop><public_url xmlns="urn:yandex:disk:meta">true</public_url></prop></set></propertyupdate>'
|
232
|
-
send_request(:proppatch,
|
235
|
+
send_request(:proppatch, :path => path, :body => body)
|
233
236
|
xml = REXML::Document.new(@response.body)
|
234
237
|
return xml.elements['d:multistatus/d:response/d:propstat/d:prop/public_url'].text
|
235
238
|
end
|
@@ -242,7 +245,7 @@ module YandexDisk
|
|
242
245
|
# path: path to yandex disk directory or file
|
243
246
|
def set_private(path)
|
244
247
|
body = '<propertyupdate xmlns="DAV:"><remove><prop><public_url xmlns="urn:yandex:disk:meta" /></prop></remove></propertyupdate>'
|
245
|
-
send_request(:proppatch,
|
248
|
+
send_request(:proppatch, :path => path, :body => body)
|
246
249
|
xml = REXML::Document.new(@response.body)
|
247
250
|
return xml.elements['d:multistatus/d:response/d:propstat/d:prop/public_url'].text.nil?
|
248
251
|
end
|
@@ -256,22 +259,54 @@ module YandexDisk
|
|
256
259
|
# size: preview size (for details visit http://api.yandex.com/disk/doc/dg/reference/preview.xml)
|
257
260
|
# save_to: path to save
|
258
261
|
def preview(path, size, save_to)
|
259
|
-
send_request(:get,
|
262
|
+
send_request(:get, :path => path, :preview => size.to_s)
|
260
263
|
File.open(File.join(save_to, path.split('/').last), 'w'){|f| f.write(@response.body)}
|
261
264
|
end
|
262
265
|
|
263
266
|
########## private ##########
|
264
267
|
private
|
265
268
|
|
269
|
+
def gzip?(type)
|
270
|
+
type == 'gzip'
|
271
|
+
end
|
272
|
+
|
266
273
|
def create_dest(from, to)
|
267
274
|
prop = properties(from)
|
268
275
|
to = prop[:is_file] ? to.gsub(/\/$/,'') + '/' + prop[:name] : to
|
269
276
|
return '/' + to
|
270
277
|
end
|
271
278
|
|
279
|
+
def request_path(path, preview)
|
280
|
+
if path.blank?
|
281
|
+
return ''
|
282
|
+
else
|
283
|
+
path = URI.encode( path.split('/').reject{|it| it.blank?}.join('/') )
|
284
|
+
raise Exception if path.empty?
|
285
|
+
# image preview
|
286
|
+
path << "?preview&size=#{preview}" if preview
|
287
|
+
return path
|
288
|
+
end
|
289
|
+
rescue Exception
|
290
|
+
raise BadFormat, 'Path has bad format.'
|
291
|
+
end
|
292
|
+
|
293
|
+
def init_request(method)
|
294
|
+
case method
|
295
|
+
when :put then Net::HTTP::Put
|
296
|
+
when :get then Net::HTTP::Get
|
297
|
+
when :mkcol then Net::HTTP::Mkcol
|
298
|
+
when :propfind then Net::HTTP::Propfind
|
299
|
+
when :copy then Net::HTTP::Copy
|
300
|
+
when :move then Net::HTTP::Move
|
301
|
+
when :delete then Net::HTTP::Delete
|
302
|
+
when :proppatch then Net::HTTP::Proppatch
|
303
|
+
else raise RequestError, "Method #{method} not supported."
|
304
|
+
end
|
305
|
+
end
|
306
|
+
|
272
307
|
def move_copy(method, from, to)
|
273
|
-
send_request(method,
|
274
|
-
|
308
|
+
send_request(method, :path => from,
|
309
|
+
:headers => {'Destination' => create_dest(from, to)})
|
275
310
|
end
|
276
311
|
|
277
312
|
def send_propfind(depth, options = {})
|
@@ -288,18 +323,7 @@ module YandexDisk
|
|
288
323
|
headers.merge!(args[:headers]) if args[:headers]
|
289
324
|
uri = URI.parse(YandexDisk::API_URL)
|
290
325
|
# path
|
291
|
-
path =
|
292
|
-
begin
|
293
|
-
unless args[:path].blank?
|
294
|
-
path = URI.encode( args[:path].split('/').reject{|it| it.blank?}.join('/') )
|
295
|
-
raise Exception if path.empty?
|
296
|
-
# image preview
|
297
|
-
path << "?preview&size=#{args[:preview]}" if args[:preview]
|
298
|
-
end
|
299
|
-
rescue Exception => e
|
300
|
-
raise RequestError, 'Path has bad format.'
|
301
|
-
end
|
302
|
-
request_path = uri.request_uri + path
|
326
|
+
path = uri.request_uri + request_path(args[:path], args[:preview])
|
303
327
|
# init
|
304
328
|
http = Net::HTTP.new(uri.host, uri.port)
|
305
329
|
# ssl
|
@@ -309,33 +333,13 @@ module YandexDisk
|
|
309
333
|
end
|
310
334
|
# debug
|
311
335
|
http.set_debug_output($stderr) if YandexDisk::DEBUG
|
312
|
-
#
|
313
|
-
req =
|
314
|
-
|
315
|
-
when :put then
|
316
|
-
req = Net::HTTP::Put.new(request_path, headers)
|
317
|
-
req.body_stream = Chunked.new(@file, args[:chunk_size])
|
318
|
-
when :get then
|
319
|
-
req = Net::HTTP::Get.new(request_path, headers)
|
320
|
-
when :mkcol then
|
321
|
-
req = Net::HTTP::Mkcol.new(request_path, headers)
|
322
|
-
when :propfind then
|
323
|
-
req = Net::HTTP::Propfind.new(request_path, headers)
|
324
|
-
when :copy then
|
325
|
-
req = Net::HTTP::Copy.new(request_path, headers)
|
326
|
-
when :move then
|
327
|
-
req = Net::HTTP::Move.new(request_path, headers)
|
328
|
-
when :delete then
|
329
|
-
req = Net::HTTP::Delete.new(request_path, headers)
|
330
|
-
when :proppatch
|
331
|
-
req = Net::HTTP::Proppatch.new(request_path, headers)
|
332
|
-
else
|
333
|
-
raise RequestError, "Method #{method} not supported."
|
334
|
-
end
|
335
|
-
# start
|
336
|
+
# request
|
337
|
+
req = init_request(method).new(path, headers)
|
338
|
+
req.body_stream = Chunked.new(@file, args[:chunk_size]) if method == :put
|
336
339
|
req.body = args[:body] if args[:body]
|
340
|
+
# start
|
337
341
|
http.start{|h| @response = h.request(req) }
|
338
|
-
successful?(method,
|
342
|
+
successful?(method, path)
|
339
343
|
end
|
340
344
|
|
341
345
|
def successful?(method, path)
|
data/lib/yandex_disk/cfg.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# encoding: UTF-8
|
2
|
+
require 'codeclimate-test-reporter'
|
2
3
|
require 'simplecov'
|
4
|
+
|
5
|
+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
6
|
+
SimpleCov::Formatter::HTMLFormatter,
|
7
|
+
CodeClimate::TestReporter::Formatter
|
8
|
+
]
|
3
9
|
SimpleCov.start
|
4
10
|
require 'rubygems'
|
5
11
|
require 'yandex_disk'
|
@@ -7,9 +13,14 @@ require 'fileutils'
|
|
7
13
|
|
8
14
|
RSpec.configure do |config|
|
9
15
|
config.fail_fast = true
|
16
|
+
|
10
17
|
config.before(:each) do
|
11
18
|
init_test_files
|
12
19
|
end
|
20
|
+
|
21
|
+
config.after(:each) do
|
22
|
+
clear!
|
23
|
+
end
|
13
24
|
end
|
14
25
|
|
15
26
|
# login and password for yandex disk
|
@@ -23,16 +34,21 @@ FILE_TEXT = 'Hi developer.'
|
|
23
34
|
|
24
35
|
def init_test_files
|
25
36
|
FileUtils.mkdir_p(DOWNLOAD_PATH) if !Dir.exist?(DOWNLOAD_PATH)
|
37
|
+
FileUtils.mkdir_p(FILES_PATH) if !Dir.exist?(FILES_PATH)
|
38
|
+
|
26
39
|
@text_file = FILES_PATH + '/sample.txt'
|
27
40
|
File.open(@text_file, 'w+'){|f| f.write(FILE_TEXT)} unless File.file? @text_file
|
28
41
|
@text_file.freeze
|
42
|
+
|
29
43
|
@image_file = FILES_PATH + '/sample.jpg'
|
30
44
|
@image_file.freeze
|
31
|
-
|
45
|
+
|
46
|
+
raise Exception, "Please add any image file named 'sample.jpg' to #{FILES_PATH}" unless File.file? @image_file
|
32
47
|
end
|
33
48
|
|
49
|
+
# Delete test files and delete test path 'my' on Yandex disc
|
34
50
|
def clear!
|
35
|
-
@yd.delete('/my').should be_true
|
51
|
+
@yd.delete('/my').should be_true if @yd
|
36
52
|
FileUtils.rm_rf DOWNLOAD_PATH
|
37
53
|
end
|
38
54
|
|
data/spec/yandex_disk_spec.rb
CHANGED
@@ -11,12 +11,17 @@ describe YandexDisk do
|
|
11
11
|
describe 'validate' do
|
12
12
|
it 'authorization' do
|
13
13
|
yd = YandexDisk.login('', '')
|
14
|
-
expect{yd.size}.to raise_error YandexDisk::RequestError
|
14
|
+
expect{yd.size}.to raise_error YandexDisk::RequestError, /401 Unauthorized/
|
15
15
|
end
|
16
16
|
|
17
|
-
it 'file' do
|
17
|
+
it 'wrong file' do
|
18
18
|
yd = YandexDisk.login('', '')
|
19
|
-
expect{yd.upload('not/exist/file')}.to raise_error YandexDisk::RequestError
|
19
|
+
expect{yd.upload('not/exist/file')}.to raise_error YandexDisk::RequestError, /File not found/
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'wrong path' do
|
23
|
+
yd = YandexDisk.login('', '')
|
24
|
+
expect{yd.create_path('/ / / / /f // / ')}.to raise_error YandexDisk::BadFormat, /Path has bad format/
|
20
25
|
end
|
21
26
|
end
|
22
27
|
|
@@ -26,12 +31,12 @@ describe YandexDisk do
|
|
26
31
|
end
|
27
32
|
|
28
33
|
describe 'size' do
|
29
|
-
it '
|
34
|
+
it 'in bytes' do
|
30
35
|
size = @yd.size
|
31
36
|
expect(size[:used] > 0 && size[:available] > 0).to be_true
|
32
37
|
end
|
33
38
|
|
34
|
-
it '
|
39
|
+
it 'in readable format' do
|
35
40
|
size = @yd.size(:h_size => true)
|
36
41
|
mask = /Byte|KB|MB|GB/
|
37
42
|
expect(size[:used].match(mask)[0].empty? &&
|
@@ -41,35 +46,37 @@ describe YandexDisk do
|
|
41
46
|
|
42
47
|
it 'should return list of files' do
|
43
48
|
@yd.files.each do |item|
|
44
|
-
[:name, :path, :created, :updated, :size, :is_file].each{|res|
|
49
|
+
[:name, :path, :created, :updated, :size, :is_file].each{|res| item[res].to_s.should_not be_empty}
|
45
50
|
end
|
46
51
|
end
|
47
52
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
53
|
+
describe 'properties' do
|
54
|
+
it 'for file' do
|
55
|
+
@yd.upload(@text_file, 'my', :force => true)
|
56
|
+
properties = @yd.properties('my/' + File.basename(@text_file))
|
57
|
+
[:created, :updated, :type, :size, :is_file].each{|res| properties[res].to_s.should_not be_empty}
|
58
|
+
properties[:type].should eq 'text/plain'
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'for directory' do
|
62
|
+
dir = '/my/photo'
|
63
|
+
@yd.create_path(dir)
|
64
|
+
properties = @yd.properties(dir)
|
65
|
+
properties[:is_file].should be_false
|
66
|
+
end
|
60
67
|
end
|
61
68
|
|
62
69
|
describe 'directory' do
|
63
|
-
it '
|
70
|
+
it 'create' do
|
64
71
|
dir = 'my/photos/cats'
|
65
72
|
@yd.create_path(dir).should be_true
|
66
73
|
@yd.properties(dir)[:is_file].should be_false
|
67
74
|
end
|
68
75
|
|
69
|
-
it '
|
76
|
+
it 'copy' do
|
70
77
|
# create directories with Cyrillic name
|
71
|
-
src = '
|
72
|
-
des = '
|
78
|
+
src = 'файлы/старые'
|
79
|
+
des = 'файлы/здесь новые'
|
73
80
|
|
74
81
|
@yd.create_path(src)
|
75
82
|
@yd.create_path(des)
|
@@ -84,31 +91,47 @@ describe YandexDisk do
|
|
84
91
|
@yd.copy(src, des)
|
85
92
|
# check files
|
86
93
|
@yd.files(src).size.should eq 2
|
87
|
-
files.each do |file, text|
|
88
|
-
download_and_validate(File.join(des, file), text)
|
89
|
-
end
|
90
94
|
# clear
|
91
95
|
files.each{|file, text| File.delete( File.join(FILES_PATH, file) )}
|
92
96
|
end
|
93
|
-
|
94
|
-
after(:each) do
|
95
|
-
clear!
|
96
|
-
end
|
97
97
|
end
|
98
98
|
|
99
99
|
describe 'file' do
|
100
|
-
it '
|
101
|
-
@yd.upload(@text_file, 'my',
|
100
|
+
it 'upload' do
|
101
|
+
@yd.upload(@text_file, 'my', :force => true).should be_true
|
102
|
+
@yd.exist?('my/' + File.basename(@text_file)).should be_true
|
102
103
|
end
|
103
104
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
105
|
+
describe 'download' do
|
106
|
+
it 'save and validate' do
|
107
|
+
@yd.upload(@text_file, 'my', :force => true).should be_true
|
108
|
+
path = 'my/' + File.basename(@text_file)
|
109
|
+
@yd.download(path, DOWNLOAD_PATH).should be_true
|
110
|
+
expect( File.read( File.join(DOWNLOAD_PATH, File.basename(@text_file)) ) ).to eq(FILE_TEXT)
|
111
|
+
end
|
112
|
+
|
113
|
+
it 'return and validate' do
|
114
|
+
@yd.upload(@text_file, 'my', :force => true).should be_true
|
115
|
+
path = 'my/' + File.basename(@text_file)
|
116
|
+
YandexDisk::Api.any_instance.stub(:response).and_return('xxx')
|
117
|
+
@yd.download(path).should eq FILE_TEXT
|
118
|
+
end
|
119
|
+
|
120
|
+
it 'unzip file' do
|
121
|
+
file = @text_file.gsub('.txt', '.gz')
|
122
|
+
Zlib::GzipWriter.open(file) do |gz|
|
123
|
+
gz.write File.read(@text_file)
|
124
|
+
end
|
125
|
+
|
126
|
+
@yd.upload(file, 'my', :force => true).should be_true
|
127
|
+
path = 'my/' + File.basename(file)
|
128
|
+
@yd.should_receive(:gzip?){ true }
|
129
|
+
@yd.download(path).should eq FILE_TEXT
|
130
|
+
end
|
108
131
|
end
|
109
|
-
|
110
|
-
it '
|
111
|
-
@yd.upload(@text_file, 'my',
|
132
|
+
|
133
|
+
it 'copy' do
|
134
|
+
@yd.upload(@text_file, 'my', :force => true)
|
112
135
|
f_name = File.basename(@text_file)
|
113
136
|
file = 'my/' + f_name
|
114
137
|
new_path = 'my/text'
|
@@ -116,11 +139,10 @@ describe YandexDisk do
|
|
116
139
|
@yd.copy(file, new_path).should be_true
|
117
140
|
# file still exist in src path
|
118
141
|
@yd.exist?(file).should be_true
|
119
|
-
download_and_validate(File.join(new_path, f_name))
|
120
142
|
end
|
121
143
|
|
122
|
-
it '
|
123
|
-
@yd.upload(@text_file, 'my',
|
144
|
+
it 'move' do
|
145
|
+
@yd.upload(@text_file, 'my', :force => true)
|
124
146
|
f_name = File.basename(@text_file)
|
125
147
|
file = 'my/' + f_name
|
126
148
|
new_path = 'my/text'
|
@@ -128,26 +150,23 @@ describe YandexDisk do
|
|
128
150
|
@yd.move(file, new_path).should be_true
|
129
151
|
# file not exist in src path
|
130
152
|
@yd.exist?(file).should be_false
|
131
|
-
download_and_validate(File.join(new_path, f_name))
|
132
153
|
end
|
133
154
|
|
134
|
-
it '
|
135
|
-
# upload file
|
155
|
+
it 'delete' do
|
136
156
|
@yd.upload(@text_file)
|
137
157
|
f_name = File.basename(@text_file)
|
138
|
-
download_and_validate(f_name)
|
139
158
|
@yd.delete(f_name).should be_true
|
140
159
|
@yd.exist?(f_name).should be_false
|
141
160
|
end
|
142
161
|
|
143
|
-
it '
|
144
|
-
@yd.upload(@image_file, 'my',
|
162
|
+
it 'set public'do
|
163
|
+
@yd.upload(@image_file, 'my', :force => true)
|
145
164
|
# mask: http://yadi.sk/d/#############
|
146
165
|
expect(@yd.set_public('my/' + File.basename(@image_file)) =~ /http:\/\/yadi\.sk\/d\/.+/).to be_true
|
147
166
|
end
|
148
167
|
|
149
|
-
it '
|
150
|
-
@yd.upload(@text_file, 'my',
|
168
|
+
it 'set private'do
|
169
|
+
@yd.upload(@text_file, 'my', :force => true)
|
151
170
|
f_name = 'my/' + File.basename(@text_file)
|
152
171
|
# mask: http://yadi.sk/d/#############
|
153
172
|
expect(@yd.set_public(f_name) =~ /http:\/\/yadi\.sk\/d\/.+/).to be_true
|
@@ -156,7 +175,7 @@ describe YandexDisk do
|
|
156
175
|
|
157
176
|
describe 'preview' do
|
158
177
|
before(:each)do
|
159
|
-
@yd.upload(@image_file, 'my',
|
178
|
+
@yd.upload(@image_file, 'my', :force => true).should be_true
|
160
179
|
@f_name = File.basename(@image_file)
|
161
180
|
end
|
162
181
|
|
@@ -175,18 +194,10 @@ describe YandexDisk do
|
|
175
194
|
FastImage.size( File.join(DOWNLOAD_PATH, @f_name) )[0].should eq 128
|
176
195
|
end
|
177
196
|
end
|
178
|
-
|
179
|
-
after(:each) do
|
180
|
-
clear!
|
181
|
-
end
|
182
197
|
end
|
183
198
|
|
199
|
+
it 'should catch wrong method' do
|
200
|
+
expect { @yd.send :init_request, :none }.to raise_error YandexDisk::RequestError, /Method none not supported/
|
201
|
+
end
|
184
202
|
end
|
185
|
-
|
186
|
-
def download_and_validate(download_file, text = FILE_TEXT)
|
187
|
-
@yd.download(download_file, DOWNLOAD_PATH).should be_true
|
188
|
-
file = download_file.split('/').last
|
189
|
-
expect( File.read( File.join(DOWNLOAD_PATH, file) ) ).to eq(text)
|
190
|
-
end
|
191
|
-
|
192
203
|
end
|
metadata
CHANGED
@@ -1,70 +1,83 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yandex_disk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Boris Murga
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-04-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ~>
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: simplecov
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ~>
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: codeclimate-test-reporter
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
39
53
|
- !ruby/object:Gem::Version
|
40
54
|
version: '0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: fastimage
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
44
58
|
requirements:
|
45
|
-
- -
|
59
|
+
- - ~>
|
46
60
|
- !ruby/object:Gem::Version
|
47
61
|
version: '0'
|
48
62
|
type: :development
|
49
63
|
prerelease: false
|
50
64
|
version_requirements: !ruby/object:Gem::Requirement
|
51
65
|
requirements:
|
52
|
-
- -
|
66
|
+
- - ~>
|
53
67
|
- !ruby/object:Gem::Version
|
54
68
|
version: '0'
|
55
|
-
description: An easy-to-use client library for Yandex Disk API
|
69
|
+
description: An easy-to-use client library for Yandex Disk API written in pure ruby.
|
56
70
|
email: denwwer.c4@gmail.com
|
57
71
|
executables: []
|
58
72
|
extensions: []
|
59
73
|
extra_rdoc_files: []
|
60
74
|
files:
|
61
75
|
- lib/yandex_disk.rb
|
62
|
-
- lib/yandex_disk/chunked.rb
|
63
|
-
- lib/yandex_disk/ext.rb
|
64
76
|
- lib/yandex_disk/api.rb
|
65
77
|
- lib/yandex_disk/cfg.rb
|
78
|
+
- lib/yandex_disk/chunked.rb
|
79
|
+
- lib/yandex_disk/ext.rb
|
66
80
|
- spec/spec_helper.rb
|
67
|
-
- spec/files/README
|
68
81
|
- spec/yandex_disk_spec.rb
|
69
82
|
homepage: https://github.com/denwwer/yandex_disk
|
70
83
|
licenses:
|
@@ -87,11 +100,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
87
100
|
version: '0'
|
88
101
|
requirements: []
|
89
102
|
rubyforge_project:
|
90
|
-
rubygems_version: 2.
|
103
|
+
rubygems_version: 2.2.2
|
91
104
|
signing_key:
|
92
105
|
specification_version: 4
|
93
106
|
summary: API for Yandex Disk
|
94
107
|
test_files:
|
95
108
|
- spec/spec_helper.rb
|
96
|
-
- spec/files/README
|
97
109
|
- spec/yandex_disk_spec.rb
|