url = $url;
$this->requestXML = $webapi = new SimpleXMLElement('');
$verify = $webapi->addchild('verify');
$verify->addChild('username', $username);
$verify->addChild('apikey', $apikey);
} // __construct
function add_request( SimpleXMLElement $newRequest )
{
$webapi = $this->requestXML;
//$request = $webapi->addChild('request');
$this->append_tree($webapi, $newRequest);
}
function append_tree( $root, $child )
{
// Create new DOMElements from the two SimpleXMLElements
$domroot = dom_import_simplexml($root);
$domchild = dom_import_simplexml($child);
// Import the into the dictionary document
$domchild = $domroot->ownerDocument->importNode($domchild, TRUE);
// Append the to in the dictionary
$domroot->appendChild($domchild);
}
function request()
{
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $this->url);
curl_setopt($ch,CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt($ch,CURLOPT_POSTFIELDS, $this->requestXML->saveXML());
//execute post
$xml = curl_exec($ch);
$this->responseXML = new SimpleXMLElement($xml);
//close connection
curl_close($ch);
} // request
function requestXML()
{
return $this->requestXML;
} // requestXML
function responseXML()
{
return $this->responseXML;
} // responseXML
function __destruct()
{
}// __destruct
} // WebAPI
?>