Module: Ankoder

Defined in:
lib/ankoder/version.rb,
lib/ankoder.rb,
lib/ankoder/ext.rb,
lib/ankoder/job.rb,
lib/ankoder/auth.rb,
lib/ankoder/base.rb,
lib/ankoder/video.rb,
lib/ankoder/upload.rb,
lib/ankoder/account.rb,
lib/ankoder/browser.rb,
lib/ankoder/profile.rb,
lib/ankoder/download.rb

Overview

:nodoc:

Defined Under Namespace

Modules: CoreExtension, VERSION Classes: Account, Auth, Base, Browser, Configuration, Download, DownloadFailed, Job, JobFailed, NotAuthorized, Profile, RequestError, ResourceNotFound, ServerError, SessionNotFound, Upload, Video

Constant Summary collapse

OUT_FORMAT =
"xml"
RESOURCES =
%w{job profile download video account upload}
DEFAULT_EXPIRY =
300
ERROR_CODE =

These are error codes you receive if you use ping options

{
  100 => "Unknown error",
  101 => "Unsupported audio codec",
  102 => "Unsupported video codec",
  103 => "This video cannot be encoded in this format",
  104 => "Wrong settings for audio",
  105 => "Wrong settings for video",
  106 => "Cannot retrieve info from this video",
  107 => "Not a video file",
  108 => "Video too long",
  109 => "The container of this video is not supported yet",
  110 => "The audio can't be resampled",
  201 => "404 Not Found",
  202 => "Bad address",
  300 => "No more credit available"
}

Class Method Summary collapse

Class Method Details

.load_configObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/ankoder.rb', line 38

def self.load_config
  begin
    globe_config = YAML::load(ERB.new((IO.read("#{RAILS_ROOT}/config/ankoder.yml"))).result)
    auth_config = globe_config["#{RAILS_ENV}"]
    Configuration::private_key   = auth_config["private_key"] 
    Configuration::access_key    = auth_config["access_key"] 
    Configuration::auth_user     = auth_config["auth_user"]
    Configuration::auth_password = auth_config["auth_password"]
    Configuration::host          = auth_config["host"] || "api.ankoder.com"
    Configuration::port          = auth_config["port"] || "80"
  rescue
    raise $!, " Ankoder: problems trying to load '\"#{RAILS_ROOT}/config/ankoder.yml\")}'"
    raise
  end
end

.response(xml) ⇒ Object

Convert the XML response into Hash



55
56
57
# File 'lib/ankoder.rb', line 55

def self.response(xml)
  XmlSimple.xml_in(xml, {'ForceArray' => false})
end

.sanitize_url(url) ⇒ Object

sanitize url



60
61
62
# File 'lib/ankoder.rb', line 60

def self.sanitize_url(url)
  return url.gsub(/[^a-zA-Z0-9:\/\.\-\+_\?\=&]/) {|s| CGI::escape(s)}.gsub("+", "%20")
end

.url_exist?(url, limit = 10) ⇒ Boolean

Returns:

  • (Boolean)


64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/ankoder.rb', line 64

def self.url_exist?(url , limit = 10)
  raise false if limit == 0
  response = Net::HTTP.get_response(URI.parse(url))
  case response
  when Net::HTTPSuccess     then true
  when Net::HTTPRedirection then url_exist?(response['location'], limit - 1)
  else
    false
  end
rescue 
  false
end