rapidshare-ext 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.md +9 -3
- data/README.md +93 -91
- data/lib/rapidshare-ext/api.rb +39 -22
- data/lib/rapidshare-ext/version.rb +1 -1
- data/rapidshare-ext.gemspec +1 -1
- data/test/integration/rapidshare-ext_test.rb +129 -11
- metadata +3 -3
data/History.md
CHANGED
@@ -1,4 +1,10 @@
|
|
1
|
-
## ver.0.0.
|
1
|
+
## ver. 0.0.4 2012-11-21
|
2
|
+
|
3
|
+
* [changed] folders_hierarchy(): :validate param added
|
4
|
+
* [changed] folders_hierarchy(), folder_path(): orphan pathes marked with "<undefined>" parts
|
5
|
+
* [changed] 100% code coverage
|
6
|
+
|
7
|
+
## ver. 0.0.3 2012-11-19
|
2
8
|
|
3
9
|
* [added] Downloading files by absolute path
|
4
10
|
* [added] File download url added to the return hash of file_info(). Url is represented by the :url key
|
@@ -10,11 +16,11 @@ It has began. We have the features as follows:
|
|
10
16
|
|
11
17
|
* [added] Creating folders
|
12
18
|
|
13
|
-
## ver.0.0.2 2012-11-18
|
19
|
+
## ver. 0.0.2 2012-11-18
|
14
20
|
|
15
21
|
Technical release. No features, no bug fixes.
|
16
22
|
|
17
|
-
## ver.0.0.1 2012-11-17
|
23
|
+
## ver. 0.0.1 2012-11-17
|
18
24
|
|
19
25
|
It has began. We have the features as follows:
|
20
26
|
|
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# Rapidshare::Ext
|
2
2
|
|
3
|
-
Makes your interactions with Rapidshare API more pleasant by providing new handy features: creating/moving/deleting files/folders in a user friendly way, upload files, etc.
|
3
|
+
Makes your interactions with the Rapidshare API more pleasant by providing new handy features: creating/moving/deleting files/folders in a user friendly way, upload files, etc.
|
4
4
|
|
5
|
-
This gem extends the existing one - https://github.com/defkode/rapidshare, so it has all features implemented
|
5
|
+
This gem extends the existing one - https://github.com/defkode/rapidshare, so it has all features have been implemented by the authors of the original gem at the moment.
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
@@ -26,6 +26,74 @@ api = Rapidshare::API.new(:login => 'my_login', :password => 'my_password')
|
|
26
26
|
api = Rapidshare::API.new(:cookie => 'cookie_here') # More preferable way
|
27
27
|
```
|
28
28
|
|
29
|
+
### Files
|
30
|
+
|
31
|
+
Now you can perform file download in two ways: by the HTTP url or by the absolute path.
|
32
|
+
|
33
|
+
First, by the HTTP url, as it has worked before:
|
34
|
+
```ruby
|
35
|
+
@rs.download "https://rapidshare.com/files/4226120320/upload_file_1.txt",
|
36
|
+
:downloads_dir => "/tmp",
|
37
|
+
:save_as => "file2.txt" # This doesn't work in the original gem at the moment because of Rapidshare API changes
|
38
|
+
|
39
|
+
# With a default local file name
|
40
|
+
@rs.download "https://rapidshare.com/files/4226120320/upload_file_1.txt",
|
41
|
+
:downloads_dir => "/tmp"
|
42
|
+
```
|
43
|
+
|
44
|
+
Download by absolute path:
|
45
|
+
```ruby
|
46
|
+
@rs.download "/foo/bar/baz/upload_file_1.txt",
|
47
|
+
:downloads_dir => "/tmp"
|
48
|
+
```
|
49
|
+
|
50
|
+
In both the first and second samples the result will be the same.
|
51
|
+
|
52
|
+
File uploading became very simple now:
|
53
|
+
```ruby
|
54
|
+
api.upload("/home/odiszapc/my_damn_cat.mov", :to => "/gallery/video", :as => "cat1.mov")
|
55
|
+
# => {
|
56
|
+
# :id => 1,
|
57
|
+
# :size => 12345, # File size in bytes
|
58
|
+
# :checksum => <MD5>,
|
59
|
+
# :url => <DOWNLOAD_URL>, # https://rapidshare/.......
|
60
|
+
# :already_exists? => true/false # Does the file already exists within a specific folder, real uploading will not being performed in this case
|
61
|
+
#}
|
62
|
+
```
|
63
|
+
Destination folder will be created automatically.
|
64
|
+
After uploading has been completed the file will be stored in a Rapidshare as "/gallery/video/cat1.mov"
|
65
|
+
You can easily get a download url after uploading:
|
66
|
+
```ruby
|
67
|
+
result = api.upload("/home/odiszapc/my_damn_cat.mov", :to => "/gallery/video", :as => "cat1.mov")
|
68
|
+
result[:url]
|
69
|
+
```
|
70
|
+
|
71
|
+
By default, file is uploaded to the root folder:
|
72
|
+
```ruby
|
73
|
+
api.upload("/home/odiszapc/my_damn_humster.mov")
|
74
|
+
```
|
75
|
+
|
76
|
+
Deleting files:
|
77
|
+
```ruby
|
78
|
+
api.remove_file("/putin/is/a/good/reason/to/live/abroad/ticket_to_Nicaragua.jpg")
|
79
|
+
```
|
80
|
+
|
81
|
+
Renaming files:
|
82
|
+
```ruby
|
83
|
+
api.rename_file("/foo/bar.rar", "baz.rar")
|
84
|
+
```
|
85
|
+
|
86
|
+
Moving files:
|
87
|
+
```ruby
|
88
|
+
api.move_file("/foo/bar/baz.rar", :to => "/foo") # new file path: "/foo/baz.rar"
|
89
|
+
api.move_file("/foo/bar/baz.rar") # move to a root folder
|
90
|
+
```
|
91
|
+
|
92
|
+
Get the file ID:
|
93
|
+
```ruby
|
94
|
+
api.file_id("/foo/bar/baz.rar") # => <ID>
|
95
|
+
```
|
96
|
+
|
29
97
|
### Folders
|
30
98
|
As you note you can have a hierarchy of folders in your account.
|
31
99
|
|
@@ -45,7 +113,7 @@ api.move_folder("/a/b/c", :to => "/a")
|
|
45
113
|
```
|
46
114
|
This moves folder "c" from directory "/a/b/" and places it under the directory "/a"
|
47
115
|
|
48
|
-
Get hierarchy of all folders in account:
|
116
|
+
Get the hierarchy of all folders in account:
|
49
117
|
```ruby
|
50
118
|
api.folders_hierarchy
|
51
119
|
# => {
|
@@ -58,30 +126,37 @@ api.folders_hierarchy
|
|
58
126
|
# }
|
59
127
|
```
|
60
128
|
|
61
|
-
Note, that after the folder hierarchy is generated first time
|
129
|
+
Note, that after the folder hierarchy is generated first time it's cached permanently to improve performance.
|
62
130
|
|
63
131
|
So, if you want to invalidate the cache just call the above method with trailing "!":
|
64
132
|
```ruby
|
65
133
|
api.folders_hierarchy!
|
66
134
|
```
|
67
135
|
|
68
|
-
If folder tree is inconsistent (orphans are found, see next paragraph for details) the Exception will be thrown
|
136
|
+
If folder tree is inconsistent (orphans are found, see next paragraph for details) the Exception will be thrown when you perform #folders_hierarchy.
|
137
|
+
To automatically normalize the tree, call the method with the :consistent flag:
|
69
138
|
```ruby
|
70
139
|
api.folders_hierarchy :consistent => true
|
71
140
|
```
|
72
|
-
Be careful with
|
141
|
+
Be careful with the tree consistency, orphan folders may contain a critical data.
|
73
142
|
|
74
|
-
A more secure way to deal with consistency is to fix orphans first and then generate
|
143
|
+
A more secure way to deal with folder consistency is to fix all orphans first and then generate folder tree:
|
75
144
|
```ruby
|
76
145
|
api.add_folder "/garbage"
|
77
146
|
api.move_orphans :to => "/garbage" # Collect all orphans and place them under the /garbage folder
|
78
147
|
tree = api.folders_hierarchy
|
79
148
|
```
|
80
149
|
|
150
|
+
Get the folder ID or path:
|
151
|
+
```ruby
|
152
|
+
id = api.folder_id("/foo/bar") # <ID>
|
153
|
+
api.folder_path(id) # "/foo/bar"
|
154
|
+
```
|
155
|
+
|
81
156
|
### Orphans
|
82
|
-
As mentioned
|
83
|
-
What does it mean? When you delete parent folder by its ID
|
84
|
-
For example,
|
157
|
+
As mentioned earlier, the Rapidshare has its common problem: the chance of orphan folders to be appeared.
|
158
|
+
What does it mean? When you delete parent folder by its ID the folder will be deleted without any of its child folders being deleted.
|
159
|
+
For example, let we have the basic directory tree:
|
85
160
|
```
|
86
161
|
ROOT
|
87
162
|
`-a <- RS API allows us to delete JUST THIS folder, so hierarchy relation between folders will be lost and the folders "c" and "b" will become orphans
|
@@ -89,15 +164,15 @@ ROOT
|
|
89
164
|
`-c
|
90
165
|
```
|
91
166
|
|
92
|
-
|
167
|
+
My know-how: orphan folders become invisible in your File Manager on the Rapidshare web site, so you may want to hide all the data in this way (stupid idea)
|
93
168
|
|
94
|
-
So, the best way to delete directory tree without washing away its consistency is the following:
|
169
|
+
So, the best way to delete some directory tree without washing away its consistency is the following:
|
95
170
|
```ruby
|
96
|
-
api.remove_folder "/a"
|
171
|
+
api.remove_folder "/a" # This will correctly delete all child directories
|
97
172
|
```
|
98
173
|
|
99
|
-
|
100
|
-
The next method detects all orphan folders in your account and moves them
|
174
|
+
But if you already have orphans in your account there is possible to fix them.
|
175
|
+
The next method detects all orphan folders in your account and moves them into a specific folder:
|
101
176
|
```ruby
|
102
177
|
move_orphans :to => "/"
|
103
178
|
```
|
@@ -107,82 +182,8 @@ Or we can just delete all of them (be careful):
|
|
107
182
|
remove_orphans!
|
108
183
|
```
|
109
184
|
|
110
|
-
Get the folder ID or path:
|
111
|
-
```ruby
|
112
|
-
id = api.folder_id("/foo/bar") # <ID>
|
113
|
-
api.folder_path(id) # "/foo/bar"
|
114
|
-
```
|
115
|
-
|
116
|
-
### Files
|
117
|
-
|
118
|
-
Now you can download files in two ways: by HTTP url or by absolute path.
|
119
|
-
|
120
|
-
By url, as it worked before:
|
121
|
-
```ruby
|
122
|
-
@rs.download "https://rapidshare.com/files/4226120320/upload_file_1.txt",
|
123
|
-
:downloads_dir => "/tmp",
|
124
|
-
:save_as => "file2.txt" # This doesn't work in the base rapidshare gem
|
125
|
-
|
126
|
-
# With a default local file name
|
127
|
-
@rs.download "https://rapidshare.com/files/4226120320/upload_file_1.txt",
|
128
|
-
:downloads_dir => "/tmp"
|
129
|
-
```
|
130
|
-
|
131
|
-
Download by the absolute path:
|
132
|
-
```ruby
|
133
|
-
@rs.download "/foo/bar/baz/upload_file_1.txt",
|
134
|
-
:downloads_dir => "/tmp"
|
135
|
-
```
|
136
|
-
|
137
|
-
For both first and second samples result will be the same
|
138
|
-
|
139
|
-
File uploading became very simple now:
|
140
|
-
```ruby
|
141
|
-
api.upload("/home/odiszapc/my_damn_cat.mov", :to => "/gallery/video", :as => "cat1.mov")
|
142
|
-
# => {
|
143
|
-
# :id => 1,
|
144
|
-
# :size => 12345, # File size in bytes
|
145
|
-
# :checksum => <MD5>,
|
146
|
-
# :url => <DOWNLOAD_URL>, # https://rapidshare/.......
|
147
|
-
# :already_exists? => true/false # Does the file already exists within a specific folder, real uploading will not being performed in this case
|
148
|
-
#}
|
149
|
-
```
|
150
|
-
Destination folder will be created automatically.
|
151
|
-
After uploading has been completed the file will be stored in a Rapidshare as "/gallery/video/cat1.mov"
|
152
|
-
You can easily get a download url after uploading:
|
153
|
-
```ruby
|
154
|
-
result = api.upload("/home/odiszapc/my_damn_cat.mov", :to => "/gallery/video", :as => "cat1.mov")
|
155
|
-
result[:url]
|
156
|
-
```
|
157
|
-
|
158
|
-
By default, file is uploaded to root folder:
|
159
|
-
```ruby
|
160
|
-
api.upload("/home/odiszapc/my_damn_humster.mov")
|
161
|
-
```
|
162
|
-
|
163
|
-
Deleting files:
|
164
|
-
```ruby
|
165
|
-
api.remove_file("/putin/is/a/good/reason/to/live/abroad/ticket_to_Nicaragua.jpg")
|
166
|
-
```
|
167
|
-
|
168
|
-
Renaming files:
|
169
|
-
```ruby
|
170
|
-
api.rename_file("/foo/bar.rar", "baz.rar")
|
171
|
-
```
|
172
|
-
|
173
|
-
Moving files:
|
174
|
-
```ruby
|
175
|
-
api.move_file("/foo/bar/baz.rar", :to => "/foo") # new file path: "/foo/baz.rar"
|
176
|
-
api.move_file("/foo/bar/baz.rar") # move to a root folder
|
177
|
-
```
|
178
|
-
|
179
|
-
Get the file ID:
|
180
|
-
```ruby
|
181
|
-
api.file_id("/foo/bar/baz.rar") # => <ID>
|
182
|
-
```
|
183
|
-
|
184
185
|
### Account
|
185
|
-
You can null your account by deleting all data stored inside. Be careful with it, because all you
|
186
|
+
You can null your account by deleting all data stored inside. Be careful with it, because all you lose all your data:
|
186
187
|
```ruby
|
187
188
|
api.erase_all_data!
|
188
189
|
```
|
@@ -193,4 +194,5 @@ api.erase_all_data!
|
|
193
194
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
194
195
|
3. Commit your changes (`git commit -am 'Added some feature'`)
|
195
196
|
4. Push to the branch (`git push origin my-new-feature`)
|
196
|
-
5. Create new Pull Request
|
197
|
+
5. Create new Pull Request
|
198
|
+
6. Open beer
|
data/lib/rapidshare-ext/api.rb
CHANGED
@@ -247,12 +247,18 @@ module Rapidshare
|
|
247
247
|
# Invalidate cached tree, default: false
|
248
248
|
# After each call of this method the generated tree will be saved as cache
|
249
249
|
# to avoid unnecessary queries to be performed fpr a future calls
|
250
|
+
# <tt>:validate</tt>::
|
251
|
+
# Validate tree after it has been generated, default: true
|
250
252
|
# <tt>:consistent</tt>::
|
251
253
|
# Delete all found orphans, default: false
|
254
|
+
# Ignored if :validate is set to false
|
252
255
|
def folders_hierarchy(params = {})
|
253
256
|
force_load = params.delete :force
|
254
257
|
from_folder_path = path_trim(params.delete(:from) || '/')
|
255
258
|
remove_orphans = params.delete(:consistent)
|
259
|
+
perform_validation = params.delete(:validate)
|
260
|
+
perform_validation = true if perform_validation.nil?
|
261
|
+
remove_orphans = false unless perform_validation
|
256
262
|
|
257
263
|
if @tree && !force_load
|
258
264
|
if from_folder_path.empty?
|
@@ -284,18 +290,19 @@ module Rapidshare
|
|
284
290
|
# Kill orphans
|
285
291
|
remove_orphans! if remove_orphans
|
286
292
|
|
287
|
-
# Validate folder tree consistency
|
288
293
|
@tree.each_pair do |folder_id, data|
|
289
|
-
|
290
|
-
if !parent_id.zero? && @tree[parent_id].nil?
|
291
|
-
|
292
|
-
error = "There is no parent folder with id ##{data[:parent]} for the folder \"#{data[:name]}\" [#{folder_id}]"
|
293
|
-
raise error
|
294
|
-
end
|
294
|
+
@tree[folder_id][:path] = folder_path folder_id
|
295
295
|
end
|
296
296
|
|
297
|
-
|
298
|
-
|
297
|
+
if perform_validation
|
298
|
+
# Validate folder tree consistency
|
299
|
+
@tree.each_pair do |folder_id, data|
|
300
|
+
parent_id = data[:parent]
|
301
|
+
if !parent_id.zero? && @tree[parent_id].nil?
|
302
|
+
error = "Directory tree consistency error. Parent folder ##{data[:parent]} for the folder \"#{data[:path]}\" [#{folder_id}] could not be found"
|
303
|
+
raise error
|
304
|
+
end
|
305
|
+
end
|
299
306
|
end
|
300
307
|
|
301
308
|
@tree = slice_tree @tree, :from => from_folder_path unless from_folder_path.empty?
|
@@ -358,18 +365,23 @@ module Rapidshare
|
|
358
365
|
# Example:
|
359
366
|
# move_orphans :to => "/"
|
360
367
|
def move_orphans(params = {})
|
361
|
-
new_folder =
|
362
|
-
|
363
|
-
|
364
|
-
|
368
|
+
new_folder = path_trim(params.delete(:to) || '/')
|
369
|
+
gaps = detect_gaps
|
370
|
+
|
371
|
+
if gaps.any?
|
372
|
+
params = {
|
373
|
+
:realfolder => gaps.join(','),
|
374
|
+
:newparent => new_folder
|
375
|
+
}.merge params
|
376
|
+
moverealfolder params
|
365
377
|
end
|
366
378
|
end
|
367
379
|
|
368
380
|
# Returns gap list between folders
|
369
381
|
# See #gap? for example
|
370
382
|
def detect_gaps
|
371
|
-
@tree = folders_hierarchy
|
372
|
-
@tree.keep_if do |folder_id, data|
|
383
|
+
@tree = folders_hierarchy :validate => false
|
384
|
+
@tree.dup.keep_if do |folder_id, data|
|
373
385
|
gap? folder_id # This is wrong
|
374
386
|
end.keys
|
375
387
|
end
|
@@ -378,7 +390,7 @@ module Rapidshare
|
|
378
390
|
# WARNING!!! All data will be lost!!!
|
379
391
|
# Use it carefully
|
380
392
|
def erase_all_data!
|
381
|
-
@tree = folders_hierarchy
|
393
|
+
@tree = folders_hierarchy! :validate => false
|
382
394
|
@tree.keys.each do |folder_id|
|
383
395
|
delrealfolder :realfolder => folder_id
|
384
396
|
end
|
@@ -387,13 +399,14 @@ module Rapidshare
|
|
387
399
|
|
388
400
|
# Check if folder with given id placed on the bottom of folder hierarchy
|
389
401
|
def root_folder?(folder_id)
|
390
|
-
@tree = folders_hierarchy
|
402
|
+
@tree = folders_hierarchy :validate => false
|
403
|
+
return false if @tree[folder_id].nil?
|
391
404
|
@tree[folder_id][:parent].zero?
|
392
405
|
end
|
393
406
|
|
394
407
|
# Check if the given folder has no parent
|
395
408
|
def gap?(folder_id)
|
396
|
-
@tree = folders_hierarchy
|
409
|
+
@tree = folders_hierarchy :validate => false
|
397
410
|
parent_id = @tree[folder_id][:parent]
|
398
411
|
@tree[parent_id].nil?
|
399
412
|
end
|
@@ -406,7 +419,8 @@ module Rapidshare
|
|
406
419
|
# `-b
|
407
420
|
# `-c
|
408
421
|
def orphan?(folder_id)
|
409
|
-
@tree = folders_hierarchy
|
422
|
+
@tree = folders_hierarchy :validate => false
|
423
|
+
return false if @tree[folder_id].nil?
|
410
424
|
parent_id = @tree[folder_id][:parent]
|
411
425
|
return false if root_folder? folder_id
|
412
426
|
return true if gap? folder_id
|
@@ -418,8 +432,11 @@ module Rapidshare
|
|
418
432
|
# api.folder_path(123) # -> "foo/bar/baz"
|
419
433
|
def folder_path(folder_id)
|
420
434
|
@tree = folders_hierarchy
|
421
|
-
|
422
|
-
|
435
|
+
|
436
|
+
folder_data = @tree[folder_id] || {:parent => 0, :name => "<undefined>", :path => "<undefined>"}
|
437
|
+
|
438
|
+
parent_id = folder_data[:parent]
|
439
|
+
path = (folder_path(parent_id) if parent_id.nonzero?).to_s + ('/' if parent_id.nonzero?).to_s + folder_data[:name]
|
423
440
|
parent_id.zero? ? "/#{path}" : path
|
424
441
|
end
|
425
442
|
|
@@ -456,7 +473,7 @@ module Rapidshare
|
|
456
473
|
# :licids,
|
457
474
|
# :sentby
|
458
475
|
# }
|
459
|
-
# See http://images.rapidshare.com/apidoc.txt for more details
|
476
|
+
# See the http://images.rapidshare.com/apidoc.txt for more details
|
460
477
|
def file_info(file_path, params = {})
|
461
478
|
folder_path = File.dirname file_path
|
462
479
|
file_name = File.basename file_path
|
data/rapidshare-ext.gemspec
CHANGED
@@ -6,7 +6,7 @@ Gem::Specification.new do |gem|
|
|
6
6
|
gem.version = Rapidshare::Ext::VERSION
|
7
7
|
gem.authors = ["odiszapc"]
|
8
8
|
gem.email = ["odiszapc@gmail.com"]
|
9
|
-
gem.description = %q{Extends the
|
9
|
+
gem.description = %q{Extends the original rapidshare gem with a set of handy features}
|
10
10
|
gem.summary = %q{Makes your interactions with Rapidshare API more pleasant by providing new handy features: creating/moving/deleting files/folders in a user friendly way, upload files, etc}
|
11
11
|
gem.homepage = "http://github.com/odiszapc/rapidshare-ext"
|
12
12
|
|
@@ -20,7 +20,7 @@ class RapidshareExtTest < Test::Unit::TestCase
|
|
20
20
|
end
|
21
21
|
|
22
22
|
context "Api" do
|
23
|
-
should "
|
23
|
+
should "upload file" do
|
24
24
|
upload_assertion = ->(resp, size_local, digest_local, remote_filename) do
|
25
25
|
assert_instance_of Hash, resp
|
26
26
|
assert_kind_of Integer, resp[:id]
|
@@ -62,7 +62,7 @@ class RapidshareExtTest < Test::Unit::TestCase
|
|
62
62
|
assert_true response[:already_exists?]
|
63
63
|
end
|
64
64
|
|
65
|
-
should "
|
65
|
+
should "download file" do
|
66
66
|
@rs.upload @upload_file_1, :to => "/a/b/c", :as => "upload_file_1.txt"
|
67
67
|
assert_not_nil @rs.file_info("/a/b/c/upload_file_1.txt")
|
68
68
|
|
@@ -85,7 +85,7 @@ class RapidshareExtTest < Test::Unit::TestCase
|
|
85
85
|
assert_equal @upload_file_1_md5, Digest::MD5.hexdigest(File.read("#@download_dir/file2.txt"))
|
86
86
|
end
|
87
87
|
|
88
|
-
should "
|
88
|
+
should "rename file" do
|
89
89
|
@rs.upload @upload_file_1, :to => "/a/b/c", :as => "upload_file_1.txt"
|
90
90
|
assert_not_nil @rs.file_info("/a/b/c/upload_file_1.txt")
|
91
91
|
|
@@ -99,7 +99,7 @@ class RapidshareExtTest < Test::Unit::TestCase
|
|
99
99
|
assert_equal info[:md5hex].downcase, @upload_file_1_md5
|
100
100
|
end
|
101
101
|
|
102
|
-
should "
|
102
|
+
should "move file" do
|
103
103
|
@rs.upload @upload_file_1, :to => "/a/b/c", :as => "upload_file_1.txt"
|
104
104
|
assert_not_nil @rs.file_info("/a/b/c/upload_file_1.txt")
|
105
105
|
|
@@ -114,7 +114,7 @@ class RapidshareExtTest < Test::Unit::TestCase
|
|
114
114
|
assert_equal info[:md5hex].downcase, @upload_file_1_md5
|
115
115
|
end
|
116
116
|
|
117
|
-
should "
|
117
|
+
should "delete file" do
|
118
118
|
@rs.upload @upload_file_1, :to => "/a/b/c", :as => "upload_file_1.txt"
|
119
119
|
assert_not_nil @rs.file_info("/a/b/c/upload_file_1.txt")
|
120
120
|
|
@@ -122,13 +122,13 @@ class RapidshareExtTest < Test::Unit::TestCase
|
|
122
122
|
assert_nil @rs.file_info("/a/b/c/upload_file_1.txt")
|
123
123
|
end
|
124
124
|
|
125
|
-
should "
|
125
|
+
should "folder id <=> path conversions" do
|
126
126
|
@rs.add_folder "/a/b/c"
|
127
127
|
id = @rs.folder_id("/a/b/c")
|
128
128
|
assert_equal "/a/b/c", @rs.folder_path(id)
|
129
129
|
end
|
130
130
|
|
131
|
-
should "
|
131
|
+
should "create folder" do
|
132
132
|
folder_id = @rs.add_folder "a/b/c"
|
133
133
|
assert_kind_of Integer, folder_id
|
134
134
|
assert_not_equal 0, folder_id
|
@@ -140,7 +140,7 @@ class RapidshareExtTest < Test::Unit::TestCase
|
|
140
140
|
assert_equal "/a", tree[tree[tree[folder_id][:parent]][:parent]][:path]
|
141
141
|
end
|
142
142
|
|
143
|
-
should "
|
143
|
+
should "move folder" do
|
144
144
|
folder_id = @rs.add_folder "/a/b/c"
|
145
145
|
assert_kind_of Integer, folder_id
|
146
146
|
assert_not_equal 0, folder_id
|
@@ -160,7 +160,7 @@ class RapidshareExtTest < Test::Unit::TestCase
|
|
160
160
|
assert_equal @rs.folder_id("/a"), tree[folder_id][:parent]
|
161
161
|
end
|
162
162
|
|
163
|
-
should "
|
163
|
+
should "remove folder" do
|
164
164
|
folder_id = @rs.add_folder "a/b/c"
|
165
165
|
assert_kind_of Integer, folder_id
|
166
166
|
assert_not_equal 0, folder_id
|
@@ -185,7 +185,7 @@ class RapidshareExtTest < Test::Unit::TestCase
|
|
185
185
|
end
|
186
186
|
|
187
187
|
|
188
|
-
should "
|
188
|
+
should "build folders tree" do
|
189
189
|
# Create folders
|
190
190
|
folder_a_id = @rs.add_folder "/a"
|
191
191
|
assert_kind_of Integer, folder_a_id
|
@@ -224,7 +224,7 @@ class RapidshareExtTest < Test::Unit::TestCase
|
|
224
224
|
assert_equal folder_b_id, sub_tree[folder_c_id][:parent]
|
225
225
|
end
|
226
226
|
|
227
|
-
should "
|
227
|
+
should "erase all account data" do
|
228
228
|
folder_id = @rs.add_folder "/a/b/c"
|
229
229
|
assert_kind_of Integer, folder_id
|
230
230
|
|
@@ -237,6 +237,124 @@ class RapidshareExtTest < Test::Unit::TestCase
|
|
237
237
|
folder_ids = @rs.folders_hierarchy.keys
|
238
238
|
assert_equal 0, folder_ids.count
|
239
239
|
end
|
240
|
+
|
241
|
+
should "move orphans" do
|
242
|
+
# Create folders
|
243
|
+
folder_a_id = @rs.add_folder "/a"
|
244
|
+
assert_kind_of Integer, folder_a_id
|
245
|
+
assert_not_equal 0, folder_a_id
|
246
|
+
|
247
|
+
folder_b_id = @rs.add_folder "/a/b"
|
248
|
+
assert_kind_of Integer, folder_b_id
|
249
|
+
assert_not_equal 0, folder_b_id
|
250
|
+
|
251
|
+
folder_c_id = @rs.add_folder "/a/b/c"
|
252
|
+
assert_kind_of Integer, folder_c_id
|
253
|
+
assert_not_equal 0, folder_c_id
|
254
|
+
|
255
|
+
@rs.reload!
|
256
|
+
|
257
|
+
assert_true @rs.root_folder? folder_a_id
|
258
|
+
assert_false @rs.root_folder? folder_b_id
|
259
|
+
assert_false @rs.root_folder? folder_c_id
|
260
|
+
|
261
|
+
assert_false @rs.orphan? folder_a_id
|
262
|
+
assert_false @rs.orphan? folder_b_id
|
263
|
+
assert_false @rs.orphan? folder_c_id
|
264
|
+
|
265
|
+
# Delete just folder "/a" to accomplish tree inconsistency
|
266
|
+
@rs.delrealfolder :realfolder => folder_a_id
|
267
|
+
@rs.reload! :validate => false
|
268
|
+
|
269
|
+
assert_equal [folder_b_id], @rs.detect_gaps
|
270
|
+
|
271
|
+
assert_false @rs.root_folder? folder_a_id
|
272
|
+
assert_false @rs.root_folder? folder_b_id
|
273
|
+
assert_false @rs.root_folder? folder_c_id
|
274
|
+
|
275
|
+
assert_false @rs.orphan? folder_a_id
|
276
|
+
assert_true @rs.orphan? folder_b_id
|
277
|
+
assert_true @rs.orphan? folder_c_id
|
278
|
+
|
279
|
+
# Move orphan folders to root folder
|
280
|
+
@rs.move_orphans :to => "/"
|
281
|
+
|
282
|
+
hierarchy_expected = {
|
283
|
+
folder_c_id => {:name=>"c", :parent => folder_b_id, :path => "/b/c"},
|
284
|
+
folder_b_id => {:name=>"b", :parent => 0, :path => "/b"},
|
285
|
+
}
|
286
|
+
assert_equal hierarchy_expected, @rs.folders_hierarchy!
|
287
|
+
end
|
288
|
+
|
289
|
+
should "delete orphans" do
|
290
|
+
# Create folders
|
291
|
+
folder_a_id = @rs.add_folder "/a"
|
292
|
+
assert_kind_of Integer, folder_a_id
|
293
|
+
assert_not_equal 0, folder_a_id
|
294
|
+
|
295
|
+
folder_b_id = @rs.add_folder "/a/b"
|
296
|
+
assert_kind_of Integer, folder_b_id
|
297
|
+
assert_not_equal 0, folder_b_id
|
298
|
+
|
299
|
+
folder_c_id = @rs.add_folder "/a/b/c"
|
300
|
+
assert_kind_of Integer, folder_c_id
|
301
|
+
assert_not_equal 0, folder_c_id
|
302
|
+
|
303
|
+
@rs.reload!
|
304
|
+
|
305
|
+
assert_true @rs.root_folder? folder_a_id
|
306
|
+
assert_false @rs.root_folder? folder_b_id
|
307
|
+
assert_false @rs.root_folder? folder_c_id
|
308
|
+
|
309
|
+
assert_false @rs.orphan? folder_a_id
|
310
|
+
assert_false @rs.orphan? folder_b_id
|
311
|
+
assert_false @rs.orphan? folder_c_id
|
312
|
+
|
313
|
+
# Delete just folder "/a" to accomplish tree inconsistency
|
314
|
+
@rs.delrealfolder :realfolder => folder_a_id
|
315
|
+
@rs.reload! :validate => false
|
316
|
+
|
317
|
+
@rs.remove_orphans!
|
318
|
+
|
319
|
+
hierarchy_expected = {
|
320
|
+
folder_c_id => {:name=>"c", :parent => folder_b_id, :path => "/b/c"},
|
321
|
+
folder_b_id => {:name=>"b", :parent => 0, :path => "/b"},
|
322
|
+
}
|
323
|
+
assert_equal ({}), @rs.folders_hierarchy!
|
324
|
+
end
|
325
|
+
|
326
|
+
should "work with invalid tree" do
|
327
|
+
# Create folders
|
328
|
+
folder_a_id = @rs.add_folder "/a"
|
329
|
+
assert_kind_of Integer, folder_a_id
|
330
|
+
assert_not_equal 0, folder_a_id
|
331
|
+
|
332
|
+
folder_b_id = @rs.add_folder "/a/b"
|
333
|
+
assert_kind_of Integer, folder_b_id
|
334
|
+
assert_not_equal 0, folder_b_id
|
335
|
+
|
336
|
+
folder_c_id = @rs.add_folder "/a/b/c"
|
337
|
+
assert_kind_of Integer, folder_c_id
|
338
|
+
assert_not_equal 0, folder_c_id
|
339
|
+
|
340
|
+
@rs.reload!
|
341
|
+
|
342
|
+
assert_true @rs.root_folder? folder_a_id
|
343
|
+
assert_false @rs.root_folder? folder_b_id
|
344
|
+
assert_false @rs.root_folder? folder_c_id
|
345
|
+
|
346
|
+
assert_false @rs.orphan? folder_a_id
|
347
|
+
assert_false @rs.orphan? folder_b_id
|
348
|
+
assert_false @rs.orphan? folder_c_id
|
349
|
+
|
350
|
+
# Delete just folder "/a" to accomplish tree inconsistency
|
351
|
+
@rs.delrealfolder :realfolder => folder_a_id
|
352
|
+
|
353
|
+
msg = "Directory tree consistency error. Parent folder ##{folder_a_id} for the folder \"/<undefined>/b\" [#{folder_b_id}] could not be found"
|
354
|
+
assert_raise_message(msg) do
|
355
|
+
@rs.reload! :validate => true
|
356
|
+
end
|
357
|
+
end
|
240
358
|
end
|
241
359
|
end
|
242
360
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rapidshare-ext
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-11-
|
12
|
+
date: 2012-11-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rapidshare
|
@@ -107,7 +107,7 @@ dependencies:
|
|
107
107
|
- - ! '>='
|
108
108
|
- !ruby/object:Gem::Version
|
109
109
|
version: '0'
|
110
|
-
description: Extends the
|
110
|
+
description: Extends the original rapidshare gem with a set of handy features
|
111
111
|
email:
|
112
112
|
- odiszapc@gmail.com
|
113
113
|
executables: []
|