diff --git a/src/LooplineSystems/CloseIoApiWrapper/Api/LeadStatusApi.php b/src/LooplineSystems/CloseIoApiWrapper/Api/LeadStatusApi.php new file mode 100644 index 0000000..e5bf9c0 --- /dev/null +++ b/src/LooplineSystems/CloseIoApiWrapper/Api/LeadStatusApi.php @@ -0,0 +1,129 @@ +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(); + } + } +} diff --git a/src/LooplineSystems/CloseIoApiWrapper/CloseIoApiWrapper.php b/src/LooplineSystems/CloseIoApiWrapper/CloseIoApiWrapper.php index d89fbdc..1a2297d 100644 --- a/src/LooplineSystems/CloseIoApiWrapper/CloseIoApiWrapper.php +++ b/src/LooplineSystems/CloseIoApiWrapper/CloseIoApiWrapper.php @@ -10,6 +10,7 @@ namespace LooplineSystems\CloseIoApiWrapper; use LooplineSystems\CloseIoApiWrapper\Api\LeadApi; +use LooplineSystems\CloseIoApiWrapper\Api\LeadStatusApi; use LooplineSystems\CloseIoApiWrapper\Api\OpportunityApi; use LooplineSystems\CloseIoApiWrapper\Library\Api\ApiHandler; @@ -45,6 +46,7 @@ protected function initApiHandler(CloseIoConfig $config) $apiHandler = new ApiHandler($config); $apiHandler->setApi(new LeadApi($apiHandler)); $apiHandler->setApi(new OpportunityApi($apiHandler)); + $apiHandler->setApi(new LeadStatusApi($apiHandler)); return $apiHandler; } @@ -67,6 +69,15 @@ public function getOpportunityApi() return $this->apiHandler->getApi(OpportunityApi::NAME); } + /** + * @return LeadStatusApi + * @throws Library\Exception\ApiNotFoundException + */ + public function getLeadStatusesApi() + { + return $this->apiHandler->getApi(LeadStatusApi::NAME); + } + /** * @return ApiHandler */ diff --git a/src/LooplineSystems/CloseIoApiWrapper/Model/LeadStatus.php b/src/LooplineSystems/CloseIoApiWrapper/Model/LeadStatus.php new file mode 100644 index 0000000..3f7783b --- /dev/null +++ b/src/LooplineSystems/CloseIoApiWrapper/Model/LeadStatus.php @@ -0,0 +1,93 @@ +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; + } +}