Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
176 changes: 176 additions & 0 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@
*/
class Client extends GuzzleClient
{
/**
* @var array
*/
private $marketoObjects = array(
'Leads' => 'leads',
'Companies' => 'companies',
'Opportunities' => 'opportunities',
'Opportunities Roles' => 'opportunities/roles',
'Sales Persons' => 'salespersons'
);

/**
* {@inheritdoc}
*/
Expand Down Expand Up @@ -192,6 +203,84 @@ private function createOrUpdateLeadsCommand($action, $leads, $lookupField, $args
return $this->getResult('createOrUpdateLeads', $args, false, $returnRaw);
}

/**
* Only update the given companies.
*
* @param array $companies Array of arrays.
* @param string $dedupeBy
* @param array $args
* @param bool|false $returnRaw
* @throws \Exception
*
* @link http://developers.marketo.com/rest-api/endpoint-reference/lead-database-endpoint-reference/#!/Companies/syncCompaniesUsingPOST
*
* @return GetLeadsResponse
*/
public function updateCompanies($companies, $dedupeBy = 'dedupeFields', $args = array(), $returnRaw = false) {
return $this->createOrUpdateObjects('Companies', 'updateOnly', $companies, $dedupeBy, $args, $returnRaw);
}

/**
* Only create the given companies.
*
* @param array $companies Array of arrays.
* @param string $dedupeBy
* @param array $args
* @param bool|false $returnRaw
* @throws \Exception
*
* @link http://developers.marketo.com/rest-api/endpoint-reference/lead-database-endpoint-reference/#!/Companies/syncCompaniesUsingPOST
*
* @return GetLeadsResponse
*/
public function createCompanies($companies, $dedupeBy = 'dedupeFields', $args = array(), $returnRaw = false) {
return $this->createOrUpdateObjects('Companies', 'createOnly', $companies, $dedupeBy, $args, $returnRaw);
}

/**
* Create or update the given companies.
*
* @param array $companies Array of arrays.
* @param string $dedupeBy
* @param array $args
* @param bool|false $returnRaw
* @throws \Exception
*
* @link http://developers.marketo.com/rest-api/endpoint-reference/lead-database-endpoint-reference/#!/Companies/syncCompaniesUsingPOST
*
* @return GetLeadsResponse
*/
public function createOrUpdateCompanies($companies, $dedupeBy = 'dedupeFields', $args = array(), $returnRaw = false) {
return $this->createOrUpdateObjects('Companies', 'createOrUpdate', $companies, $dedupeBy, $args, $returnRaw);
}

/**
* Generic method to create or update Marketo objects.
*
* @param string $objectName
* @param string $action Should be createOnly, updateOnly, or createOrUpdate.
* @param array $records Array of arrays.
* @param string $dedupeBy
* @param array $args
* @param bool|false $returnRaw
* @throws \Exception
*
* @return GetLeadsResponse

*/
private function createOrUpdateObjects($objectName, $action, $records, $dedupeBy, $args = array(), $returnRaw = false) {
if (!isset($this->marketoObjects[$objectName])) {
throw new \Exception('createOrUpdate() Expected parameter $objectName, to be a valid Marketo object ' . "but $objectName provided");
};

$args['objectName'] = $this->marketoObjects[$objectName];
$args['action'] = $action;
$args['input'] = $records;
$args['dedupeBy'] = $dedupeBy;

return $this->getResult('createOrUpdateObject', $args, false, $returnRaw);
}

/**
* Create the given leads.
*
Expand Down Expand Up @@ -684,6 +773,93 @@ public function approveEmail($emailId, $args = array(), $returnRaw = false)
return $this->getResult('approveEmailbyId', $args, false, $returnRaw);
}

/**
* Describe the leads object
*
* @param bool|false $returnRaw
* @throws \Exception
*
* @link http://developers.marketo.com/rest-api/endpoint-reference/lead-database-endpoint-reference/#!/Leads/describeUsingGET_2
*
* @return Response
*/
public function describeLeads($returnRaw = false) {
return $this->describeObject('Leads', $returnRaw);
}

/**
* Describe the opportunities object
*
* @param bool|false $returnRaw
* @throws \Exception
*
* @link http://developers.marketo.com/rest-api/endpoint-reference/lead-database-endpoint-reference/#!/Opportunities/describeUsingGET_3
*
* @return Response
*/
public function describeOpportunities($returnRaw = false) {
return $this->describeObject('Opportunities', $returnRaw);
}

/**
* Describe the opportunities roles object.
*
* @param bool|false $returnRaw
* @throws \Exception
*
* @link http://developers.marketo.com/rest-api/endpoint-reference/lead-database-endpoint-reference/#!/Opportunities/describeOpportunityRoleUsingGET
*
* @return Response
*/
public function describeOpportunityRoles($returnRaw = false) {
return $this->describeObject('Opportunities Roles', $returnRaw);
}

/**
* Describe the companies object.
*
* @param bool|false $returnRaw
* @throws \Exception
*
* @link http://developers.marketo.com/rest-api/endpoint-reference/lead-database-endpoint-reference/#!/Companies/describeUsingGET
*
* @return Response
*/
public function describeCompanies($returnRaw = false) {
return $this->describeObject('Companies', $returnRaw);
}

/**
* Describe the Sales Persons object.
*
* @param bool|false $returnRaw
* @throws \Exception
*
* @link http://developers.marketo.com/rest-api/endpoint-reference/lead-database-endpoint-reference/#!/Sales_Persons/describeUsingGET_4
*
* @return Response
*/
public function describeSalesPersons($returnRaw = false) {
return $this->describeObject('Sales Persons', $returnRaw);
}

/**
* Generic method to describe a Marketo object.
*
* @param string $objectName
* @param bool|false $returnRaw
* @return Response
* @throws \Exception
*/
private function describeObject($objectName, $returnRaw = false) {
if (!isset($this->marketoObjects[$objectName])) {
throw new \Exception('describeObject() Expected parameter $objectName, to be a valid Marketo object ' . "but $objectName provided");
};

$args['objectName'] = $this->marketoObjects[$objectName];
return $this->getResult('describeObject', $args, false, $returnRaw);
}

/**
* Internal helper method to actually perform command.
*
Expand Down
19 changes: 19 additions & 0 deletions src/service.json
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,25 @@
"id": {"location": "uri"}
},
"responseClass": "CSD\\Marketo\\Response\\ApproveEmailResponse"
},
"describeObject": {
"httpMethod": "GET",
"uri": "/rest/v1/{objectName}/describe.json",
"parameters": {
"objectName": {"location": "uri"}
},
"responseClass": "CSD\\Marketo\\Response"
},
"createOrUpdateObject": {
"httpMethod": "POST",
"uri": "/rest/v1/{objectName}.json",
"parameters": {
"objectName": {"location": "uri"},
"action": {"location": "json"},
"input": {"location": "json"},
"dedupeBy": {"location": "json"}
},
"responseClass": "CSD\\Marketo\\Response\\GetLeadsResponse"
}
}
}