This gem provides a wrapper for RapidShare API.
Full documentation of RapidShare API is available at http://images.rapidshare.com/apidoc.txt
gem install rapidshare
This example shows a simple script which downloads files from Rapidshare:
require 'rubygems'
require 'rapidshare'
files_to_download = %w{
https://rapidshare.com/files/829628035/HornyRhinos.jpg
https://rapidshare.com/files/3103991314/HappyHippos.jpg
https://rapidshare.com/files/3882189288/ElegantElephants.jpg
}
rs = Rapidshare::API.new(:login => 'my_login', :password => 'my_password')
files_to_download.each do |file|
result = rs.download(file)
unless result.downloaded?
puts "[#{file}] cannot be downloaded: #{result.error}"
end
end
Rapidshare gem is meant to be used mostly by premium users. In order to call Rapidshare services as premium user, you need to log in first, using your login and password.
rs = Rapidshare::API.new(:login => 'my_login', :password => 'my_password')
Alternatively you can use cookie parameter, which stores encrypted login and password parameters.
rs = Rapidshare::API.new(:cookie => 'my_cookie')
Best practice is to use cookie. You probably don't want to enter your Rapidshare password every time or have it stored in some config file on your hard drive.
Rapidshare::API.new(:login => 'my_login', :password => 'my_password').cookie
rs.get_account_details
rs.check_files(
'https://rapidshare.com/files/829628035/HornyRhinos.jpg',
'https://rapidshare.com/files/428232373/HappyHippos.jpg',
'https://rapidshare.com/files/766059293/ElegantElephants.jpg'
)
rs.download('https://rapidshare.com/files/829628035/HornyRhinos.jpg')
Download workflow: file is checked by API#check_files
method first. If it
can be downloaded, progress bar is shown for download and afterwards API
instance is returned with downloaded
attribute set to true. If the file is
invalid, API
instance is returned with downloaded
attribute set to (wait for
it) false. (downloaded
attribute is also accessible by downloaded?
method.)
All calls to Rapidshare services are done internally by API#request
method:
Syntax:
request(service_name, params_in_hash)
Example:
Rapidshare::API.request(:getaccountdetails, :login => 'my_login', :password => 'my_password')
Use this method to call Rapidshare services which don't have dedicated methods available.
API#request
method has an optional parameter :parser which specifies how to
parse the response from Rapidshare. (Rapidshare doesn't unified API, there are
several "types" of responses.) Following options are supported at the moment:
- :none - default, returns response body as it is
- :csv - parses response like CSV file into array of arrays
- :hash - parses response like a hash - key=value strings separated by newlines
Example:
rs.request(:getaccountdetails, :parser => :hash)
PS: cookie is automatically added if you call request method on a API
instance.
Let's say you want to call service for which rapidshare gem doesn't have
dedicated method yet, for example: getrapidtranslogs . While you can
explicitly call API#request
method:
rs.request(:getrapidtranslogs, :parser => 'csv')
the cooler way is to make a service call using API#method_missing
:
rs.getrapidtranslogs(:parser => 'csv')
If you call an uknown method on API
instance, missing_method
assumes
that you want to make a service call to Rapidshare and invokes the request
method, using the missing method name as service name and passing any available
params. For example:
rs.getrapidtranslogs(:parser => 'csv')
invokes
rs.request(:getrapidtranslogs, :parser => 'csv')
method_missing
also removes any underscores from the service name, so these
method calls are equivalent:
rs.getrapidtranslogs == rs.get_rapid_trans_logs
PS: This is used for aliasing dedicated methods as well: rs.get_account_details
invokes rs.getaccountdetails
. In this case the corresponding dedicated
method is called instead of the low-level request
method, because we check for
existence of dedicated method first.
In examples directory you will other examples of using Rapidshare gem. Among other things there are scripts which can serve as simple download clients.
See LICENSE
Copyright (c) 2009-2012 Tomasz Mazur, Lukas Stejskal