This repository has been archived by the owner on Jan 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/develop'
- Loading branch information
Showing
11 changed files
with
577 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
src/LooplineSystems/CloseIoApiWrapper/Api/CustomFieldApi.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?php | ||
|
||
namespace LooplineSystems\CloseIoApiWrapper\Api; | ||
|
||
use LooplineSystems\CloseIoApiWrapper\CloseIoResponse; | ||
use LooplineSystems\CloseIoApiWrapper\Library\Api\AbstractApi; | ||
use LooplineSystems\CloseIoApiWrapper\Model\CustomField; | ||
|
||
class CustomFieldApi extends AbstractApi | ||
{ | ||
const NAME = 'CustomFieldApi'; | ||
|
||
protected function initUrls() | ||
{ | ||
$this->urls = [ | ||
'get-customFields' => '/custom_fields/lead/', | ||
'update-customField' => '/custom_fields/lead/[:id]/' | ||
]; | ||
} | ||
|
||
/** | ||
* @param Curl $curl | ||
*/ | ||
public function setCurl($curl) | ||
{ | ||
$this->curl = $curl; | ||
} | ||
|
||
/** | ||
* @return CustomField[] | ||
*/ | ||
public function getAllCustomFields() | ||
{ | ||
/** @var CustomField[] $customFields */ | ||
$customFields = array(); | ||
|
||
$apiRequest = $this->prepareRequest('get-customFields'); | ||
|
||
/** @var CloseIoResponse $result */ | ||
$result = $this->triggerGet($apiRequest); | ||
|
||
if ($result->getReturnCode() == 200) { | ||
$rawData = $result->getData()[CloseIoResponse::GET_RESPONSE_DATA_KEY]; | ||
|
||
foreach ($rawData as $customField) { | ||
$customFields[] = new CustomField($customField); | ||
} | ||
} | ||
return $customFields; | ||
} | ||
|
||
/** | ||
* @param CustomField $customField | ||
* | ||
* @return CustomField | ||
* @throws InvalidParamException | ||
* @throws ResourceNotFoundException | ||
*/ | ||
public function updateCustomField(CustomField $customField) | ||
{ | ||
if ($customField->getId() == null) { | ||
throw new InvalidParamException('When updating a custom field you must provide the custom field ID'); | ||
} | ||
$id = $customField->getId(); | ||
$customField->setId(null); | ||
|
||
$customField = json_encode($customField); | ||
$apiRequest = $this->prepareRequest('update-customField', $customField, ['id' => $id]); | ||
$response = $this->triggerPut($apiRequest); | ||
|
||
if ($response->getReturnCode() == 200 && ($response->getData() !== null)) { | ||
$customField = new CustomField($response->getData()); | ||
} else { | ||
throw new ResourceNotFoundException(); | ||
} | ||
|
||
return $customField; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.