class OpenLoad

Public Class Methods

new(login = nil, key = nil) click to toggle source

Create a new instace using the api-login and the api-key (both are optional)

# File lib/openload.rb, line 8
def initialize(login = nil, key = nil)
  @api_login = login
  @api_key   = key
end

Public Instance Methods

account_info() click to toggle source
# File lib/openload.rb, line 13
def account_info
  if is_logged?
    get_a_request_and_return_in_a_struct("/account/info?login=#{@api_login}&key=#{@api_key}")
  else
    raise "You need to insert a login and a key to use this method!"
  end
end
check_remote_upload_status(id = nil, limit = nil) click to toggle source

This method cheks the status of the remote uploads.

# File lib/openload.rb, line 55
def check_remote_upload_status(id = nil, limit = nil)
  get_a_request_and_return_in_a_struct("/remotedl/status#{login_parameter(true)}#{key_parameter}#{http_parameter('limit', limit)}#{http_parameter('id', id)}")
end
convert_to_stream(file) click to toggle source

This method convert files to stream format (mp4/h.264)

# File lib/openload.rb, line 68
def convert_to_stream(file)
  get_a_request_and_return_in_a_struct("/file/convert?login=#{@api_login}&key=#{@api_key}&file=#{file}")
end
download_ticket(file) click to toggle source

Get the ticket to download a file

# File lib/openload.rb, line 22
def download_ticket(file)
  get_a_request_and_return_in_a_struct("/file/dlticket?file=#{file}#{login_parameter}#{key_parameter}")
end
file_info(file) click to toggle source

This method return the info of a file Warning: this method rertuns a hash

# File lib/openload.rb, line 33
def file_info(file)
  response = get_a_request("/file/info?file=#{file}#{login_parameter}#{key_parameter}")
  JSON.parse(response)
end
folder_list(folder = nil) click to toggle source

This method return a list of all folders. You need a login and api kei This method return returns a hash

# File lib/openload.rb, line 62
def folder_list(folder = nil)
  response = get_a_request("/file/listfolder?login=#{@api_login}&key=#{@api_key}#{http_parameter('folder', folder)}")
  JSON.parse(response)
end
get_splash_image(file) click to toggle source
# File lib/openload.rb, line 76
def get_splash_image(file)
  get_a_request_and_return_in_a_struct("/file/getsplash?login=#{@api_login}&key=#{@api_key}&file=#{file}")
end
remote_upload(url, folder = nil , headers = nil) click to toggle source

This method make a upload of a link from the web Remember: You need a login and key api to use this method.

# File lib/openload.rb, line 46
def remote_upload(url, folder = nil , headers = nil)
  if is_logged?
    get_a_request_and_return_in_a_struct("/remotedl/add#{login_parameter(true)}#{key_parameter}#{http_parameter('url', url)}#{http_parameter('folder',folder)}#{http_parameter('headers', headers)}")
  else
    raise "You need a login and a api key to make remote uploads!"
  end
end
show_converted_files(folder = nil) click to toggle source
# File lib/openload.rb, line 72
def show_converted_files(folder = nil)
  get_a_request_and_return_in_a_struct("/file/runningconverts?login=#{@api_login}&key=#{@api_key}}#{http_parameter('folder',folder)}")
end

Private Instance Methods

get_a_request(path) click to toggle source
# File lib/openload.rb, line 81
def get_a_request(path)
  HTTParty.get("#{@@api_url}#{path}").body
end
get_a_request_and_return_in_a_struct(req) click to toggle source
# File lib/openload.rb, line 101
def get_a_request_and_return_in_a_struct(req)
  response = get_a_request(req)
  data_hash = JSON.parse(response)
  OpenStruct.new(data_hash)
end
http_parameter(name, value, first_parameter = false) click to toggle source
# File lib/openload.rb, line 85
def http_parameter(name, value, first_parameter = false)
  "#{'?' if first_parameter}#{'&' unless first_parameter}#{name}=#{value}" if value
end
is_logged?() click to toggle source
# File lib/openload.rb, line 97
def is_logged?
  @api_key && @api_login
end
key_parameter() click to toggle source
# File lib/openload.rb, line 93
def key_parameter()
  http_parameter('key', @api_key)
end
login_parameter(first_parameter = false) click to toggle source
# File lib/openload.rb, line 89
def login_parameter(first_parameter = false)
  http_parameter('login', @api_login, first_parameter)
end