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

Commit

Permalink
Merge branch 'release/v0.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco Roßdeutscher committed Mar 8, 2016
2 parents d7d930d + ec53b12 commit 4efaeeb
Show file tree
Hide file tree
Showing 11 changed files with 622 additions and 133 deletions.
129 changes: 129 additions & 0 deletions src/LooplineSystems/CloseIoApiWrapper/Api/LeadStatusApi.php
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();
}
}
}
11 changes: 11 additions & 0 deletions src/LooplineSystems/CloseIoApiWrapper/CloseIoApiWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}
Expand All @@ -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
*/
Expand Down
49 changes: 35 additions & 14 deletions src/LooplineSystems/CloseIoApiWrapper/Model/Address.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php
/**
* Close.io Api Wrapper - LLS Internet GmbH - Loopline Systems
*
* @link https://github.com/loopline-systems/closeio-api-wrapper for the canonical source repository
* @copyright Copyright (c) 2014 LLS Internet GmbH - Loopline Systems (http://www.loopline-systems.com)
* @license https://github.com/loopline-systems/closeio-api-wrapper/blob/master/LICENSE (MIT Licence)
*/
* Close.io Api Wrapper - LLS Internet GmbH - Loopline Systems
*
* @link https://github.com/loopline-systems/closeio-api-wrapper for the canonical source repository
* @copyright Copyright (c) 2014 LLS Internet GmbH - Loopline Systems (http://www.loopline-systems.com)
* @license https://github.com/loopline-systems/closeio-api-wrapper/blob/master/LICENSE (MIT Licence)
*/

namespace LooplineSystems\CloseIoApiWrapper\Model;

Expand Down Expand Up @@ -58,7 +58,7 @@ class Address implements \JsonSerializable
public function __construct(array $data = null)
{
if ($data) {
$this->hydrate($data, [], array('setAddress_1' => 'setAddress1', 'setAddress_2' => 'setAddress2'));
$this->hydrate($data, [], ['setAddress_1' => 'setAddress1', 'setAddress_2' => 'setAddress2']);
}
}

Expand All @@ -71,11 +71,14 @@ public function getAddress1()
}

/**
* @param string $address_1
* @param $address_1
* @return $this
*/
public function setAddress1($address_1)
{
$this->address_1 = $address_1;

return $this;
}

/**
Expand All @@ -87,11 +90,14 @@ public function getAddress2()
}

/**
* @param string $address_2
* @param $address_2
* @return $this
*/
public function setAddress2($address_2)
{
$this->address_2 = $address_2;

return $this;
}

/**
Expand All @@ -103,11 +109,14 @@ public function getCity()
}

/**
* @param string $city
* @param $city
* @return $this
*/
public function setCity($city)
{
$this->city = $city;

return $this;
}

/**
Expand All @@ -119,11 +128,14 @@ public function getCountry()
}

/**
* @param string $country
* @param $country
* @return $this
*/
public function setCountry($country)
{
$this->country = $country;

return $this;
}

/**
Expand All @@ -135,11 +147,14 @@ public function getLabel()
}

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

return $this;
}

/**
Expand All @@ -151,11 +166,14 @@ public function getState()
}

/**
* @param string $state
* @param $state
* @return $this
*/
public function setState($state)
{
$this->state = $state;

return $this;
}

/**
Expand All @@ -167,10 +185,13 @@ public function getZipcode()
}

/**
* @param string $zipcode
* @param $zipcode
* @return $this
*/
public function setZipcode($zipcode)
{
$this->zipcode = $zipcode;

return $this;
}
}
Loading

0 comments on commit 4efaeeb

Please sign in to comment.