Skip to content
This repository has been archived by the owner on Jan 20, 2024. It is now read-only.

Commit

Permalink
Merge pull request #71 from salesforce-marketingcloud/Dot9
Browse files Browse the repository at this point in the history
dot9 to master
  • Loading branch information
smunuswami authored Jul 11, 2017
2 parents d564503 + c79126b commit f204917
Show file tree
Hide file tree
Showing 10 changed files with 2,511 additions and 1,218 deletions.
40 changes: 27 additions & 13 deletions ET_Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,30 @@ class ET_Client extends SoapClient {
public $packageName, $packageFolders, $parentFolders;
private $wsdlLoc, $debugSOAP, $lastHTTPCode, $clientId,
$clientSecret, $appsignature, $endpoint,
$tenantTokens, $tenantKey;
$tenantTokens, $tenantKey, $xmlLoc;

function __construct($getWSDL = false, $debug = false, $params = null) {
$tenantTokens = array();
$config = @include 'config.php';
$config = false;

$this->xmlLoc = 'ExactTargetWSDL.xml';

if (file_exists(realpath(__DIR__ . "/config.php")))
$config = include 'config.php';

if ($config){
$this->wsdlLoc = $config['defaultwsdl'];
$this->clientId = $config['clientid'];
$this->clientSecret = $config['clientsecret'];
$this->appsignature = $config['appsignature'];
if (array_key_exists('xmlloc', $config)){$this->xmlLoc = $config['xmlloc'];}
} else {
if ($params && array_key_exists('defaultwsdl', $params)){$this->wsdlLoc = $params['defaultwsdl'];}
else {$this->wsdlLoc = "https://webservice.exacttarget.com/etframework.wsdl";}
if ($params && array_key_exists('clientid', $params)){$this->clientId = $params['clientid'];}
if ($params && array_key_exists('clientsecret', $params)){$this->clientSecret = $params['clientsecret'];}
if ($params && array_key_exists('appsignature', $params)){$this->appsignature = $params['appsignature'];}
if ($params && array_key_exists('xmlloc', $params)){$this->xmlLoc = $params['xmlloc'];}
}

$this->debugSOAP = $debug;
Expand Down Expand Up @@ -50,21 +58,21 @@ function __construct($getWSDL = false, $debug = false, $params = null) {
$url = "https://www.exacttargetapis.com/platform/v1/endpoints/soap?access_token=".$this->getAuthToken($this->tenantKey);
$endpointResponse = restGet($url);
$endpointObject = json_decode($endpointResponse->body);
if ($endpointResponse && property_exists($endpointObject,"url")){
if ($endpointObject && property_exists($endpointObject,"url")){
$this->endpoint = $endpointObject->url;
} else {
throw new Exception('Unable to determine stack using /platform/v1/endpoints/:'.$endpointResponse->body);
}
} catch (Exception $e) {
throw new Exception('Unable to determine stack using /platform/v1/endpoints/: '.$e->getMessage());
}
parent::__construct($this->LocalWsdlPath(), array('trace'=>1, 'exceptions'=>0));
parent::__construct($this->xmlLoc, array('trace'=>1, 'exceptions'=>0,'connection_timeout'=>120));
parent::__setLocation($this->endpoint);
}

function refreshToken($forceRefresh = false) {
if (property_exists($this, "sdl") && $this->sdl == 0){
parent::__construct($this->LocalWsdlPath(), array('trace'=>1, 'exceptions'=>0));
parent::__construct($this->xmlLoc, array('trace'=>1, 'exceptions'=>0));
}
try {
$currentTime = new DateTime();
Expand Down Expand Up @@ -119,17 +127,17 @@ function CreateWSDL($wsdlLoc) {

$remoteTS = $this->GetLastModifiedDate($wsdlLoc);

if (file_exists($this->LocalWsdlPath())){
$localTS = filemtime($this->LocalWsdlPath());
if (file_exists($this->xmlLoc)){
$localTS = filemtime($this->xmlLoc);
if ($remoteTS <= $localTS)
{
$getNewWSDL = false;
}
}

if ($getNewWSDL){
$newWSDL = file_get_contents($wsdlLoc);
file_put_contents($this->LocalWsdlPath(), $newWSDL);
$newWSDL = file_gET_contents($wsdlLoc);
file_put_contents($this->xmlLoc, $newWSDL);
}
}
catch (Exception $e) {
Expand Down Expand Up @@ -167,21 +175,21 @@ function GetLastModifiedDate($remotepath) {
$result = curl_exec($curl);

if ($result === false) {
die (curl_error($curl));
throw new Exception(curl_error($curl));
}

return curl_getinfo($curl, CURLINFO_FILETIME);
}

function __doRequest($request, $location, $saction, $version, $one_way=null) {
function __doRequest($request, $location, $saction, $version, $one_way = 0) {
$doc = new DOMDocument();
$doc->loadXML($request);

$objWSSE = new WSSESoap($doc);
$objWSSE->addUserToken("*", "*", FALSE);
$objWSSE->addOAuth($this->getInternalAuthToken($this->tenantKey));

$content = utf8_encode($objWSSE->saveXML());
$content = $objWSSE->saveXML();
$content_length = strlen($content);
if ($this->debugSOAP){
error_log ('FuelSDK SOAP Request: ');
Expand Down Expand Up @@ -425,7 +433,7 @@ function CreateAndStartDataExtensionImport($dataExtensionCustomerKey, $fileName,
$import->props["CustomerKey"] = uniqid();
$import->props["Description"] = "SDK Generated Import";
$import->props["AllowErrors"] = "true";
$import->props["DestinationObject"] = array("ObjectID"=>$dataExtensionCustomerKey);
$import->props["DestinationObject"] = array("CustomerKey"=>$dataExtensionCustomerKey);
$import->props["FieldMappingType"] = "InferFromColumnHeadings";
$import->props["FileSpec"] = $fileName;
$import->props["FileType"] = "CSV";
Expand Down Expand Up @@ -1708,6 +1716,12 @@ function __construct() {
}
}

class ET_Send extends ET_CUDSupport {
function __construct() {
$this->obj = "Send";
}
}


function restGet($url) {
$ch = curl_init();
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@ The Fuel SDK for PHP provides easy access to ExactTarget's Fuel API Family servi
- **Easier Troubleshooting**: The ability to log the full payload for API requests that are happening behind the scenes has been added in the SDK in order to make troubleshooting issues easier.

## Requirements ##
PHP Version 5.2.3
PHP Version >= 5.6.24

Extensions:

- mcrypt
- openssl
- SOAP

Expand Down
18 changes: 18 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "exacttarget/fuel-sdk-php",
"description": "ExactTarget Fuel SDK for PHP",
"homepage": "https://code.exacttarget.com/apis-sdks/fuel-sdks/",
"license": "MIT",
"minimum-stability": "stable",
"require": {
"ext-curl": "*",
"ext-openssl": "*",
"ext-soap": "*",
"php": ">=5.2.3"
},
"autoload": {
"files": [
"ET_Client.php"
]
}
}
4 changes: 2 additions & 2 deletions config.php.template
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ return array(
'appsignature' => 'none',
'clientid' => 'CCCCCCCCCCCCCCCCCCCCCCC',
'clientsecret' => 'CCCCCCCCCCCCCCCCCCCCCCC',
'defaultwsdl' => 'https://webservice.exacttarget.com/etframework.wsdl'
'defaultwsdl' => 'https://webservice.exacttarget.com/etframework.wsdl',
'xmlloc' => '/some/path/to/cache/ExactTargetWSDL.xml',
);

?>
45 changes: 45 additions & 0 deletions objsamples/sample-send.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

require('../ET_Client.php');
try {
$myclient = new ET_Client();

// Modify the date below to reduce the number of results returned from the request
// Setting this too far in the past could result in a very large response size

$retrieveDate = "2015-01-15T13:00:00.000";

// Retrieve Filtered Send with GetMoreResults
print "Retrieve Filtered Send with GetMoreResults \n";
$getSend = new ET_Send();
$getSend->authStub = $myclient;
$getSend->props = array("ID","PartnerKey","CreatedDate","ModifiedDate","Client.ID","Client.PartnerClientKey","Email.ID","Email.PartnerKey","SendDate","FromAddress","FromName","Duplicates","InvalidAddresses","ExistingUndeliverables","ExistingUnsubscribes","HardBounces","SoftBounces","OtherBounces","ForwardedEmails","UniqueClicks","UniqueOpens","NumberSent","NumberDelivered","NumberTargeted","NumberErrored","NumberExcluded","Unsubscribes","MissingAddresses","Subject","PreviewURL","SentDate","EmailName","Status","IsMultipart","SendLimit","SendWindowOpen","SendWindowClose","IsAlwaysOn","Additional","BCCEmail","EmailSendDefinition.ObjectID","EmailSendDefinition.CustomerKey");
$getSend->filter = array('Property' => 'SendDate','SimpleOperator' => 'greaterThan','DateValue' => $retrieveDate);
$getSend->getSinceLastBatch = false;
$getResponse = $getSend->get();
print_r('Get Status: '.($getResponse->status ? 'true' : 'false')."\n");
print 'Code: '.$getResponse->code."\n";
print 'Message: '.$getResponse->message."\n";
print_r('More Results: '.($getResponse->moreResults ? 'true' : 'false')."\n");
print 'Results Length: '. count($getResponse->results)."\n";
print "\n---------------\n";

while ($getResponse->moreResults) {
print "Continue Retrieve Send with GetMoreResults \n";
$getResponse = $getSend->GetMoreResults();
print_r('Get Status: '.($getResponse->status ? 'true' : 'false')."\n");
print 'Code: '.$getResponse->code."\n";
print 'Message: '.$getResponse->message."\n";
print_r('More Results: '.($getResponse->moreResults ? 'true' : 'false')."\n");
print 'Results Length: '. count($getResponse->results)."\n";
print "\n---------------\n";
}
}
catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}

?>



2 changes: 2 additions & 0 deletions soap-wsse.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php
use RobRichards\XMLSecLibs\XMLSecurityDSig;
use RobRichards\XMLSecLibs\XMLSecurityKey;
/**
* soap-wsse.php
*
Expand Down
Loading

0 comments on commit f204917

Please sign in to comment.