Class: Rapidshare::API
- Inherits:
-
Object
- Object
- Rapidshare::API
- Includes:
- Ext::API
- Defined in:
- lib/rapidshare-base/api.rb,
lib/rapidshare-ext.rb
Constant Summary
Constants included from Ext::API
Class Method Summary collapse
-
.request(service_name, params = {}) ⇒ Object
Calls specific RapidShare API service and returns result.
Instance Method Summary collapse
Methods included from Ext::API
#add_folder, #detect_gaps, #erase_all_data!, #file_id, #file_info, #folder_id, #folder_path, #folders_hierarchy, #folders_hierarchy!, #gap?, #move_file, #move_folder, #move_orphans, #orphan?, #remove_file, #remove_folder, #remove_orphans!, #rename_file, #root_folder?, #slice_tree, #upload
Class Method Details
.request(service_name, params = {}) ⇒ Object
Calls specific RapidShare API service and returns result.
Throws exception if error is received from RapidShare API.
Params:
-
service_name - name of the RapidShare service, for example
checkfiles
-
params - hash of service parameters and options (listed below)
-
parser - option, determines how the response body will be parsed:
-
none - default value, returns response body as it is
-
csv - comma-separated values, for example: getrapidtranslogs. Returns array or arrays, one array per each line.
-
hash - lines with key and value separated by “=”, for example: getaccountdetails. Returns hash.
-
-
server - option, determines which server will be used to send request
25 26 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 |
# File 'lib/rapidshare-base/api.rb', line 25 def self.request(service_name, params = {}) params.symbolize_keys! parser = (params.delete(:parser) || :none).to_sym unless [:none, :csv, :hash].include?(parser) raise Rapidshare::API::Error.new("Invalid parser for request method: #{parser}") end server = params.delete(:server) server_url = server ? "https://#{server}/cgi-bin/rsapi.cgi?sub=%s&%s" : URL http_method = (params.delete(:method) || :get).to_sym raise Exception, "invalid HTTP method #{http_method}" unless self.respond_to? http_method case http_method when :get response = self.send(http_method, server_url % [service_name, params.to_query]) else params[:sub] = service_name response = self.send(http_method, server_url.gsub(/\?sub=%s&%s$/,''), params) end if response.start_with?(ERROR_PREFIX) case error = response.sub(ERROR_PREFIX, "").split('.').first when "Login failed" raise Rapidshare::API::Error::LoginFailed when "Invalid routine called" raise Rapidshare::API::Error::InvalidRoutineCalled.new(service_name) else raise Rapidshare::API::Error.new(error) end end self.parse_response(parser, response) end |
Instance Method Details
#download(file, params = {}) ⇒ Object
61 62 63 64 65 66 67 68 69 |
# File 'lib/rapidshare-base/api.rb', line 61 def download(file, params= {}) if file.match /\Ahttps?:\/\// url = file else url = file_info(file)[:url] end Rapidshare::Ext::Download.new(url, self, params).perform end |