rapidshare-ext 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/History.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## ver. 0.0.6 2012-11-25
2
+
3
+ * [changed] upload(): :overwrite parameter added
4
+
1
5
  ## ver. 0.0.5 2012-11-21
2
6
 
3
7
  * [fixed] remove_orphans!()
data/README.md CHANGED
@@ -28,7 +28,7 @@ api = Rapidshare::API.new(:cookie => 'cookie_here') # More preferable way
28
28
 
29
29
  ### Files
30
30
 
31
- Now you can perform file download in two ways: by the HTTP url or by the absolute path.
31
+ Now you can perform file downloading in two ways: by HTTP url or by absolute path.
32
32
 
33
33
  First, by the HTTP url, as it has worked before:
34
34
  ```ruby
@@ -41,7 +41,7 @@ First, by the HTTP url, as it has worked before:
41
41
  :downloads_dir => "/tmp"
42
42
  ```
43
43
 
44
- Download by absolute path:
44
+ Download by absolute path from account you owned:
45
45
  ```ruby
46
46
  @rs.download "/foo/bar/baz/upload_file_1.txt",
47
47
  :downloads_dir => "/tmp"
@@ -49,7 +49,7 @@ Download by absolute path:
49
49
 
50
50
  In both the first and second samples the result will be the same.
51
51
 
52
- File uploading became very simple now:
52
+ File uploading is also became very simple:
53
53
  ```ruby
54
54
  api.upload("/home/odiszapc/my_damn_cat.mov", :to => "/gallery/video", :as => "cat1.mov")
55
55
  # => {
