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

Commit bb35ccc

Browse files
author
Marco Roßdeutscher
committed
Merge branch 'release/v0.3.1'
2 parents 16b349b + 91564b4 commit bb35ccc

File tree

3 files changed

+52
-14
lines changed

3 files changed

+52
-14
lines changed

src/LooplineSystems/CloseIoApiWrapper/Api/LeadApi.php

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
<?php
22
/**
3-
* Close.io Api Wrapper - LLS Internet GmbH - Loopline Systems
4-
*
5-
* @link https://github.com/loopline-systems/closeio-api-wrapper for the canonical source repository
6-
* @copyright Copyright (c) 2014 LLS Internet GmbH - Loopline Systems (http://www.loopline-systems.com)
7-
* @license https://github.com/loopline-systems/closeio-api-wrapper/blob/master/LICENSE (MIT Licence)
8-
*/
3+
* Close.io Api Wrapper - LLS Internet GmbH - Loopline Systems
4+
*
5+
* @link https://github.com/loopline-systems/closeio-api-wrapper for the canonical source repository
6+
* @copyright Copyright (c) 2014 LLS Internet GmbH - Loopline Systems (http://www.loopline-systems.com)
7+
* @license https://github.com/loopline-systems/closeio-api-wrapper/blob/master/LICENSE (MIT Licence)
8+
*/
99

1010
namespace LooplineSystems\CloseIoApiWrapper\Api;
1111

1212
use LooplineSystems\CloseIoApiWrapper\CloseIoResponse;
1313
use LooplineSystems\CloseIoApiWrapper\Library\Api\AbstractApi;
14+
use LooplineSystems\CloseIoApiWrapper\Library\Curl\Curl;
1415
use LooplineSystems\CloseIoApiWrapper\Library\Exception\InvalidNewLeadPropertyException;
1516
use LooplineSystems\CloseIoApiWrapper\Library\Exception\InvalidParamException;
16-
use LooplineSystems\CloseIoApiWrapper\Model\Lead;
1717
use LooplineSystems\CloseIoApiWrapper\Library\Exception\ResourceNotFoundException;
18+
use LooplineSystems\CloseIoApiWrapper\Model\Lead;
1819

1920
class LeadApi extends AbstractApi
2021
{
@@ -30,7 +31,7 @@ protected function initUrls()
3031
'add-lead' => '/lead/',
3132
'get-lead' => '/lead/[:id]/',
3233
'update-lead' => '/lead/[:id]/',
33-
'delete-lead' => '/lead/[:id]/'
34+
'delete-lead' => '/lead/[:id]/',
3435
];
3536
}
3637

@@ -40,7 +41,7 @@ protected function initUrls()
4041
public function getAllLeads()
4142
{
4243
/** @var Lead[] $leads */
43-
$leads = array();
44+
$leads = [];
4445

4546
$apiRequest = $this->prepareRequest('get-leads');
4647

@@ -54,6 +55,7 @@ public function getAllLeads()
5455
$leads[] = new Lead($lead);
5556
}
5657
}
58+
5759
return $leads;
5860
}
5961

@@ -65,7 +67,7 @@ public function getAllLeads()
6567
public function findLeads(array $queryParams)
6668
{
6769
/** @var Lead[] $leads */
68-
$leads = array();
70+
$leads = [];
6971
if (count($queryParams) > 0) {
7072
$queryParams = ['query' => $this->buildQueryString($queryParams)];
7173
}
@@ -94,6 +96,7 @@ private function buildQueryString(array $params)
9496
$flattened[] = $key . '=' . $value;
9597
}
9698
$queryString = implode('&', $flattened);
99+
97100
return $queryString;
98101
}
99102

@@ -114,6 +117,7 @@ public function getLead($id)
114117
} else {
115118
throw new ResourceNotFoundException();
116119
}
120+
117121
return $lead;
118122
}
119123

@@ -127,6 +131,7 @@ public function addLead(Lead $lead)
127131

128132
$lead = json_encode($lead);
129133
$apiRequest = $this->prepareRequest('add-lead', $lead);
134+
130135
return $this->triggerPost($apiRequest);
131136
}
132137

