rapidshare-ext 0.0.6 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +16 -17
- data/History.md +8 -0
- data/README.md +243 -221
- data/Rakefile +3 -3
- data/lib/rapidshare-base/api.rb +136 -6
- data/lib/rapidshare-base/utils.rb +39 -0
- data/lib/rapidshare-ext.rb +17 -11
- data/lib/rapidshare-ext/api.rb +531 -531
- data/lib/rapidshare-ext/download.rb +79 -7
- data/lib/rapidshare-ext/version.rb +5 -5
- data/rapidshare-ext.gemspec +11 -10
- data/test/fixtures/checkfiles_multi.txt +3 -0
- data/test/fixtures/checkfiles_single.txt +1 -0
- data/test/fixtures/files/upload3.txt +100 -0
- data/test/fixtures/getrapidtranslogs.txt +5 -0
- data/test/integration/rapidshare-base_test.rb +278 -0
- data/test/integration/rapidshare-ext_test.rb +176 -95
- data/test/test_helper.rb +43 -43
- data/test/unit/rapidshare-ext_test.rb +27 -27
- data/tmp/.gitignore +2 -0
- metadata +56 -29
data/.gitignore
CHANGED
@@ -1,18 +1,17 @@
|
|
1
|
-
*.gem
|
2
|
-
*.rbc
|
3
|
-
.bundle
|
4
|
-
.config
|
5
|
-
.yardoc
|
6
|
-
Gemfile.lock
|
7
|
-
InstalledFiles
|
8
|
-
_yardoc
|
9
|
-
coverage
|
10
|
-
doc/
|
11
|
-
lib/bundler/man
|
12
|
-
pkg
|
13
|
-
rdoc
|
14
|
-
spec/reports
|
15
|
-
test/tmp
|
16
|
-
test/version_tmp
|
17
|
-
tmp
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
18
17
|
.idea/*
|
data/History.md
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
## ver. 0.1.0 2012-01-25
|
2
|
+
* [added] Ability to injecting into the file download process and implementing custom progress bar functionality
|
3
|
+
* [changed] Rid of original rapidshare gem dependency which was not supported for 5 months. Gem have become standalone now.
|
4
|
+
* [changed] Remove Curl lib dependency which could cause a problem on Windows machines.
|
5
|
+
* [changed] Remove Progressbar gem dependency against api for implementing custom progress bars
|
6
|
+
* [changed] File downloading works through native Ruby HTTP libraries using RestClient
|
7
|
+
* [changed] Integration test have been greatly improved and original gem tests have been included to increase coverage
|
8
|
+
|
1
9
|
## ver. 0.0.6 2012-11-25
|
2
10
|
|
3
11
|
* [changed] upload(): :overwrite parameter added
|
data/README.md
CHANGED
@@ -1,222 +1,244 @@
|
|
1
|
-
# Rapidshare::Ext
|
2
|
-
|
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
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
api = Rapidshare::API.new(:
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
:
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
#
|
58
|
-
#
|
59
|
-
#
|
60
|
-
|
61
|
-
#
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
```
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
```
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
```
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
```
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
```
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
#
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
```
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
```
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
```
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
```
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
```
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
1
|
+
# Rapidshare::Ext
|
2
|
+
|
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
|
+
|
5
|
+
Until Jan 2013 this gem has extended 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
|
+
From Jan 2013 Rapidshare-Ext gem has branched out and ships as a standalone library.
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your Gemfile:
|
11
|
+
|
12
|
+
gem 'rapidshare-ext'
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install rapidshare-ext
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
First, create an instance:
|
25
|
+
```ruby
|
26
|
+
api = Rapidshare::API.new(:login => 'my_login', :password => 'my_password')
|
27
|
+
api = Rapidshare::API.new(:cookie => 'cookie_here') # More preferable way
|
28
|
+
```
|
29
|
+
|
30
|
+
### Files
|
31
|
+
|
32
|
+
Now you can perform file download in two ways: by HTTP/HTTPS url or by absolute path.
|
33
|
+
|
34
|
+
First, by the HTTP url, as it has worked before:
|
35
|
+
```ruby
|
36
|
+
@rs.download 'https://rapidshare.com/files/4226120320/upload_file_1.txt',
|
37
|
+
:downloads_dir => '/tmp',
|
38
|
+
:save_as => 'file2.txt' # This doesn't work in the original gem at the moment because of Rapidshare API changes
|
39
|
+
|
40
|
+
# With a default local file name
|
41
|
+
@rs.download 'https://rapidshare.com/files/4226120320/upload_file_1.txt',
|
42
|
+
:downloads_dir => '/tmp'
|
43
|
+
```
|
44
|
+
|
45
|
+
Download by absolute path from account you owned:
|
46
|
+
```ruby
|
47
|
+
@rs.download '/foo/bar/baz/upload_file_1.txt',
|
48
|
+
:downloads_dir => '/tmp'
|
49
|
+
```
|
50
|
+
|
51
|
+
In both the first and second samples the result will be the same.
|
52
|
+
|
53
|
+
It's possible to implement a custom progress bar functionality by providing a codeblock to #download method
|
54
|
+
```ruby
|
55
|
+
@rs.download '/foo/bar.txt', :downloads_dir => '/tmp'
|
56
|
+
do |chunk_size, downloaded, total, progress|
|
57
|
+
# chunk_size has the default value of 16384 bytes for Ruby 1.9
|
58
|
+
# downloaded is a aggregated size of file part has already been downloaded at the moment
|
59
|
+
# total represents a file total size
|
60
|
+
# progress is a progress bar value in percents
|
61
|
+
#
|
62
|
+
# Example: While user downloading a 102598 bytes file the valuse will be as follows:
|
63
|
+
# Iter 1: chunk_size=0, downloaded=0, total=102598, progress=0
|
64
|
+
# Iter 2: chunk_size=16384, downloaded=0, total=102598, progress=15.97
|
65
|
+
# Iter 3: chunk_size=16384, downloaded=0, total=102598, progress=31.94
|
66
|
+
# Iter 4: chunk_size=16384, downloaded=0, total=102598, progress=47.91
|
67
|
+
# Iter 5: chunk_size=16384, downloaded=0, total=102598, progress=63.88
|
68
|
+
# Iter 6: chunk_size=16384, downloaded=0, total=102598, progress=79.85
|
69
|
+
# Iter 7: chunk_size=16384, downloaded=0, total=102598, progress=95.81
|
70
|
+
# Iter 8: chunk_size=4294, downloaded=0, total=102598, progress=100.00
|
71
|
+
end
|
72
|
+
```
|
73
|
+
|
74
|
+
File uploading is also became very simple:
|
75
|
+
```ruby
|
76
|
+
api.upload('/home/odiszapc/my_damn_cat.mov', :to => '/gallery/video', :as => 'cat1.mov')
|
77
|
+
# => {
|
78
|
+
# :id => 1,
|
79
|
+
# :size => 12345, # File size in bytes
|
80
|
+
# :checksum => <MD5>,
|
81
|
+
# :url => <DOWNLOAD_URL>, # https://rapidshare/.......
|
82
|
+
# :already_exists? => true/false # Does the file already exists within a specific folder, real uploading will not being performed in this case
|
83
|
+
#}
|
84
|
+
```
|
85
|
+
Destination folder will be created automatically.
|
86
|
+
After uploading has been completed the file will be stored in a Rapidshare as '/gallery/video/cat1.mov'
|
87
|
+
You can easily get a download url after uploading:
|
88
|
+
```ruby
|
89
|
+
result = api.upload('/home/odiszapc/my_damn_cat.mov', :to => '/gallery/video', :as => 'cat1.mov')
|
90
|
+
result[:url]
|
91
|
+
```
|
92
|
+
|
93
|
+
By default, file is uploaded into the root folder:
|
94
|
+
```ruby
|
95
|
+
api.upload('/home/odiszapc/my_damn_humster.mov')
|
96
|
+
```
|
97
|
+
|
98
|
+
Rapidshare allows to store multiple files having equal names under the same folder. I believe this behaviour is absolutely wrong.
|
99
|
+
Therefore, each time upload performed it checks if the file with the given name already exists in a folder.
|
100
|
+
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.
|
101
|
+
To force file being overwritten set the :overwrite parameter to true:
|
102
|
+
|
103
|
+
```ruby
|
104
|
+
api.upload '/home/odiszapc/my_damn_cat.mov',
|
105
|
+
:to => '/gallery/video',
|
106
|
+
:as => 'cat1.mov'
|
107
|
+
|
108
|
+
# No upload will be performed
|
109
|
+
api.upload '/home/odiszapc/my_damn_cat.mov',
|
110
|
+
:to => '/gallery/video',
|
111
|
+
:as => 'cat1.mov'
|
112
|
+
|
113
|
+
# With the following notation file will be uploaded with overwriting the existing one
|
114
|
+
api.upload '/home/odiszapc/my_damn_cat.mov',
|
115
|
+
:to => '/gallery/video',
|
116
|
+
:as => 'cat1.mov',
|
117
|
+
:overwrite => true
|
118
|
+
```
|
119
|
+
|
120
|
+
Deleting files:
|
121
|
+
```ruby
|
122
|
+
api.remove_file('/putin/is/a/good/reason/to/live/abroad/ticket_to_Nicaragua.jpg')
|
123
|
+
```
|
124
|
+
|
125
|
+
Renaming files:
|
126
|
+
```ruby
|
127
|
+
api.rename_file('/foo/bar.rar', 'baz.rar')
|
128
|
+
```
|
129
|
+
|
130
|
+
Moving files:
|
131
|
+
```ruby
|
132
|
+
api.move_file('/foo/bar/baz.rar', :to => '/foo') # new file path: '/foo/baz.rar'
|
133
|
+
api.move_file('/foo/bar/baz.rar') # move to a root folder
|
134
|
+
```
|
135
|
+
|
136
|
+
Get the file ID:
|
137
|
+
```ruby
|
138
|
+
api.file_id('/foo/bar/baz.rar') # => <ID>
|
139
|
+
```
|
140
|
+
|
141
|
+
### Folders
|
142
|
+
As you note it's possible having a hierarchy of folders in your account.
|
143
|
+
|
144
|
+
Creating folder hierarchy:
|
145
|
+
```ruby
|
146
|
+
folder_id = api.add_folder 'a/b/c' # => <FOLDER ID>
|
147
|
+
```
|
148
|
+
|
149
|
+
Deleting folders:
|
150
|
+
```ruby
|
151
|
+
api.remove_folder('/a/b/c')
|
152
|
+
```
|
153
|
+
|
154
|
+
Moving folders:
|
155
|
+
```ruby
|
156
|
+
api.move_folder('/a/b/c', :to => '/a')
|
157
|
+
```
|
158
|
+
This moves the folder 'c' from the directory '/a/b/' and places it under the directory '/a'
|
159
|
+
|
160
|
+
You can get hierarchy of all the folders in account:
|
161
|
+
```ruby
|
162
|
+
api.folders_hierarchy
|
163
|
+
# => {
|
164
|
+
# <folder ID> => {
|
165
|
+
# :parent => <parent folder ID>,
|
166
|
+
# :name => <folder name>,
|
167
|
+
# :path => <folder absolute path>
|
168
|
+
# },
|
169
|
+
# ...
|
170
|
+
# }
|
171
|
+
```
|
172
|
+
|
173
|
+
Note, that after the folder hierarchy is generated first time it's cached permanently to improve performance.
|
174
|
+
|
175
|
+
So, if you want to invalidate the cache just call the above method with trailing '!':
|
176
|
+
```ruby
|
177
|
+
api.folders_hierarchy!
|
178
|
+
```
|
179
|
+
|
180
|
+
If folder tree is inconsistent (orphans are found, see next paragraph for details) the Exception will be thrown when you perform #folders_hierarchy.
|
181
|
+
To automatically normalize the tree, call the method with the :consistent flag:
|
182
|
+
```ruby
|
183
|
+
api.folders_hierarchy :consistent => true
|
184
|
+
```
|
185
|
+
Be careful with the tree consistency, orphan folders may contain a critical data.
|
186
|
+
|
187
|
+
A more secure way to deal with folder consistency is to fix all orphans first and then generate folder tree:
|
188
|
+
```ruby
|
189
|
+
api.add_folder '/garbage'
|
190
|
+
api.move_orphans :to => '/garbage' # Collect all orphans and place them under the /garbage folder
|
191
|
+
tree = api.folders_hierarchy
|
192
|
+
```
|
193
|
+
|
194
|
+
Get the folder ID or path:
|
195
|
+
```ruby
|
196
|
+
id = api.folder_id('/foo/bar') # <ID>
|
197
|
+
api.folder_path(id) # '/foo/bar'
|
198
|
+
```
|
199
|
+
|
200
|
+
### Orphans
|
201
|
+
As mentioned earlier, the Rapidshare has its common problem: the chance of orphan folders to be appeared.
|
202
|
+
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.
|
203
|
+
For example, let we have the basic directory tree:
|
204
|
+
```
|
205
|
+
ROOT
|
206
|
+
`-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
|
207
|
+
`-b
|
208
|
+
`-c
|
209
|
+
```
|
210
|
+
|
211
|
+
**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)
|
212
|
+
|
213
|
+
So, the best way to delete a directory tree without washing away consistency of account folder hierarchy is the following:
|
214
|
+
```ruby
|
215
|
+
api.remove_folder '/a' # This will delete all the child directories correctly
|
216
|
+
```
|
217
|
+
|
218
|
+
However, if you already have orphans in your account there is possible to fix them.
|
219
|
+
So ,the next method detects all orphan folders in your account and moves them into a specific folder:
|
220
|
+
```ruby
|
221
|
+
api.move_orphans :to => '/'
|
222
|
+
```
|
223
|
+
|
224
|
+
Or we can just delete all of them (be careful):
|
225
|
+
```ruby
|
226
|
+
api.remove_orphans!
|
227
|
+
```
|
228
|
+
|
229
|
+
### Account
|
230
|
+
You can null your account by deleting all the data stored inside:
|
231
|
+
```ruby
|
232
|
+
api.erase_all_data!
|
233
|
+
```
|
234
|
+
|
235
|
+
**Be careful with it, because you stake losing all your data**
|
236
|
+
|
237
|
+
## Contributing
|
238
|
+
|
239
|
+
1. Fork it
|
240
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
241
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
242
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
243
|
+
5. Create new Pull Request
|
222
244
|
6. Open beer
|