@@ -68,11 +68,33 @@ result = api.upload("/home/odiszapc/my_damn_cat.mov", :to => "/gallery/video", :
68
68
  result[:url]
69
69
  ```
70
70
 
71
- By default, file is uploaded to the root folder:
71
+ By default, file is uploaded into the root folder:
72
72
  ```ruby
73
73
  api.upload("/home/odiszapc/my_damn_humster.mov")
74
74
  ```
75
75
 
76
+ Rapidshare allows to store multiple files having equal names under the same folder. I believe this behaviour is absolutely wrong.
77
+ Therefore, each time upload performed it checks if the file with the given name already exists in a folder.
78
+ If it's true, the upload() just returns info about the existing file with the :already_exists? flag is set to true without any real upload being performed.
79
+ To force file being overwritten set the :overwrite parameter to true:
80
+
81
+ ```ruby
82
+ api.upload "/home/odiszapc/my_damn_cat.mov",
83
+ :to => "/gallery/video",
84
+ :as => "cat1.mov"
85
+
86
+ # No upload will be performed
87
+ api.upload "/home/odiszapc/my_damn_cat.mov",
88
+ :to => "/gallery/video",
89
+ :as => "cat1.mov"
90
+
91
+ # With the following notation file will be uploaded with overwriting the existing one
92
+ api.upload "/home/odiszapc/my_damn_cat.mov",
93
+ :to => "/gallery/video",
94
+ :as => "cat1.mov",
95
+ :overwrite => true
96
+ ```
97
+
76
98
  Deleting files:
77
99
  ```ruby
78
100
  api.remove_file("/putin/is/a/good/reason/to/live/abroad/ticket_to_Nicaragua.jpg")
@@ -95,9 +117,9 @@ api.file_id("/foo/bar/baz.rar") # => <ID>
95
117
  ```
96
118
 
97
119
  ### Folders
98
- As you note you can have a hierarchy of folders in your account.
120
+ As you note it's possible having a hierarchy of folders in your account.
99
121
 
100
- Creating folders:
122
+ Creating folder hierarchy:
101
123
  ```ruby
102
124
  folder_id = api.add_folder "a/b/c" # => <FOLDER ID>
103
125
  ```
@@ -111,9 +133,9 @@ Moving folders:
111
133
  ```ruby
112
134
  api.move_folder("/a/b/c", :to => "/a")
113
135
  ```
114
- This moves folder "c" from directory "/a/b/" and places it under the directory "/a"
136
+ This moves the folder "c" from the directory "/a/b/" and places it under the directory "/a"
115
137
 
116
- Get the hierarchy of all folders in account:
138
+ You can get hierarchy of all the folders in account:
117
139
  ```ruby
118
140
  api.folders_hierarchy
119
141
  # => {
@@ -159,20 +181,20 @@ What does it mean? When you delete parent folder by its ID the folder will be de
159
181
  For example, let we have the basic directory tree:
160
182
  ```
161
183
  ROOT
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
184
+ `-a <- Raw Rapidshare API allows you to delete JUST THIS folder, so hierarchy relation between folders will be lost and the folders "c" and "b" will became orphans
163
185
  `-b
164
186
  `-c
165
187
  ```
166
188
 
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)
189
+ **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)
168
190
 
169
- So, the best way to delete some directory tree without washing away its consistency is the following:
191
+ So, the best way to delete a directory tree without washing away consistency of account folder hierarchy is the following:
170
192
  ```ruby
171
- api.remove_folder "/a" # This will correctly delete all child directories
193
+ api.remove_folder "/a" # This will delete all the child directories correctly
172
194
  ```
173
195
 
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:
196
+ However, if you already have orphans in your account there is possible to fix them.
197
+ So ,the next method detects all orphan folders in your account and moves them into a specific folder:
176
198
  ```ruby
177
199
  api.move_orphans :to => "/"
178
200
  ```
@@ -188,7 +210,7 @@ You can null your account by deleting all the data stored inside:
188
210
  api.erase_all_data!
189
211
  ```
190
212
 
191
- **Be careful with it, because all you lose all your data**
213
+ **Be careful with it, because you stake losing all your data**
192
214
 
193
215
  ## Contributing
194
216
 
@@ -113,6 +113,8 @@ module Rapidshare
113
113
  # Folder to place uploaded file to, default: "/"
114
114
  # <tt>:as</tt>::
115
115
  # The name file will have in storage after it has been uploaded
116
+ # <tt>:overwrite</tt>::
117
+ # Overwrite file if it already exists in the given folder
116
118
  #
117
119
  # api.upload("/home/odiszapc/my_damn_cat.mov", :to => "/gallery/video", :as => "cat1.mov")
118
120
  def upload(file_path, params = {})
@@ -120,6 +122,7 @@ module Rapidshare
120
122
  dest_path = path_trim(params.delete(:to) || '/')
121
123
  folder_id = self.add_folder dest_path
122
124
  file_name = params.delete(:as) || File.basename(file_path)
125
+ overwrite = params.delete :overwrite
123
126
 
124
127
  # Check file already exists within a folder
125
128
  listfiles_params = {
@@ -130,11 +133,14 @@ module Rapidshare
130
133
  }
131
134
  listfiles_response = self.listfiles listfiles_params
132
135
 
133
- # In case of file is not existing upload it
134
- if "NONE" == listfiles_response[0][0]
136
+ file_already_exists = ("NONE" != listfiles_response[0][0])
137
+ remove_file "#{dest_path}/#{file_name}" if file_already_exists && overwrite
138
+
139
+ # In case of file is not existing then upload it
140
+ if !file_already_exists || overwrite
135
141
  upload_server = "rs#{self.nextuploadserver}.rapidshare.com"
136
142
 
137
- upload_params = {
143
+ upload_params = {
138
144
  :server => upload_server,
139
145
  :folder => folder_id,
140
146
  :filename => file_name,
@@ -1,5 +1,5 @@
1
1
  module Rapidshare
2
2
  module Ext
3
- VERSION = "0.0.5"
3
+ VERSION = "0.0.6"
4
4
  end
5
5
  end
@@ -0,0 +1 @@
1
+ Another file to test upload
@@ -17,6 +17,10 @@ class RapidshareExtTest < Test::Unit::TestCase
17
17
  @upload_file_1 = File.expand_path(File.dirname(__FILE__) + "/../fixtures/files/upload1.txt")
18
18
  @upload_file_1_md5 = Digest::MD5.hexdigest(File.read(@upload_file_1))
19
19
  @upload_file_1_size = File.size @upload_file_1
20
+
21
+ @upload_file_2 = File.expand_path(File.dirname(__FILE__) + "/../fixtures/files/upload2.txt")
22
+ @upload_file_2_md5 = Digest::MD5.hexdigest(File.read(@upload_file_2))
23
+ @upload_file_2_size = File.size @upload_file_2
20
24
  end
21
25
 
22
26
  context "Api" do
@@ -58,8 +62,17 @@ class RapidshareExtTest < Test::Unit::TestCase
58
62
 
59
63
  # Upload the same file again
60
64
  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
62
65
  assert_true response[:already_exists?]
66
+ upload_assertion.call response, @upload_file_1_size, @upload_file_1_md5, remote_filename
67
+
68
+ # Upload another file under the same path but with overwriting the existing one
69
+ response = @rs.upload @upload_file_2,
70
+ :to => remote_dir,
71
+ :as => remote_filename,
72
+ :overwrite => true
73
+
74
+ assert_false response[:already_exists?]
75
+ upload_assertion.call response, @upload_file_2_size, @upload_file_2_md5, remote_filename
63
76
  end
64
77
 
65
78
  should "download file" do
@@ -354,6 +367,9 @@ class RapidshareExtTest < Test::Unit::TestCase
354
367
  assert_raise_message(msg) do
355
368
  @rs.reload! :validate => true
356
369
  end
370
+
371
+ # Remedy
372
+ @rs.erase_all_data!
357
373
  end
358
374
  end
359
375
  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.5
4
+ version: 0.0.6
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-21 00:00:00.000000000 Z
12
+ date: 2012-11-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rapidshare
@@ -128,6 +128,7 @@ files:
128
128
  - lib/rapidshare-ext/version.rb
129
129
  - rapidshare-ext.gemspec
130
130
  - test/fixtures/files/upload1.txt
131
+ - test/fixtures/files/upload2.txt
131
132
  - test/fixtures/getaccountdetails_valid.txt
132
133
  - test/integration/rapidshare-ext_test.rb
133
134
  - test/test_helper.rb
@@ -160,6 +161,7 @@ summary: ! 'Makes your interactions with Rapidshare API more pleasant by providi
160
161
  upload files, etc'
161
162
  test_files:
162
163
  - test/fixtures/files/upload1.txt
164
+ - test/fixtures/files/upload2.txt
163
165
  - test/fixtures/getaccountdetails_valid.txt
164
166
  - test/integration/rapidshare-ext_test.rb
165
167
  - test/test_helper.rb