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 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
- 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
-
7
- ## Installation
8
-
9
- Add this line to your Gemfile:
10
-
11
- gem 'rapidshare-ext'
12
-
13
- And then execute:
14
-
15
- $ bundle
16
-
17
- Or install it yourself as:
18
-
19
- $ gem install rapidshare-ext
20
-
21
- ## Usage
22
-
23
- First, create an instance:
24
- ```ruby
25
- api = Rapidshare::API.new(:login => 'my_login', :password => 'my_password')
26
- api = Rapidshare::API.new(:cookie => 'cookie_here') # More preferable way
27
- ```
28
-
29
- ### Files
30
-
31
- Now you can perform file downloading in two ways: by HTTP url or by 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 from account you owned:
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 is also became very simple:
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 into the root folder:
72
- ```ruby
73
- api.upload("/home/odiszapc/my_damn_humster.mov")
74
- ```
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
-
98
- Deleting files:
99
- ```ruby
100
- api.remove_file("/putin/is/a/good/reason/to/live/abroad/ticket_to_Nicaragua.jpg")
101
- ```
102
-
103
- Renaming files:
104
- ```ruby
105
- api.rename_file("/foo/bar.rar", "baz.rar")
106
- ```
107
-
108
- Moving files:
109
- ```ruby
110
- api.move_file("/foo/bar/baz.rar", :to => "/foo") # new file path: "/foo/baz.rar"
111
- api.move_file("/foo/bar/baz.rar") # move to a root folder
112
- ```
113
-
114
- Get the file ID:
115
- ```ruby
116
- api.file_id("/foo/bar/baz.rar") # => <ID>
117
- ```
118
-
119
- ### Folders
120
- As you note it's possible having a hierarchy of folders in your account.
121
-
122
- Creating folder hierarchy:
123
- ```ruby
124
- folder_id = api.add_folder "a/b/c" # => <FOLDER ID>
125
- ```
126
-
127
- Deleting folders:
128
- ```ruby
129
- api.remove_folder("/a/b/c")
130
- ```
131
-
132
- Moving folders:
133
- ```ruby
134
- api.move_folder("/a/b/c", :to => "/a")
135
- ```
136
- This moves the folder "c" from the directory "/a/b/" and places it under the directory "/a"
137
-
138
- You can get hierarchy of all the folders in account:
139
- ```ruby
140
- api.folders_hierarchy
141
- # => {
142
- # <folder ID> => {
143
- # :parent => <parent folder ID>,
144
- # :name => <folder name>,
145
- # :path => <folder absolute path>
146
- # },
147
- # ...
148
- # }
149
- ```
150
-
151
- Note, that after the folder hierarchy is generated first time it's cached permanently to improve performance.
152
-
153
- So, if you want to invalidate the cache just call the above method with trailing "!":
154
- ```ruby
155
- api.folders_hierarchy!
156
- ```
157
-
158
- If folder tree is inconsistent (orphans are found, see next paragraph for details) the Exception will be thrown when you perform #folders_hierarchy.
159
- To automatically normalize the tree, call the method with the :consistent flag:
160
- ```ruby
161
- api.folders_hierarchy :consistent => true
162
- ```
163
- Be careful with the tree consistency, orphan folders may contain a critical data.
164
-
165
- A more secure way to deal with folder consistency is to fix all orphans first and then generate folder tree:
166
- ```ruby
167
- api.add_folder "/garbage"
168
- api.move_orphans :to => "/garbage" # Collect all orphans and place them under the /garbage folder
169
- tree = api.folders_hierarchy
170
- ```
171
-
172
- Get the folder ID or path:
173
- ```ruby
174
- id = api.folder_id("/foo/bar") # <ID>
175
- api.folder_path(id) # "/foo/bar"
176
- ```
177
-
178
- ### Orphans
179
- As mentioned earlier, the Rapidshare has its common problem: the chance of orphan folders to be appeared.
180
- 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.
181
- For example, let we have the basic directory tree:
182
- ```
183
- ROOT
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
185
- `-b
186
- `-c
187
- ```
188
-
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)
190
-
191
- So, the best way to delete a directory tree without washing away consistency of account folder hierarchy is the following:
192
- ```ruby
193
- api.remove_folder "/a" # This will delete all the child directories correctly
194
- ```
195
-
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:
198
- ```ruby
199
- api.move_orphans :to => "/"
200
- ```
201
-
202
- Or we can just delete all of them (be careful):
203
- ```ruby
204
- api.remove_orphans!
205
- ```
206
-
207
- ### Account
208
- You can null your account by deleting all the data stored inside:
209
- ```ruby
210
- api.erase_all_data!
211
- ```
212
-
213
- **Be careful with it, because you stake losing all your data**
214
-
215
- ## Contributing
216
-
217
- 1. Fork it
218
- 2. Create your feature branch (`git checkout -b my-new-feature`)
219
- 3. Commit your changes (`git commit -am 'Added some feature'`)
220
- 4. Push to the branch (`git push origin my-new-feature`)
221
- 5. Create new Pull Request
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