rapidshare-ext 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/History.md CHANGED
@@ -1,3 +1,19 @@
1
+ ## ver.0.0.3 2012-11-19
2
+
3
+ * [added] Downloading files by absolute path
4
+ * [added] File download url added to the return hash of file_info(). Url is represented by the :url key
5
+ * [changed] Folder pathes now have leading slash
6
+ * [fixed] Base gem download functional didn't work when use :save_as param because of API changes month ago
7
+ * [changed] Integration file uploading test refactored
8
+
9
+ It has began. We have the features as follows:
10
+
11
+ * [added] Creating folders
12
+
13
+ ## ver.0.0.2 2012-11-18
14
+
15
+ Technical release. No features, no bug fixes.
16
+
1
17
  ## ver.0.0.1 2012-11-17
2
18
 
3
19
  It has began. We have the features as follows:
data/README.md CHANGED
@@ -65,7 +65,7 @@ So, if you want to invalidate the cache just call the above method with trailing
65
65
  api.folders_hierarchy!
66
66
  ```
67
67
 
68
- If folder tree is inconsistent (orphans are found) the Exception will be thrown. To automatically normalize the tree, call the method with :consistent flag:
68
+ If folder tree is inconsistent (orphans are found, see next paragraph for details) the Exception will be thrown. To automatically normalize the tree, call the method with :consistent flag:
69
69
  ```ruby
70
70
  api.folders_hierarchy :consistent => true
71
71
  ```
@@ -79,25 +79,35 @@ tree = api.folders_hierarchy
79
79
  ```
80
80
 
81
81
  ### Orphans
82
- Ok, the Rapidshare has its common problem: orphan folders. What is this? For example we have the following directory tree:
82
+ As mentioned before, the Rapidshare has its common problem: orphan folders.
83
+ What does it mean? When you delete parent folder by its ID then it will be deleted without any of its child folders being deleted.
84
+ For example, lets we have the basic directory tree:
83
85
  ```
84
86
  ROOT
85
87
  `-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
86
88
  `-b
87
89
  `-c
88
90
  ```
89
- Orphans is invisible in your File Manager on the Rapidshare web site, so you may want to hide data in that way (stupid idea)
90
- We can fix it by detecting all orphan folders and moving them to a specific folder:
91
+
92
+ Orphan folders are invisible in your File Manager on the Rapidshare web site, so you may want to hide data in that way (stupid idea)
93
+
94
+ So, the best way to delete directory tree without washing away its consistency is the following:
95
+ ```ruby
96
+ api.remove_folder "/a"
97
+ ```
98
+
99
+ Buy if you already have orphans in your account there is possible to fix them.
100
+ The next method detects all orphan folders in your account and moves them to a specific folder:
91
101
  ```ruby
92
102
  move_orphans :to => "/"
93
103
  ```
94
104
 
95
- Or we can just kill'em all:
105
+ Or we can just delete all of them (be careful):
96
106
  ```ruby
97
107
  remove_orphans!
98
108
  ```
99
109
 
100
- Get folder ID or path:
110
+ Get the folder ID or path:
101
111
  ```ruby
102
112
  id = api.folder_id("/foo/bar") # <ID>
103
113
  api.folder_path(id) # "/foo/bar"
@@ -105,7 +115,28 @@ api.folder_path(id) # "/foo/bar"
105
115
 
106
116
  ### Files
107
117
 
108
- File uploading is simple now:
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:
109
140
  ```ruby
110
141
  api.upload("/home/odiszapc/my_damn_cat.mov", :to => "/gallery/video", :as => "cat1.mov")
111
142
  # => {
@@ -116,8 +147,9 @@ api.upload("/home/odiszapc/my_damn_cat.mov", :to => "/gallery/video", :as => "ca
116
147
  # :already_exists? => true/false # Does the file already exists within a specific folder, real uploading will not being performed in this case
117
148
  #}
118
149
  ```
150
+ Destination folder will be created automatically.
119
151
  After uploading has been completed the file will be stored in a Rapidshare as "/gallery/video/cat1.mov"
120
- To get download url after uploading:
152
+ You can easily get a download url after uploading:
121
153
  ```ruby
122
154
  result = api.upload("/home/odiszapc/my_damn_cat.mov", :to => "/gallery/video", :as => "cat1.mov")
123
155
  result[:url]
@@ -130,7 +162,7 @@ api.upload("/home/odiszapc/my_damn_humster.mov")
130
162
 
131
163
  Deleting files:
132
164
  ```ruby
