Simple cPanel XML api call using Ruby

http://www.rajesharma.com/blog/articles/simple-cpanel-xml-api-call-using...

This is a demonstration of making a cPanel XMP API call via a ruby script.
For this you will require:
# #A working Ruby installation (1.8+, tested with 1.8.5)
# #A working (lib)curl installation, with development stuff (7.5+)

for curl-devel ( development stuff ,if you dont have it), do

$ yum install curl-devel

Then we install ‘curb’.The ‘curl’ module for ruby.

$ gem install curb

Here is the simple demonstration of the API call using Basic Authentication:
File : cp_ruby.rb

require 'rubygems' #to load the curl module
require 'curl' #for the Curl class
require 'base64' #for the authentication

url="https://example.com:2087/xml-api/version"
user="root"
pass="somePass"

str=user+":"+pass
authStr=Base64.encode64(str)

crl = Curl::Easy.new(url)
crl.headers={"Authorization"=>"Basic "+authStr+"\r\n",
"Content-Type"=>"application/x-www-form-urlencoded\r\n"}

crl.ssl_verify_peer= FALSE
crl.ssl_verify_host= FALSE

crl.perform
puts crl.body_str

Thats it.
Now,

$ ruby cp_ruby.rb

You’ll get the following response:

11.25.0