note 100276 added to soapclient.soapcall
| From: | spechal at gmail dot com | Date: | Tue, 05 Oct 2010 18:56:15 +0000 |
| Subject: | note 100276 added to soapclient.soapcall | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-172983@lists.php.net to get a copy of this message | ||
This was not a pleasant experience, but it works ... dissect it as needed.
/**
*
* When making calls to _call(), the second argument should be stdClass
*
* i.e.
* $params = new stdClass;
* $params->ListID = 123;
* $this->_call('GetContactList', $params);
*/
class Listrak {
const WSDL = 'https://webservices.listrak.com/v31/IntegrationService.asmx?WSDL';
const SOAP_NS = 'http://webservices.listrak.com/v31/';
protected $_soap = NULL;
protected $_user = NULL;
protected $_pass = NULL;
protected $_list_id = NULL;
protected $_authHeader = NULL;
public function __construct($user, $pass, $listId = NULL){
$this->_soap = new SoapClient(self::WSDL, array('soap_version' => SOAP_1_2));
$this->_user = $user;
$this->_pass = $pass;
if($listId)
$this->listId($listId);
$this->_buildAuthHeader();
}
protected function _buildAuthHeader(){
$auth = array();
$auth['UserName'] = new SoapVar($this->_user, XSD_STRING, NULL, NULL, NULL,
self::SOAP_NS);
$auth['Password'] = new SoapVar($this->_pass, XSD_STRING, NULL, NULL, NULL,
self::SOAP_NS);
$headerVar = new SoapVar($auth, SOAP_ENC_OBJECT);
$header = new SoapHeader(self::SOAP_NS, 'WSUser', $headerVar);
$this->_soap->__setSoapHeaders(array($header));
}
public function listId($listId = NULL){
if($listId)
$this->_list_id = $listId;
return $this->_list_id;
}
protected function _call($method){
$args = func_get_args();
array_shift($args);
try {
return $this->_soap->__soapCall($method, $args);
} catch(SoapFault $e){
die('There was an error: '.$e->getMessage()."\n");
}
}
public function getContactListCollection(){
return $this->_call('GetContactListCollection');
}
public function getContactList($listId = NULL){
if($listId)
$this->listId($listId);
$listId = new stdClass;
$listId->ListID = $this->listId();
return $this->_call('GetContactList', $listId);
}
}
// test
$client = new Listrak('username', 'password');
print_r($client->getContactListCollection());
----
Server IP: 69.147.83.197
Probable Submitter: 68.143.2.178
----
Manual Page -- http://www.php.net/manual/en/soapclient.soapcall.php
Edit -- https://master.php.net/note/edit/100276
Del: integrated -- https://master.php.net/note/delete/100276/integrated
Del: useless -- https://master.php.net/note/delete/100276/useless
Del: bad code -- https://master.php.net/note/delete/100276/bad+code
Del: spam -- https://master.php.net/note/delete/100276/spam
Del: non-english -- https://master.php.net/note/delete/100276/non-english
Del: in docs -- https://master.php.net/note/delete/100276/in+docs
Del: other reasons-- https://master.php.net/note/delete/100276
Reject -- https://master.php.net/note/reject/100276
Search -- https://master.php.net/manage/user-notes.php