@@ -156,6 +161,7 @@ public function updateLead(Lead $lead)
156161
} else {
157162
throw new ResourceNotFoundException();
158163
}
164+
159165
return $lead;
160166
}
161167

@@ -164,7 +170,8 @@ public function updateLead(Lead $lead)
164170
* @return CloseIoResponse
165171
* @throws ResourceNotFoundException
166172
*/
167-
public function deleteLead($id){
173+
public function deleteLead($id)
174+
{
168175
$apiRequest = $this->prepareRequest('delete-lead', null, ['id' => $id]);
169176

170177
/** @var CloseIoResponse $result */
@@ -193,9 +200,9 @@ public function setCurl($curl)
193200
public function validateLeadForPost(Lead $lead)
194201
{
195202
$invalidProperties = ['id', 'organization', 'tasks', 'opportunities'];
196-
foreach ($invalidProperties as $invalidProperty){
203+
foreach ($invalidProperties as $invalidProperty) {
197204
$getter = 'get' . ucfirst($invalidProperty);
198-
if ($lead->$getter()){
205+
if ($lead->$getter()) {
199206
throw new InvalidNewLeadPropertyException('Cannot post ' . $invalidProperty . ' to new lead.');
200207
}
201208
}

src/LooplineSystems/CloseIoApiWrapper/Model/Task.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ class Task implements \JsonSerializable
1717
use ObjectHydrateHelperTrait;
1818
use JsonSerializableHelperTrait;
1919

20+
/**
21+
* @var string
22+
*/
23+
private $type;
24+
2025
/**
2126
* @var string
2227
*/
@@ -101,6 +106,25 @@ public function __construct($data = null)
101106
}
102107
}
103108

109+
/**
110+
* @return string
111+
*/
112+
public function getType()
113+
{
114+
return $this->type;
115+
}
116+
117+
/**
118+
* @param string $type
119+
* @return $this
120+
*/
121+
public function setType($type)
122+
{
123+
$this->type = $type;
124+
125+
return $this;
126+
}
127+
104128
/**
105129
* @return string
106130
*/

tests/LooplineSystems/CloseIoApi/Api/LeadTest.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use LooplineSystems\CloseIoApiWrapper\Model\Lead;
1414
use LooplineSystems\CloseIoApiWrapper\Model\Opportunity;
1515
use LooplineSystems\CloseIoApiWrapper\Model\Phone;
16+
use LooplineSystems\CloseIoApiWrapper\Model\Task;
1617

1718
class LeadTest extends \PHPUnit_Framework_TestCase
1819
{
@@ -45,6 +46,11 @@ public function testCreateDynamicLead($data)
4546
$hydratedLead = new Lead($data);
4647
$dynamicLead = new Lead();
4748

49+
$tasks = [];
50+
foreach ($data['tasks'] as $task) {
51+
$tasks[] = new Task($task);
52+
}
53+
4854
$dynamicLead->setId($data['id']);
4955
$dynamicLead->setStatusId($data['status_id']);
5056
$dynamicLead->setStatusLabel($data['status_label']);
@@ -54,7 +60,7 @@ public function testCreateDynamicLead($data)
5460
$dynamicLead->setOrganization($data['organization']);
5561
$dynamicLead->setCreatedBy($data['created_by']);
5662
$dynamicLead->setUrl($data['url']);
57-
$dynamicLead->setTasks($data['tasks']);
63+
$dynamicLead->setTasks($tasks);
5864
$dynamicLead->setName($data['name']);
5965
$dynamicLead->setContacts($data['contacts']);
6066
$dynamicLead->setDateCreated($data['date_created']);
@@ -137,6 +143,7 @@ public function fullLeadProvider()
137143
'url' => 'http://www.test-url.com',
138144
'tasks' => [
139145
[
146+
'_type' => 'lead',
140147
'due_date' => '01-01-2016',
141148
'text' => 'Test Task Text',
142149
'assigned_to' => 'dfaslk2324',

0 commit comments

Comments
 (0)