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

Commit

Permalink
Refactor to fluent interface
Browse files Browse the repository at this point in the history
  • Loading branch information
dlimars committed Mar 8, 2016
1 parent db10779 commit ddccd5e
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 15 deletions.
9 changes: 4 additions & 5 deletions src/LooplineSystems/CloseIoApiWrapper/Api/LeadStatusApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ public function addStatus(LeadStatus $status)
*/
public function updateStatus(LeadStatus $status)
{
if ($status->getStatusId() == null) {
if ($status->getId() == null) {
throw new InvalidParamException('When updating a status you must provide the statuses ID');
}

$id = $status->getStatusId();
$status->setStatusId(null);
$id = $status->getId();
$status->setId(null);

$status = json_encode($status);
$apiRequest = $this->prepareRequest('update-status', $status, ['id' => $id]);
Expand All @@ -68,7 +68,7 @@ public function updateStatus(LeadStatus $status)
}

/**
* @return \LooplineSystems\CloseIoApiWrapper\Model\LeadStatus[]
* @return LeadStatus[]
*/
public function getAllStatus()
{
Expand All @@ -82,7 +82,6 @@ public function getAllStatus()

if ($result->getReturnCode() == 200) {
$rawData = $result->getData()[CloseIoResponse::GET_ALL_RESPONSE_LEADS_KEY];

foreach ($rawData as $status) {
$statuses[] = new LeadStatus($status);
}
Expand Down
63 changes: 53 additions & 10 deletions src/LooplineSystems/CloseIoApiWrapper/Model/LeadStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,40 +11,83 @@ class LeadStatus implements \JsonSerializable
use ObjectHydrateHelperTrait;
use JsonSerializableHelperTrait;

/**
* @var string
*/
private $label;

/**
* @var string
*/
private $id;

public function __construct(array $fields)
/**
* @var string
*/
private $organizationId;

/**
* LeadStatus constructor.
* @param array $data
*/
public function __construct(array $data)
{
foreach($fields as $field=>$value)
{
if (property_exists($this, $field)) {
$this->$field = $value;
}
if ($data) {
$this->hydrate($data);
}
}

/**
* @param $label
* @return LeadStatus
*/
public function setStatusLabel($label)
public function setLabel($label)
{
$this->label = $label;
return $this;
}

public function getStatusLabel()
/**
* @return string
*/
public function getLabel()
{
return $this->label;
}

public function setStatusId($id)
/**
* @param $id
* @return LeadStatus
*/
public function setId($id)
{
$this->id = $id;
return $this;
}

public function getStatusId()
/**
* @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;
}
}

0 comments on commit ddccd5e

Please sign in to comment.