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 pull request #12 from dlimars/develop
Add Lead Statuses
- Loading branch information
Showing
3 changed files
with
233 additions
and
0 deletions.
There are no files selected for viewing
129 changes: 129 additions & 0 deletions
129
src/LooplineSystems/CloseIoApiWrapper/Api/LeadStatusApi.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,129 @@ | ||
<?php | ||
|
||
namespace LooplineSystems\CloseIoApiWrapper\Api; | ||
|
||
|
||
use LooplineSystems\CloseIoApiWrapper\CloseIoResponse; | ||
use LooplineSystems\CloseIoApiWrapper\Library\Api\AbstractApi; | ||
use LooplineSystems\CloseIoApiWrapper\Library\Exception\InvalidParamException; | ||
use LooplineSystems\CloseIoApiWrapper\Library\Exception\ResourceNotFoundException; | ||
use LooplineSystems\CloseIoApiWrapper\Model\LeadStatus; | ||
|
||
class LeadStatusApi extends AbstractApi | ||
{ | ||
const NAME = 'LeadStatusApi'; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function initUrls() | ||
{ | ||
$this->urls = [ | ||
'get-statuses' => '/status/lead/', | ||
'add-status' => '/status/lead/', | ||
'get-status' => '/status/lead/[:id]/', | ||
'update-status' => '/status/lead/[:id]/', | ||
'delete-status' => '/status/lead/[:id]/' | ||
]; | ||
} | ||
|
||
/** | ||
* @param LeadStatus $status | ||
* @return LeadStatus | ||
*/ | ||
public function addStatus(LeadStatus $status) | ||
{ | ||
$status = json_encode($status); | ||
$apiRequest = $this->prepareRequest('add-status', $status); | ||
$response = $this->triggerPost($apiRequest); | ||
return new LeadStatus($response->getData()); | ||
} | ||
|
||
/** | ||
* @param LeadStatus $status | ||
* @return LeadStatus|string | ||
* @throws InvalidParamException | ||
* @throws ResourceNotFoundException | ||
*/ | ||
public function updateStatus(LeadStatus $status) | ||
{ | ||
if ($status->getId() == null) { | ||
throw new InvalidParamException('When updating a status you must provide the statuses ID'); | ||
} | ||
|
||
$id = $status->getId(); | ||
$status->setId(null); | ||
|
||
$status = json_encode($status); | ||
$apiRequest = $this->prepareRequest('update-status', $status, ['id' => $id]); | ||
$response = $this->triggerPut($apiRequest); | ||
|
||
// return Lead object if successful | ||
if ($response->getReturnCode() == 200 && ($response->getData() !== null)) { | ||
$status = new LeadStatus($response->getData()); | ||
} else { | ||
throw new ResourceNotFoundException(); | ||
} | ||
return $status; | ||
} | ||
|
||
/** | ||
* @return LeadStatus[] | ||
*/ | ||
public function getAllStatus() | ||
{ | ||
/** @var LeadStatus[] $statuses */ | ||
$statuses = array(); | ||
|
||
$apiRequest = $this->prepareRequest('get-statuses'); | ||
|
||
/** @var CloseIoResponse $result */ | ||
$result = $this->triggerGet($apiRequest); | ||
|
||
if ($result->getReturnCode() == 200) { | ||
$rawData = $result->getData()[CloseIoResponse::GET_ALL_RESPONSE_LEADS_KEY]; | ||
foreach ($rawData as $status) { | ||
$statuses[] = new LeadStatus($status); | ||
} | ||
} | ||
return $statuses; | ||
} | ||
|
||
/** | ||
* @param $id | ||
* @return LeadStatus | ||
* @throws ResourceNotFoundException | ||
*/ | ||
public function getStatus($id) | ||
{ | ||
$apiRequest = $this->prepareRequest('get-status', null, ['id' => $id]); | ||
|
||
/** @var CloseIoResponse $result */ | ||
$result = $this->triggerGet($apiRequest); | ||
|
||
if ($result->getReturnCode() == 200 && ($result->getData() !== null)) { | ||
$status = new LeadStatus($result->getData()); | ||
} else { | ||
throw new ResourceNotFoundException(); | ||
} | ||
return $status; | ||
} | ||
|
||
/** | ||
* @param $id | ||
* @return CloseIoResponse | ||
* @throws ResourceNotFoundException | ||
*/ | ||
public function deleteStatus($id){ | ||
$apiRequest = $this->prepareRequest('delete-status', null, ['id' => $id]); | ||
|
||
/** @var CloseIoResponse $result */ | ||
$result = $this->triggerDelete($apiRequest); | ||
|
||
if ($result->getReturnCode() == 200) { | ||
return $result; | ||
} else { | ||
throw new ResourceNotFoundException(); | ||
} | ||
} | ||
} |
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
93 changes: 93 additions & 0 deletions
93
src/LooplineSystems/CloseIoApiWrapper/Model/LeadStatus.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,93 @@ | ||
<?php | ||
|
||
namespace LooplineSystems\CloseIoApiWrapper\Model; | ||
|
||
|
||
use LooplineSystems\CloseIoApiWrapper\Library\JsonSerializableHelperTrait; | ||
use LooplineSystems\CloseIoApiWrapper\Library\ObjectHydrateHelperTrait; | ||
|
||
class LeadStatus implements \JsonSerializable | ||
{ | ||
use ObjectHydrateHelperTrait; | ||
use JsonSerializableHelperTrait; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $label; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $id; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $organizationId; | ||
|
||
/** | ||
* LeadStatus constructor. | ||
* @param array $data | ||
*/ | ||
public function __construct(array $data) | ||
{ | ||
if ($data) { | ||
$this->hydrate($data); | ||
} | ||
} | ||
|
||
/** | ||
* @param $label | ||
* @return LeadStatus | ||
*/ | ||
public function setLabel($label) | ||
{ | ||
$this->label = $label; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getLabel() | ||
{ | ||
return $this->label; | ||
} | ||
|
||
/** | ||
* @param $id | ||
* @return LeadStatus | ||
*/ | ||
public function setId($id) | ||
{ | ||
$this->id = $id; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getId() | ||
{ | ||
return $this->id; | ||
} | ||
|
||
/** | ||
* @param string $organizationId | ||
* @return LeadStatus | ||
*/ | ||
public function setOrganizationId($organizationId) | ||
{ | ||
$this->organizationId = $organizationId; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getOrganizationId() | ||
{ | ||
return $this->organizationId; | ||
} | ||
} |