133
- api.remove_file("/putin/is/a/good/reason/to/live/abroad/ticket_to_Nikaragua.jpg")
165
+ api.remove_file("/putin/is/a/good/reason/to/live/abroad/ticket_to_Nicaragua.jpg")
134
166
  ```
135
167
 
136
168
  Renaming files:
@@ -144,13 +176,13 @@ api.move_file("/foo/bar/baz.rar", :to => "/foo") # new file path: "/foo/baz.rar"
144
176
  api.move_file("/foo/bar/baz.rar") # move to a root folder
145
177
  ```
146
178
 
147
- Get file ID:
179
+ Get the file ID:
148
180
  ```ruby
149
181
  api.file_id("/foo/bar/baz.rar") # => <ID>
150
182
  ```
151
183
 
152
184
  ### Account
153
- You can null your account by deleting all data involved. Be carefull with it, all data will be lost:
185
+ You can null your account by deleting all data stored inside. Be careful with it, because all you los all your data:
154
186
  ```ruby
155
187
  api.erase_all_data!
156
188
  ```
@@ -57,5 +57,15 @@ module Rapidshare
57
57
 
58
58
  self.parse_response(parser, response)
59
59
  end
60
+
61
+ def download(file, params= {})
62
+ if file.match /\Ahttps?:\/\//
63
+ url = file
64
+ else
65
+ url = file_info(file)[:url]
66
+ end
67
+
68
+ Rapidshare::Ext::Download.new(url, self, params).perform
69
+ end
60
70
  end
61
71
  end
@@ -12,6 +12,8 @@ module Rapidshare
12
12
  #
13
13
  # api.add_folder("/a/b/c") #=> <Random folder ID from Rapidshare>, 1234 for example
14
14
  def add_folder(path, params = {})
15
+ path = path_trim path
16
+
15
17
  @tree = folders_hierarchy
16
18
  i = 1
17
19
  parent = 0
@@ -36,7 +38,7 @@ module Rapidshare
36
38
  @tree[folder_id] = {
37
39
  :parent => parent,
38
40
  :name => folder_name,
39
- :path => (@tree[parent] || {})[:path].to_s + ('/' if @tree[parent]).to_s + folder_name
41
+ :path => path_canonize((@tree[parent] || {})[:path].to_s + ('/' if @tree[parent]).to_s + folder_name)
40
42
  }
41
43
  parent = folder_id
42
44
  path == base_path + '/' + folder_name
@@ -86,7 +88,7 @@ module Rapidshare
86
88
  #
87
89
  # api.move_folder("/a/b/c", :to => "/a")
88
90
  def move_folder(source_path, params = {})
89
- dest_path = path_trim(params.delete(:to) || '/')
91
+ dest_path = (params.delete(:to) || '/')
90
92
  source_folder_id = folder_id(source_path)
91
93
  dest_folder_id = folder_id(dest_path)
92
94
 
@@ -99,7 +101,7 @@ module Rapidshare
99
101
 
100
102
  @tree = folders_hierarchy
101
103
  @tree[source_folder_id][:parent] = dest_folder_id
102
- @tree[source_folder_id][:path] = "#{folder_path(dest_folder_id)}/#{@tree[source_folder_id][:name]}"
104
+ @tree[source_folder_id][:path] = path_canonize "#{folder_path(dest_folder_id)}/#{@tree[source_folder_id][:name]}"
103
105
  true
104
106
  end
105
107
 
@@ -261,6 +263,7 @@ module Rapidshare
261
263
  end
262
264
 
263
265
  return @tree if @tree && !force_load # TODO: about slices here (:from parameter)
266
+ @tree = {}
264
267
 
265
268
  from_folder_id = folder_id from_folder_path
266
269
  raise Exception, "Folder #{from_folder_path} could not be found" if from_folder_id.nil?
@@ -322,12 +325,12 @@ module Rapidshare
322
325
  unless from_folder_path == ''
323
326
 
324
327
  result_tree.keep_if do |folder_id, data|
325
- data[:path].start_with? "#{from_folder_path}/"
328
+ path_trim(data[:path]).start_with? "#{from_folder_path}/"
326
329
  end
327
330
 
328
331
  result_tree.each_pair do |folder_id, data|
329
332
  path = result_tree[folder_id][:path]
