Skip to content

Commit

Permalink
Dependencies update, workflow functionality changed and general updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Cristian Pontes authored and Cristian Pontes committed Aug 13, 2017
1 parent cfed3dd commit b88e39e
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Request/DeleteRecords.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ protected function configureRequest()
* @param $id
* @return DeleteRecords
*/
public function id($id){
public function id($id) {
$this->request->setParam('id', $id);
return $this;
}
Expand Down
10 changes: 9 additions & 1 deletion Request/InsertRecords.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ public function setRecords(array $records)
}

/**
* The workflow rules are only triggered for API V2.
* The API version will be changed automatically to this version
* When the request has only 1 record.
* @see https://www.zoho.eu/crm/help/api/insertrecords.html#Insert_Multiple_records (Notes section)
* @return InsertRecords
*/
public function triggerWorkflow()
Expand All @@ -52,7 +56,7 @@ public function triggerWorkflow()
}

/**
* @param int $ruleId
* @param int $ruleId (ID of a Zoho Assignment Rule)
* @return InsertRecords
*/
public function triggerAssignmentRule($ruleId)
Expand Down Expand Up @@ -93,6 +97,10 @@ public function requireApproval()
*/
public function request()
{
if(count($this->records) < 2) {
$this->request->setParam('version', 2);
}

return $this->request
->setParam('xmlData', $this->records)
->request();
Expand Down
8 changes: 8 additions & 0 deletions Request/UpdateRecords.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ public function setRecords(array $records)
}

/**
* The workflow rules are only triggered for API V2.
* The API version will be changed automatically to this version
* When the request has only 1 record.
* @see https://www.zoho.eu/crm/help/api/insertrecords.html#Insert_Multiple_records (Notes section)
* @return UpdateRecords
*/
public function triggerWorkflow()
Expand Down Expand Up @@ -91,6 +95,10 @@ public function requireApproval()
*/
public function request()
{
if(count($this->records) < 2) {
$this->request->setParam('version', 2);
}

return $this->request
->setParam('xmlData', $this->records)
->request();
Expand Down
17 changes: 15 additions & 2 deletions Tests/Request/InsertRecordsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function testInitialStatus()
$this->assertEquals(4, $this->request->getParam('version'));
}

public function testRecords()
public function testSingleRecord()
{
$record = array('First Name' => 'Cristian', 'Last Name' => 'Pontes');
$this->insertRecords->addRecord($record);
Expand All @@ -29,7 +29,20 @@ public function testRecords()

$this->assertTrue($this->insertRecords->request());

$this->assertEquals(array('version' => 4, 'xmlData' => array($record)), $this->transport->paramList);
$this->assertEquals(array('version' => 2, 'xmlData' => array($record)), $this->transport->paramList);
}

public function testMultipleRecords()
{
$record = array('First Name' => 'Cristian', 'Last Name' => 'Pontes');
$this->insertRecords->addRecord($record);
$this->insertRecords->addRecord($record);

$this->transport->response = true;

$this->assertTrue($this->insertRecords->request());

$this->assertEquals(array('version' => 4, 'xmlData' => array($record, $record)), $this->transport->paramList);
}

public function testTriggerWorkflow()
Expand Down
15 changes: 13 additions & 2 deletions Tests/Request/UpdateRecordsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,25 @@ public function testInitial()
);
}

public function testAddRecord()
public function testSingleRecord()
{
$this->updateRecords->addRecord(array('abc123'));

$this->transport->response = true;

$this->assertTrue($this->updateRecords->request());
$this->assertEquals(array('version' => 4, 'xmlData' => array(array('abc123'))), $this->transport->paramList);
$this->assertEquals(array('version' => 2, 'xmlData' => array(array('abc123'))), $this->transport->paramList);
}

public function testMultipleRecords()
{
$this->updateRecords->addRecord(array('abc123'));
$this->updateRecords->addRecord(array('abc123'));

$this->transport->response = true;

$this->assertTrue($this->updateRecords->request());
$this->assertEquals(array('version' => 4, 'xmlData' => array(array('abc123'), array('abc123'))), $this->transport->paramList);
}

public function testTriggerWorkflow()
Expand Down
6 changes: 6 additions & 0 deletions Tests/ZohoCRMClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ public function testGetRecords()
$this->assertTrue($request instanceof GetRecords);
}

public function testSetModule()
{
$this->client->setModule('Contacts');
$this->assertEquals('Contacts', $this->client->publicRequest()->getModule());
}

public function testGetRecordById()
{
$request = $this->client->getRecordById();
Expand Down
37 changes: 29 additions & 8 deletions ZohoCRMClient.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<?php

namespace CristianPontes\ZohoCRMClient;

use Buzz\Browser;
use Buzz\Client\Curl;
use CristianPontes\ZohoCRMClient\Request;
use CristianPontes\ZohoCRMClient\Transport;
use Psr\Log\LoggerAwareInterface;
Expand All @@ -19,22 +22,31 @@ class ZohoCRMClient implements LoggerAwareInterface
/** @var LoggerInterface */
private $logger;

public function __construct($module, $authToken, $domain = "com")
/**
* ZohoCRMClient constructor.
* @param $module
* @param $authToken
* @param string $domain
* @param int $timeout
*/
public function __construct($module, $authToken, $domain = 'com', $timeout = 5)
{
$this->module = $module;

if ($authToken instanceof Transport\Transport) {
$this->transport = $authToken;
} else {
$curl_client = new Curl();
$curl_client->setTimeout($timeout);
$this->transport = new Transport\XmlDataTransportDecorator(
new Transport\AuthenticationTokenTransportDecorator(
$authToken,
new Transport\BuzzTransport(
new \Buzz\Browser(new \Buzz\Client\Curl()),
'https://crm.zoho.'.$domain.'/crm/private/xml/'
)
new Transport\AuthenticationTokenTransportDecorator(
$authToken,
new Transport\BuzzTransport(
new Browser($curl_client),
'https://crm.zoho.' . $domain . '/crm/private/xml/'
)
);
)
);
}
}

Expand All @@ -52,6 +64,15 @@ public function setLogger(LoggerInterface $logger)
}
}

/**
* Sets the Zoho CRM module, overriding the the actual value
* @param $module
*/
public function setModule($module)
{
$this->module = $module;
}

/**
* @return Request\GetRecords
*/
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
],
"require": {
"php": ">=5.3.3",
"kriswallsmith/buzz": "~0.10",
"kriswallsmith/buzz": "~0.15",
"psr/log": "~1.0.0"
},
"require-dev":{
Expand Down

0 comments on commit b88e39e

Please sign in to comment.