diff --git a/Autoload.php b/Autoload.php new file mode 100644 index 0000000..a3fbc7b --- /dev/null +++ b/Autoload.php @@ -0,0 +1,85 @@ + 'interact.php', + 'getLaunchStatus' => 'includes/campaign.php', + 'launchCampaign' => 'includes/campaign.php', + 'mergeTriggerEmail' => 'includes/campaign.php', + 'scheduleCampaignLaunch' => 'includes/campaign.php', + 'triggerCustomEvent' => 'includes/campaign.php', + 'triggerCampaignMessage' => 'includes/campaign.php', + 'HAmergeTriggerEmail' => 'includes/campaign.php', + 'copyContentLibraryItem' => 'includes/content.php', + 'createContentLibraryItem' => 'includes/content.php', + 'createDocument' => 'includes/content.php', + 'deleteContentLibraryItem' => 'includes/content.php', + 'deleteDocument' => 'includes/content.php', + 'getContentLibraryItem' => 'includes/content.php', + 'getDocumentContent' => 'includes/content.php', + 'getDocumentImages' => 'includes/content.php', + 'moveContentLibraryItem' => 'includes/content.php', + 'setDocumentContent' => 'includes/content.php', + 'setDocumentImages' => 'includes/content.php', + 'updateContentLibraryItem' => 'includes/content.php', + 'deleteFolder' => 'includes/folder.php', + 'listFolders' => 'includes/folder.php', + 'createContentLibraryFolder' => 'includes/folder.php', + 'createFolder' => 'includes/folder.php', + 'doesContentLibraryFolderExist' => 'includes/folder.php', + 'mergeListMembersRIID' => 'includes/list.php', + 'retrieveListMembers' => 'includes/list.php', + 'deleteListMembers' => 'includes/list.php', + 'createTable' => 'includes/table.php', + 'createTableWithPK' => 'includes/table.php', + 'deleteProfileExtensionMembers' => 'includes/table.php', + 'deleteTable' => 'includes/table.php', + 'mergeIntoProfileExtension' => 'includes/table.php', + 'mergeTableRecords' => 'includes/table.php', + 'mergeTableRecordsWithPK' => 'includes/table.php', + 'deleteTableRecords' => 'includes/table.php', + 'retrieveTableRecords' => 'includes/table.php', + 'retrieveProfileExtensionRecords' => 'includes/table.php', + 'truncateTable' => 'includes/table.php', + 'CustomEvent' => 'objects/CustomEvent.php', + 'DefaultPermissionStatus' => 'objects/DefaultPermissionStatus.php', + 'EmailFormat' => 'objects/EmailFormat.php', + 'Field' => 'objects/Field.php', + 'FieldType' => 'objects/FieldType.php', + 'ImageData' => 'objects/ImageData.php', + 'InteractObject' => 'objects/InteractObject.php', + 'ItemData' => 'objects/ItemData.php', + 'LaunchPreferences' => 'objects/LaunchPreferences.php', + 'ListMergeRule' => 'objects/ListMergeRule.php', + 'MatchColumn' => 'objects/MatchColumn.php', + 'MatchOperator' => 'objects/MatchOperator.php', + 'OptionalData' => 'objects/OptionalData.php', + 'ProofLaunchOptions' => 'objects/ProofLaunchOptions.php', + 'ProofLaunchType' => 'objects/ProofLaunchType.php', + 'QueryColumn' => 'objects/QueryColumn.php', + 'RecipientData' => 'objects/RecipientData.php', + 'RecipientIdentifier' => 'objects/RecipientIdentifier.php', + 'Recipient' => 'objects/Recipient.php', + 'RecordData' => 'objects/RecordData.php', + 'Record' => 'objects/Record.php', + 'RejectChannel' => 'objects/RejectChannel.php', + 'UpdateOnMatch' => 'objects/UpdateOnMatch.php', + 'authenticateServer' => 'objects/Login.php', + 'loginWithCertificate' => 'objects/Login.php', + 'ProgressChunk' => 'objects/ProgressChunk.php' + ); + } + $path = __DIR__; + if ( isset($class_map[$class]) ) { + $file = $path . '/' . $class_map[$class]; + require_once $file; + } + } + spl_autoload_register('Responsys_Autoload'); +} + +?> \ No newline at end of file diff --git a/bootstrap.php b/bootstrap.php index d8bbc78..76a0b3c 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -1,5 +1,14 @@ \ No newline at end of file diff --git a/includes/folder.php b/includes/folder.php index 7b4ee64..38517ab 100755 --- a/includes/folder.php +++ b/includes/folder.php @@ -15,3 +15,33 @@ class listFolders extends interact { public $params = array(); } + +class createContentLibraryFolder extends interact +{ + public $params = array( 'path' => null ); + + public function setPathParam( $folderName ) + { + $this->params['path'] = $folderName; + } +} + +class createFolder extends interact +{ + public $params = array( 'folderName' => null ); + + public function setFolderNameParam( $folderName ) + { + $this->params['folderName'] = $folderName; + } +} + +class doesContentLibraryFolderExist extends interact +{ + public $params = array( 'path' => null ); + + public function setPathParam( $path ) + { + $this->params['path'] = $path; + } +} diff --git a/includes/list.php b/includes/list.php index 4b1683f..6bb4027 100755 --- a/includes/list.php +++ b/includes/list.php @@ -24,6 +24,30 @@ public function setListParam( InteractObject $interact_object ) } +class mergeListMembers extends interact +{ + public $params = array( 'recordData' => array( 'fieldNames' => null, 'records' => null ), + 'mergeRule' => null, + 'list' => null ); + + public function setMergeRuleParam( ListMergeRule $rule ) + { + $this->params['mergeRule'] = $rule; + } + + public function setRecordDataParam( array $fieldNames, array $records ) + { + $this->params['recordData']['fieldNames'] = $fieldNames; + $this->params['recordData']['records'] = $records; + } + + public function setListParam( InteractObject $interact_object ) + { + $this->params['list'] = $interact_object; + } + +} + /** * Retrieve a record or set of records by its QueryColumn value */ diff --git a/interact.php b/interact.php index 373580f..9c56dcc 100755 --- a/interact.php +++ b/interact.php @@ -15,7 +15,8 @@ class interact CONST SOAP_ERROR_HEADER = " An error occurred during soap client creation - check soap header and cookie "; CONST SOAP_ERROR_CALL_NAME = " Interact_API requires a soap call name in order to run API. " ; - protected $endPoint, + protected $soapClientClass, + $endPoint, $wsdl, $uri, $soapNameSpace, @@ -39,20 +40,21 @@ function __construct(){} * @param unknown $pod_number WILL BE A 2 or 5 depending on the account location ws5.responsys.net* or ws2.responsys.net* * @throws Exception */ - public function intitializeSoapClient( $wsdl, $end_point ) + public function intitializeSoapClient( $wsdl, $end_point, $client_class = "SoapClient" ) { - $this->setSoapParams( $wsdl, $end_point ); + $this->setSoapParams( $wsdl, $end_point, $client_class ); if( !$this->setSoapClient() ) throw new Exception(" *** Soap Client Init Failed *** "); } - private function setSoapParams( $wsdl, $end_point ) + private function setSoapParams( $wsdl, $end_point, $client_class = "SoapClient" ) { $this->wsdl = $wsdl; $this->endPoint = $end_point; $this->uri = ( stristr("ws3", $wsdl) || stristr("ws4", $wsdl) ) ? self::SOAP_URI_URSA : null; $this->soapNameSpace = ( stristr("ws3", $wsdl) || stristr("ws4", $wsdl) ) ? self::SOAP_NS_URSA : self::SOAP_NS; + $this->soapClientClass = $client_class; } private function setSoapHeaders( $authId = null ) @@ -110,7 +112,7 @@ private function setSoapClient() //'proxy_port' => '8888', 'cache_wsdl' => WSDL_CACHE_NONE, ) ; - self::$soapClient = new SoapClient( $this->wsdl, $soapClientParams ); + self::$soapClient = new $this->soapClientClass( $this->wsdl, $soapClientParams ); if( self::$soapClient instanceof SoapClient) { @@ -155,23 +157,14 @@ private function print_xml() public function execute( $instance ) { $result = null; - - try - { + + try{ $result = self::$soapClient->{ get_class( $instance ) }( $instance->params ); + } catch (Exception $ex){ $this->print_xml(); + throw $ex; } - catch( SoapFault $fault ) - { - echo " *** SOAPFAULT *** \n"; - $this->print_xml(); - - } - catch( Exception $exception ) - { - echo " *** EXCEPTION *** \n"; - echo $exception->getMessage(); - } + $this->print_xml(); //if( $this->debug == true ) // print_r( $result ); @@ -189,8 +182,7 @@ private function loadObjects() foreach( $objects as $object ) { - echo "Including object ( file/class ): " . $object . "\n"; - include( $object ); + require_once( $object ); } } @@ -227,7 +219,9 @@ public function login( $username, $password ) } else { - echo "Logged in -> session_id : " . $this->sessionId . "\n"; + if ($this->debug){ + echo "Logged in -> session_id : " . $this->sessionId . "\n"; + } self::$isLoggedIn = true; $result = true; @@ -235,6 +229,16 @@ public function login( $username, $password ) $this->print_xml(); } } + else + { + throw new Exception (self::SOAP_ERROR_LOGIN); + } + } + else + { + if ($this->debug) { + echo "Attempt to login when already logged in"; + } } return $result; @@ -252,17 +256,36 @@ public function logout() if( self::$isLoggedIn ) { - $loggedOut = self::$soapClient->logout(); - - if( $this->debug == true ) - $this->print_xml(); - - if( $loggedOut->result == 1 ) - { + try { + $loggedOut = self::$soapClient->logout(); + + if( $this->debug == true ) + $this->print_xml(); + + if( $loggedOut->result == 1 ) + { + self::$isLoggedIn = false; + self::$soapClient = null; + if( $this->debug == true ) { + echo "Logged Out from sessionId : " . $this->sessionId . "\n"; + } + $result = true; + } + else + { + if( $this->debug == true ) { + echo "Unable to perform logout"; + $this->print_xml(); + } + } + } + catch( \Exception $ex) { self::$isLoggedIn = false; self::$soapClient = null; - echo "Logged Out from sessionId : " . $this->sessionId . "\n"; - $result = true; + if( $this->debug == true ) { + echo "Error logging out: " . $ex->getMessage(); + } + throw $ex; } } @@ -303,7 +326,7 @@ private function authServer( $user, $challenge, $wsdl, $endpoint) $result = null; - $this->setSoapParams( $wsdl, $endpoint ); + $this->setSoapParams( $wsdl, $endpoint, $this->soapClientClass ); if( $this->setSoapClient() ) { @@ -312,7 +335,7 @@ private function authServer( $user, $challenge, $wsdl, $endpoint) } else { - die( self::SOAP_ERROR_CLIENT ); + throw new SoapFault( self::SOAP_ERROR_CLIENT ); } return $result; @@ -330,6 +353,13 @@ private function authServer( $user, $challenge, $wsdl, $endpoint) */ public function loginWithCertificate( $user, $byte_array_challenge, $wsdl, $endpoint, $responsys_public_cert_path, $client_private_key_path) { + + if( self::$isLoggedIn ) { + if ($this->debug) { + echo "Attempt to loginWithCertificate when already logged in"; + } + return false; + } // RESPONSYS PUBLIC CERT $responsys_certificate_file = file_get_contents( $responsys_public_cert_path ); @@ -390,8 +420,7 @@ public function loginWithCertificate( $user, $byte_array_challenge, $wsdl, $endp } else { - echo openssl_error_string(); - die( "Failed to decrypt the challenge - exiting" ); + throw new Exception( "Failed to decrypt the challenge " . openssl_error_string() ); } @@ -420,7 +449,7 @@ public function loginWithCertificate( $user, $byte_array_challenge, $wsdl, $endp if ( !openssl_private_encrypt($encryptMe, $encryptedData, $private_key, OPENSSL_PKCS1_PADDING ) ) { - die( "Failed to Encrypt data with Private Key - exiting"); + throw new Exception( "Failed to Encrypt data with Private Key - exiting"); } // Now we have to unpack data which converts unsigned encrypted data to signed byte type @@ -456,6 +485,11 @@ public function loginWithCertificate( $user, $byte_array_challenge, $wsdl, $endp { throw new Exception( self::SOAP_ERROR_HEADER ); } + + self::$isLoggedIn = true; + } + else { + throw new Exception (self::SOAP_ERROR_LOGIN); } //print_r( $result ); @@ -464,13 +498,9 @@ public function loginWithCertificate( $user, $byte_array_challenge, $wsdl, $endp } else { - die("Problem during handshake - exiting"); + throw new SoapFault("Problem during handshake - exiting"); } } } - - - - ?> diff --git a/objects/ListMergeRule.php b/objects/ListMergeRule.php index 26123f0..b45f102 100644 --- a/objects/ListMergeRule.php +++ b/objects/ListMergeRule.php @@ -56,7 +56,7 @@ public function setRejectChannel( RejectChannel $channel ) public function setDefaultPermissionStatus( DefaultPermissionStatus $status ) { - $this->defaultPermissionStatus = null;//$status->defaultPermissionStatus; + $this->defaultPermissionStatus = $status->defaultPermissionStatus; } public function setMatchColumn1( MatchColumn $match_column ) diff --git a/objects/OptionalData.php b/objects/OptionalData.php index 0d04fea..d482aa5 100755 --- a/objects/OptionalData.php +++ b/objects/OptionalData.php @@ -1,6 +1,6 @@ value = $value; } -} \ No newline at end of file +}