330
- result_tree[folder_id][:path] = path.gsub /#{from_folder_path.gsub /\//, '\/'}\//, ''
333
+ result_tree[folder_id][:path] = path_canonize path_trim(path.gsub /#{from_folder_path.gsub /\//, '\/'}\//, '')
331
334
  end
332
335
  end
333
336
 
@@ -416,7 +419,8 @@ module Rapidshare
416
419
  def folder_path(folder_id)
417
420
  @tree = folders_hierarchy
418
421
  parent_id = @tree[folder_id][:parent]
419
- (folder_path(parent_id) if parent_id.nonzero?).to_s + ('/' if parent_id.nonzero?).to_s + @tree[folder_id][:name]
422
+ path = (folder_path(parent_id) if parent_id.nonzero?).to_s + ('/' if parent_id.nonzero?).to_s + @tree[folder_id][:name]
423
+ parent_id.zero? ? "/#{path}" : path
420
424
  end
421
425
 
422
426
  # Get folder ID by path
@@ -428,7 +432,7 @@ module Rapidshare
428
432
 
429
433
  @tree = folders_hierarchy
430
434
  index = @tree.find_index do |folder_id, data|
431
- data[:path] == folder_path
435
+ path_trim(data[:path]) == path_trim(folder_path)
432
436
  end
433
437
  @tree.keys[index] unless index.nil?
434
438
  end
@@ -477,12 +481,14 @@ module Rapidshare
477
481
  response[value.to_sym] = resp[index]
478
482
  end
479
483
 
484
+ response[:url] = "https://rapidshare.com/files/#{response[:id]}/#{URI::encode response[:filename]}" if response[:filename]
485
+
480
486
  response
481
487
  end
482
488
 
483
- # Get file ID by absolute path
489
+ # Returns file ID by absolute path
484
490
  #
485
- # api.file_id("foo/bar/baz/file.rar") # -> 456
491
+ # api.file_id("foo/bar/baz/file.rar") # => <FILE_ID>
486
492
  def file_id(file_path, params = {})
487
493
  params[:fields] = ""
488
494
  file_info = file_info file_path, params
@@ -494,6 +500,10 @@ module Rapidshare
494
500
  def path_trim(path)
495
501
  path.gsub(/\A\/+/, '').gsub(/\/+\Z/, '')
496
502
  end
503
+
504
+ def path_canonize(path)
505
+ "/" + path_trim(path)
506
+ end
497
507
  end
498
508
  end
499
509
  end
@@ -0,0 +1,47 @@
1
+ module Rapidshare
2
+ module Ext
3
+
4
+ # Note from odiszapc:
5
+ #
6
+ # 1 oct 2012 the Rapidshare download API (http://images.rapidshare.com/apidoc.txt) was changed
7
+ # so the base download function provided by rapidshare gem became broken
8
+ #
9
+ # In the original method the parameter :filename being interpreted incorrectly now.
10
+ # It's being interpreted like a "save file as" parameter. Actually it must be equal to the file name you want to download
11
+ # So, to download file now you must specify exactly two parameters: file id and file name.
12
+ class Download < Rapidshare::Download
13
+
14
+ # Options:
15
+ # * *filename* (optional) - specifies filename under which the file will be
16
+ # saved. Default: filename parsed from Rapidshare link.
17
+ # * *downloads_dir* (optional) - specifies directory into which downloaded files
18
+ # will be saved. Default: current directory.
19
+ #
20
+ def initialize(url, api, options = {})
21
+ super
22
+ @local_filename = options[:save_as]
23
+ @filename = nil # It will be filled automatically by the #check method of the base class
24
+ end
25
+
26
+ # Checks if file exists (using checkfiles service) and gets data necessary for download.
27
+ #
28
+ # Returns true or false, which determines whether the file can be downloaded.
29
+ #
30
+ def check
31
+ res = super
32
+ if res
33
+ @remote_filename = @filename
34
+ @filename = @local_filename || @remote_filename
35
+ end
36
+ res
37
+ end
38
+
39
+ # Generates link which downloads file by Rapidshare API
40
+ #
41
+ def download_link
42
+ download_params = { :sub => 'download', :fileid => @fileid, :filename => @remote_filename, :cookie => @api.cookie }
43
+ DOWNLOAD_URL % [ @server_id, @short_host, download_params.to_query ]
44
+ end
45
+ end
46
+ end
47
+ end
@@ -1,5 +1,5 @@
1
1
  module Rapidshare
2
2
  module Ext
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3"
4
4
  end
5
5
  end
@@ -3,6 +3,7 @@ require "rapidshare"
3
3
  require "rapidshare-base/utils"
4
4
  require "rapidshare-base/api"
5
5
  require "rapidshare-ext/api"
6
+ require "rapidshare-ext/download"
6
7
  require "rapidshare-ext/version"
7
8
 
8
9
  class Rapidshare::API
@@ -4,7 +4,6 @@ require File.expand_path('../lib/rapidshare-ext/version', __FILE__)
4
4
  Gem::Specification.new do |gem|
5
5
  gem.name = "rapidshare-ext"
6
6
  gem.version = Rapidshare::Ext::VERSION
7
- gem.date = '2012-11-18'
8
7
  gem.authors = ["odiszapc"]
9
8
  gem.email = ["odiszapc@gmail.com"]
10
9
  gem.description = %q{Extends the base rapidshare gem with a set of handy features}
@@ -8,11 +8,20 @@ class RapidshareExtTest < Test::Unit::TestCase
8
8
  FakeWeb.allow_net_connect = true
9
9
  @rs = Rapidshare::API.new :cookie => ENV['RAPIDSHARE_COOKIE']
10
10
  @rs.erase_all_data!
11
+
12
+ @download_dir = File.expand_path(File.dirname(__FILE__) + "/../../tmp")
13
+ File.delete "#@download_dir/file1.txt" if File.exist? "#@download_dir/file1.txt"
14
+ File.delete "#@download_dir/file2.txt" if File.exist? "#@download_dir/file2.txt"
15
+ File.delete "#@download_dir/upload_file_1.txt" if File.exist? "#@download_dir/upload_file_1.txt"
16
+
17
+ @upload_file_1 = File.expand_path(File.dirname(__FILE__) + "/../fixtures/files/upload1.txt")
18
+ @upload_file_1_md5 = Digest::MD5.hexdigest(File.read(@upload_file_1))
19
+ @upload_file_1_size = File.size @upload_file_1
11
20
  end
12
21
 
13
22
  context "Api" do
14
23
  should "Upload file" do
15
- assertion = ->(resp, size_local, digest_local, remote_filename) do
24
+ upload_assertion = ->(resp, size_local, digest_local, remote_filename) do
16
25
  assert_instance_of Hash, resp
17
26
  assert_kind_of Integer, resp[:id]
18
27
  assert_kind_of Integer, resp[:size]
@@ -24,24 +33,13 @@ class RapidshareExtTest < Test::Unit::TestCase
24
33
  assert_equal "https://rapidshare.com/files/#{resp[:id]}/#{URI::encode(remote_filename)}", resp[:url]
25
34
  end
26
35
 
27
- file_info_assertion = ->(info, file_id, digest_local, size_local, remote_filename, remote_dir) do
28
- assert_equal info[:filename], remote_filename
29
- assert_equal info[:id].to_i, file_id
30
- assert_equal info[:md5hex].downcase, digest_local
31
- assert_equal info[:realfolder].to_i, @rs.folder_id(remote_dir)
32
- assert_equal info[:size].to_i, size_local
33
- end
34
-
35
- local_path = File.expand_path(File.dirname(__FILE__) + "/../fixtures/files/upload1.txt")
36
36
  remote_filename = "upload_file_1.txt"
37
37
  remote_dir = "a/b/c"
38
38
  remote_path = "#{remote_dir}/#{remote_filename}"
39
- digest_local = Digest::MD5.hexdigest(File.read(local_path))
40
- size_local = File.size local_path
41
39
 
42
40
  # Initial upload
43
- response = @rs.upload local_path, :as => remote_filename, :to => remote_dir
44
- assertion.call response, size_local, digest_local, remote_filename
41
+ response = @rs.upload @upload_file_1, :as => remote_filename, :to => remote_dir
42
+ upload_assertion.call response, @upload_file_1_size, @upload_file_1_md5, remote_filename
45
43
  assert_false response[:already_exists?]
46
44
 
47
45
  # Check file ID
@@ -51,33 +49,83 @@ class RapidshareExtTest < Test::Unit::TestCase
51
49
 
52
50
  # Check file info
53
51
  info = @rs.file_info remote_path
54
- file_info_assertion.call info, file_id, digest_local, size_local, remote_filename, remote_dir
52
+ assert_not_nil info
53
+ assert_equal info[:filename], remote_filename
54
+ assert_equal info[:id].to_i, file_id
55
+ assert_equal info[:size].to_i, @upload_file_1_size
56
+ assert_equal info[:md5hex].downcase, @upload_file_1_md5
57
+ assert_equal info[:realfolder].to_i, @rs.folder_id(remote_dir)
55
58
 
56
59
  # Upload the same file again
57
- response = @rs.upload local_path, :as => remote_filename, :to => remote_dir
58
- assertion.call response, size_local, digest_local, remote_filename
60
+ response = @rs.upload @upload_file_1, :to => remote_dir, :as => remote_filename
61
+ upload_assertion.call response, @upload_file_1_size, @upload_file_1_md5, remote_filename
59
62
  assert_true response[:already_exists?]
63
+ end
64
+
65
+ should "Download file" do
66
+ @rs.upload @upload_file_1, :to => "/a/b/c", :as => "upload_file_1.txt"
67
+ assert_not_nil @rs.file_info("/a/b/c/upload_file_1.txt")
68
+
69
+ @rs.download "/a/b/c/upload_file_1.txt", :downloads_dir => @download_dir, :save_as => "file1.txt"
70
+ assert_path_exist "#@download_dir/file1.txt"
71
+ assert_equal @upload_file_1_size, File.size("#@download_dir/file1.txt")
72
+ assert_equal @upload_file_1_md5, Digest::MD5.hexdigest(File.read("#@download_dir/file1.txt"))
73
+
74
+ # Download with default :save_as
75
+ @rs.download "/a/b/c/upload_file_1.txt", :downloads_dir => @download_dir
76
+ assert_path_exist "#@download_dir/upload_file_1.txt"
77
+ assert_equal @upload_file_1_size, File.size("#@download_dir/upload_file_1.txt")
78
+ assert_equal @upload_file_1_md5, Digest::MD5.hexdigest(File.read("#@download_dir/upload_file_1.txt"))
79
+
80
+ # Download by http url
81
+ download_url = @rs.file_info("/a/b/c/upload_file_1.txt")[:url]
82
+ @rs.download download_url, :downloads_dir => @download_dir, :save_as => "file2.txt"
83
+ assert_path_exist "#@download_dir/file2.txt"
84
+ assert_equal @upload_file_1_size, File.size("#@download_dir/file2.txt")
85
+ assert_equal @upload_file_1_md5, Digest::MD5.hexdigest(File.read("#@download_dir/file2.txt"))
86
+ end
87
+
88
+ should "Rename file" do
89
+ @rs.upload @upload_file_1, :to => "/a/b/c", :as => "upload_file_1.txt"
90
+ assert_not_nil @rs.file_info("/a/b/c/upload_file_1.txt")
91
+
92
+ @rs.rename_file "/a/b/c/upload_file_1.txt", "file_2.txt"
93
+ info = @rs.file_info "/a/b/c/file_2.txt"
60
94
 
61
- # Rename file
62
- remote_filename_2 ="foo.txt"
63
- remote_path_2 = "#{remote_dir}/#{remote_filename_2}"
64
- @rs.rename_file remote_path, remote_filename_2
65
- info = @rs.file_info remote_path_2
66
- file_info_assertion.call info, @rs.file_id(remote_path_2), digest_local, size_local, remote_filename_2, remote_dir
95
+ assert_not_nil info
96
+ assert_equal info[:filename], "file_2.txt"
97
+ assert_equal info[:realfolder].to_i, @rs.folder_id("/a/b/c")
98
+ assert_equal info[:size].to_i, @upload_file_1_size
99
+ assert_equal info[:md5hex].downcase, @upload_file_1_md5
100
+ end
101
+
102
+ should "Move file" do
103
+ @rs.upload @upload_file_1, :to => "/a/b/c", :as => "upload_file_1.txt"
104
+ assert_not_nil @rs.file_info("/a/b/c/upload_file_1.txt")
67
105
 
68
- # Move file
69
- remote_dir_3 = "a/b"
70
- remote_path_3 = "#{remote_dir_3}/#{remote_filename_2}"
71
- @rs.move_file remote_path_2, :to => remote_dir_3
106
+ @rs.move_file "/a/b/c/upload_file_1.txt", :to => "/a/b"
107
+ assert_nil @rs.file_info("/a/b/c/upload_file_1.txt")
72
108
 
73
- info = @rs.file_info remote_path_3
74
- file_info_assertion.call info, @rs.file_id(remote_path_3), digest_local, size_local, remote_filename_2, remote_dir_3
109
+ info = @rs.file_info "/a/b/upload_file_1.txt"
110
+ assert_not_nil info
111
+ assert_equal info[:filename], "upload_file_1.txt"
112
+ assert_equal info[:realfolder].to_i, @rs.folder_id("/a/b")
113
+ assert_equal info[:size].to_i, @upload_file_1_size
114
+ assert_equal info[:md5hex].downcase, @upload_file_1_md5
115
+ end
75
116
 
76
- # Delete file
77
- @rs.remove_file remote_path_3
117
+ should "Delete file" do
118
+ @rs.upload @upload_file_1, :to => "/a/b/c", :as => "upload_file_1.txt"
119
+ assert_not_nil @rs.file_info("/a/b/c/upload_file_1.txt")
78
120
 
79
- info = @rs.file_info remote_path_3
80
- assert_nil info
121
+ @rs.remove_file "/a/b/c/upload_file_1.txt"
122
+ assert_nil @rs.file_info("/a/b/c/upload_file_1.txt")
123
+ end
124
+
125
+ should "Folder id <=> path conversions" do
126
+ @rs.add_folder "/a/b/c"
127
+ id = @rs.folder_id("/a/b/c")
128
+ assert_equal "/a/b/c", @rs.folder_path(id)
81
129
  end
82
130
 
83
131
  should "Create folder" do
@@ -87,48 +135,29 @@ class RapidshareExtTest < Test::Unit::TestCase
87
135
  tree = @rs.folders_hierarchy
88
136
 
89
137
  assert_equal 3, tree.count
90
- assert_equal "a/b/c", tree[folder_id][:path]
91
- assert_equal "a/b", tree[tree[folder_id][:parent]][:path]
92
- assert_equal "a", tree[tree[tree[folder_id][:parent]][:parent]][:path]
138
+ assert_equal "/a/b/c", tree[folder_id][:path]
139
+ assert_equal "/a/b", tree[tree[folder_id][:parent]][:path]
140
+ assert_equal "/a", tree[tree[tree[folder_id][:parent]][:parent]][:path]
93
141
  end
94
142
 
95
143
  should "Move folder" do
96
- folder_id = @rs.add_folder "a/b/c"
144
+ folder_id = @rs.add_folder "/a/b/c"
97
145
  assert_kind_of Integer, folder_id
98
146
  assert_not_equal 0, folder_id
99
147
  tree = @rs.folders_hierarchy
100
148
 
101
149
  assert_equal 3, tree.count
102
- assert_equal "a/b/c", tree[folder_id][:path]
103
- assert_equal "a/b", tree[tree[folder_id][:parent]][:path]
104
- assert_equal "a", tree[tree[tree[folder_id][:parent]][:parent]][:path]
150
+ assert_equal "/a/b/c", tree[folder_id][:path]
151
+ assert_equal "/a/b", tree[tree[folder_id][:parent]][:path]
152
+ assert_equal "/a", tree[tree[tree[folder_id][:parent]][:parent]][:path]
105
153
 
106
- @rs.move_folder "a/b/c", :to => 'a'
154
+ @rs.move_folder "/a/b/c", :to => 'a'
107
155
 
108
156
  tree = @rs.reload!
109
157
 
110
158
  assert_equal 3, tree.count
111
- assert_equal "a/c", tree[folder_id][:path]
112
- assert_equal @rs.folder_id("a"), tree[folder_id][:parent]
113
- end
114
-
115
- should "Build folder tree" do
116
- # Create folder
117
- folder_id = @rs.add_folder "a/b/c"
118
- assert_kind_of Integer, folder_id
119
- assert_not_equal 0, folder_id
120
- tree = @rs.folders_hierarchy
121
-
122
- # Validate tree
123
- assert_equal 3, tree.count
124
- assert_equal "a/b/c", tree[folder_id][:path]
125
- assert_equal "a/b", tree[tree[folder_id][:parent]][:path]
126
- assert_equal "a", tree[tree[tree[folder_id][:parent]][:parent]][:path]
127
-
128
- # Validate subtree
129
- sub_tree = @rs.folders_hierarchy :from => 'a/b'
130
- assert_equal 1, sub_tree.count
131
- assert_equal "c", sub_tree[folder_id][:path]
159
+ assert_equal "/a/c", tree[folder_id][:path]
160
+ assert_equal @rs.folder_id("/a"), tree[folder_id][:parent]
132
161
  end
133
162
 
134
163
  should "Remove folder" do
@@ -138,25 +167,65 @@ class RapidshareExtTest < Test::Unit::TestCase
138
167
  tree = @rs.folders_hierarchy
139
168
  assert_equal 3, tree.count
140
169
 
141
- @rs.remove_folder "a/b/c"
170
+ @rs.remove_folder "/a/b/c"
142
171
 
143
172
  tree = @rs.folders_hierarchy!
144
173
  assert_equal 2, tree.count
145
174
 
146
175
 
147
- folder_id = @rs.add_folder "a/b/c"
176
+ folder_id = @rs.add_folder "/a/b/c"
148
177
  assert_kind_of Integer, folder_id
149
178
  assert_not_equal 0, folder_id
150
179
  tree = @rs.folders_hierarchy!
151
180
  assert_equal 3, tree.count
152
181
 
153
- @rs.remove_folder "a"
182
+ @rs.remove_folder "/a"
154
183
  tree = @rs.folders_hierarchy!
155
184
  assert_equal 0, tree.count
156
185
  end
157
186
 
158
- should "Erase account" do
159
- folder_id = @rs.add_folder "a/b/c"
187
+
188
+ should "Build folders tree" do
189
+ # Create folders
190
+ folder_a_id = @rs.add_folder "/a"
191
+ assert_kind_of Integer, folder_a_id
192
+ assert_not_equal 0, folder_a_id
193
+
194
+ folder_b_id = @rs.add_folder "/a/b"
195
+ assert_kind_of Integer, folder_b_id
196
+ assert_not_equal 0, folder_b_id
197
+
198
+ folder_c_id = @rs.add_folder "/a/b/c"
199
+ assert_kind_of Integer, folder_c_id
200
+ assert_not_equal 0, folder_c_id
201
+
202
+
203
+ tree = @rs.folders_hierarchy
204
+ # Validate tree
205
+ assert_equal 3, tree.count
206
+
207
+ assert_equal "a", tree[folder_a_id][:name]
208
+ assert_equal "/a", tree[folder_a_id][:path]
209
+ assert_equal 0, tree[folder_a_id][:parent]
210
+
211
+ assert_equal "b", tree[folder_b_id][:name]
212
+ assert_equal "/a/b", tree[folder_b_id][:path]
213
+ assert_equal folder_a_id, tree[folder_b_id][:parent]
214
+
215
+ assert_equal "c", tree[folder_c_id][:name]
216
+ assert_equal "/a/b/c", tree[folder_c_id][:path]
217
+ assert_equal folder_b_id, tree[folder_c_id][:parent]
218
+
219
+ # Validate subtree
220
+ sub_tree = @rs.folders_hierarchy :from => '/a/b'
221
+ assert_equal 1, sub_tree.count
222
+ assert_equal "/c", sub_tree[folder_c_id][:path]
223
+ assert_equal "c", sub_tree[folder_c_id][:name]
224
+ assert_equal folder_b_id, sub_tree[folder_c_id][:parent]
225
+ end
226
+
227
+ should "Erase all account data" do
228
+ folder_id = @rs.add_folder "/a/b/c"
160
229
  assert_kind_of Integer, folder_id
161
230
 
162
231
  folder_ids = @rs.folders_hierarchy.keys
data/test/test_helper.rb CHANGED
@@ -37,4 +37,8 @@ class Test::Unit::TestCase
37
37
  @rs = Rapidshare::API.new(:login => 'valid_login', :password => 'valid_password')
38
38
  end
39
39
 
40
+ def upload local_path, remote_filename, remote_dir
41
+
42
+ end
43
+
40
44
  end
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.2
4
+ version: 0.0.3
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-18 00:00:00.000000000 Z
12
+ date: 2012-11-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rapidshare
@@ -124,6 +124,7 @@ files:
124
124
  - lib/rapidshare-base/utils.rb
125
125
  - lib/rapidshare-ext.rb
126
126
  - lib/rapidshare-ext/api.rb
127
+ - lib/rapidshare-ext/download.rb
127
128
  - lib/rapidshare-ext/version.rb
128
129
  - rapidshare-ext.gemspec
129
130
  - test/fixtures/files/upload1.txt