Module: Rapidshare::Utils
Overview
Contains utility methods which can be called both as class and instance methods
Instance Method Summary collapse
-
#decode_file_status(status_code) ⇒ Object
Convert file status code (returned by checkfiles method) to
:ok
or:error
symbol. -
#fileid_and_filename(url) ⇒ Object
Extracts file id and file name from Rapidshare url.
- #get(url) ⇒ Object
-
#post(url, params) ⇒ Object
From historical purposes GET and POST methods a distinguished.
-
#text_to_hash(response) ⇒ Object
Converts rapidshare response (which is just a text in specific format) to hash.
Instance Method Details
#decode_file_status(status_code) ⇒ Object
Convert file status code (returned by checkfiles method) to :ok
or :error
symbol.
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/rapidshare-base/utils.rb', line 20 def decode_file_status(status_code) # TODO in checkfiles, return both file_status as is and decoded file status # or just boolean value if file is OK and can be downloaded case status_code when 0 then :error # File not found when 1 then :ok # File OK when 3 then :error # Server down when 4 then :error # File marked as illegal else :error # unknown status, this shouldn't happen end end |
#fileid_and_filename(url) ⇒ Object
Extracts file id and file name from Rapidshare url. Returns both in array.
Example:
https://rapidshare.com/files/829628035/HornyRhinos.jpg -> [ '829628035', 'HornyRhinos.jpg' ]
38 39 40 |
# File 'lib/rapidshare-base/utils.rb', line 38 def fileid_and_filename(url) url.split('/').slice(-2,2) || ['', ''] end |
#get(url) ⇒ Object
14 15 16 |
# File 'lib/rapidshare-base/utils.rb', line 14 def get(url) ::RestClient.get(url) end |
#post(url, params) ⇒ Object
From historical purposes GET and POST methods a distinguished. They will be merged in a future release
9 10 11 12 |
# File 'lib/rapidshare-base/utils.rb', line 9 def post(url, params) params[:filecontent] = File.new(params[:filecontent]) ::RestClient.post(url, params) end |
#text_to_hash(response) ⇒ Object
Converts rapidshare response (which is just a text in specific format) to hash.
Example:
"key1=value1\nkey1=value2" -> { :key1 => 'value1', :key2 => 'value2' }
47 48 49 |
# File 'lib/rapidshare-base/utils.rb', line 47 def text_to_hash(response) Hash[ response.strip.split(/\s*\n\s*/).map { |param| param.split('=') } ].symbolize_keys end |