Skip to content

Commit

Permalink
Supported External ID and improved Utility methods
Browse files Browse the repository at this point in the history
  • Loading branch information
raja-7453 committed May 13, 2021
1 parent 6218e64 commit d146f16
Show file tree
Hide file tree
Showing 14 changed files with 159 additions and 42 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ You can include the SDK to your project using:
- Run the command below:

```sh
composer require zohocrm/php-sdk:3.0.3
composer require zohocrm/php-sdk:3.1.0
```

- The PHP SDK will be installed and a package named vendor will be created in the workspace of your client app.
Expand Down
14 changes: 14 additions & 0 deletions src/com/zoho/crm/api/record/DeleteRecordHeader.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
namespace com\zoho\crm\api\record;

use com\zoho\crm\api\Header;

class DeleteRecordHeader
{

public static final function XEXTERNAL()
{
return new Header('X-EXTERNAL', 'com.zoho.crm.api.Record.DeleteRecordHeader');

}
}
14 changes: 14 additions & 0 deletions src/com/zoho/crm/api/record/DeleteRecordsHeader.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
namespace com\zoho\crm\api\record;

use com\zoho\crm\api\Header;

class DeleteRecordsHeader
{

public static final function XEXTERNAL()
{
return new Header('X-EXTERNAL', 'com.zoho.crm.api.Record.DeleteRecordsHeader');

}
}
5 changes: 5 additions & 0 deletions src/com/zoho/crm/api/record/GetRecordHeader.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,9 @@ public static final function IfModifiedSince()
return new Header('If-Modified-Since', 'com.zoho.crm.api.Record.GetRecordHeader');

}
public static final function XEXTERNAL()
{
return new Header('X-EXTERNAL', 'com.zoho.crm.api.Record.GetRecordHeader');

}
}
5 changes: 5 additions & 0 deletions src/com/zoho/crm/api/record/GetRecordsHeader.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,9 @@ public static final function IfModifiedSince()
return new Header('If-Modified-Since', 'com.zoho.crm.api.Record.GetRecordsHeader');

}
public static final function XEXTERNAL()
{
return new Header('X-EXTERNAL', 'com.zoho.crm.api.Record.GetRecordsHeader');

}
}
24 changes: 18 additions & 6 deletions src/com/zoho/crm/api/record/RecordOperations.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@ public function getRecord(string $id, string $moduleAPIName, ParameterMap $para
* @param string $id A string
* @param string $moduleAPIName A string
* @param BodyWrapper $request An instance of BodyWrapper
* @param HeaderMap $headerInstance An instance of HeaderMap
* @return APIResponse An instance of APIResponse
*/
public function updateRecord(string $id, string $moduleAPIName, BodyWrapper $request)
public function updateRecord(string $id, string $moduleAPIName, BodyWrapper $request, HeaderMap $headerInstance=null)
{
$handlerInstance=new CommonAPIHandler();
$apiPath="";
Expand All @@ -61,6 +62,7 @@ public function updateRecord(string $id, string $moduleAPIName, BodyWrapper $re
$handlerInstance->setCategoryMethod(Constants::REQUEST_CATEGORY_UPDATE);
$handlerInstance->setContentType('application/json');
$handlerInstance->setRequest($request);
$handlerInstance->setHeader($headerInstance);
Utility::getFields($moduleAPIName);
$handlerInstance->setModuleAPIName($moduleAPIName);
return $handlerInstance->apiCall(ActionHandler::class, 'application/json');
Expand All @@ -72,9 +74,10 @@ public function updateRecord(string $id, string $moduleAPIName, BodyWrapper $re
* @param string $id A string
* @param string $moduleAPIName A string
* @param ParameterMap $paramInstance An instance of ParameterMap
* @param HeaderMap $headerInstance An instance of HeaderMap
* @return APIResponse An instance of APIResponse
*/
public function deleteRecord(string $id, string $moduleAPIName, ParameterMap $paramInstance=null)
public function deleteRecord(string $id, string $moduleAPIName, ParameterMap $paramInstance=null, HeaderMap $headerInstance=null)
{
$handlerInstance=new CommonAPIHandler();
$apiPath="";
Expand All @@ -86,6 +89,7 @@ public function deleteRecord(string $id, string $moduleAPIName, ParameterMap $p
$handlerInstance->setHttpMethod(Constants::REQUEST_METHOD_DELETE);
$handlerInstance->setCategoryMethod(Constants::REQUEST_METHOD_DELETE);
$handlerInstance->setParam($paramInstance);
$handlerInstance->setHeader($headerInstance);
return $handlerInstance->apiCall(ActionHandler::class, 'application/json');

}
Expand Down Expand Up @@ -142,9 +146,10 @@ public function createRecords(string $moduleAPIName, BodyWrapper $request)
* The method to update records
* @param string $moduleAPIName A string
* @param BodyWrapper $request An instance of BodyWrapper
* @param HeaderMap $headerInstance An instance of HeaderMap
* @return APIResponse An instance of APIResponse
*/
public function updateRecords(string $moduleAPIName, BodyWrapper $request)
public function updateRecords(string $moduleAPIName, BodyWrapper $request, HeaderMap $headerInstance=null)
{
$handlerInstance=new CommonAPIHandler();
$apiPath="";
Expand All @@ -156,6 +161,7 @@ public function updateRecords(string $moduleAPIName, BodyWrapper $request)
$handlerInstance->setContentType('application/json');
$handlerInstance->setRequest($request);
$handlerInstance->setMandatoryChecker(true);
$handlerInstance->setHeader($headerInstance);
Utility::getFields($moduleAPIName);
$handlerInstance->setModuleAPIName($moduleAPIName);
return $handlerInstance->apiCall(ActionHandler::class, 'application/json');
Expand All @@ -166,9 +172,10 @@ public function updateRecords(string $moduleAPIName, BodyWrapper $request)
* The method to delete records
* @param string $moduleAPIName A string
* @param ParameterMap $paramInstance An instance of ParameterMap
* @param HeaderMap $headerInstance An instance of HeaderMap
* @return APIResponse An instance of APIResponse
*/
public function deleteRecords(string $moduleAPIName, ParameterMap $paramInstance=null)
public function deleteRecords(string $moduleAPIName, ParameterMap $paramInstance=null, HeaderMap $headerInstance=null)
{
$handlerInstance=new CommonAPIHandler();
$apiPath="";
Expand All @@ -178,6 +185,7 @@ public function deleteRecords(string $moduleAPIName, ParameterMap $paramInstanc
$handlerInstance->setHttpMethod(Constants::REQUEST_METHOD_DELETE);
$handlerInstance->setCategoryMethod(Constants::REQUEST_METHOD_DELETE);
$handlerInstance->setParam($paramInstance);
$handlerInstance->setHeader($headerInstance);
return $handlerInstance->apiCall(ActionHandler::class, 'application/json');

}
Expand All @@ -186,9 +194,10 @@ public function deleteRecords(string $moduleAPIName, ParameterMap $paramInstanc
* The method to upsert records
* @param string $moduleAPIName A string
* @param BodyWrapper $request An instance of BodyWrapper
* @param HeaderMap $headerInstance An instance of HeaderMap
* @return APIResponse An instance of APIResponse
*/
public function upsertRecords(string $moduleAPIName, BodyWrapper $request)
public function upsertRecords(string $moduleAPIName, BodyWrapper $request, HeaderMap $headerInstance=null)
{
$handlerInstance=new CommonAPIHandler();
$apiPath="";
Expand All @@ -200,6 +209,7 @@ public function upsertRecords(string $moduleAPIName, BodyWrapper $request)
$handlerInstance->setCategoryMethod(Constants::REQUEST_CATEGORY_ACTION);
$handlerInstance->setContentType('application/json');
$handlerInstance->setRequest($request);
$handlerInstance->setHeader($headerInstance);
Utility::getFields($moduleAPIName);
$handlerInstance->setModuleAPIName($moduleAPIName);
return $handlerInstance->apiCall(ActionHandler::class, 'application/json');
Expand Down Expand Up @@ -233,9 +243,10 @@ public function getDeletedRecords(string $moduleAPIName, ParameterMap $paramIns
* The method to search records
* @param string $moduleAPIName A string
* @param ParameterMap $paramInstance An instance of ParameterMap
* @param HeaderMap $headerInstance An instance of HeaderMap
* @return APIResponse An instance of APIResponse
*/
public function searchRecords(string $moduleAPIName, ParameterMap $paramInstance=null)
public function searchRecords(string $moduleAPIName, ParameterMap $paramInstance=null, HeaderMap $headerInstance=null)
{
$handlerInstance=new CommonAPIHandler();
$apiPath="";
Expand All @@ -246,6 +257,7 @@ public function searchRecords(string $moduleAPIName, ParameterMap $paramInstanc
$handlerInstance->setHttpMethod(Constants::REQUEST_METHOD_GET);
$handlerInstance->setCategoryMethod(Constants::REQUEST_CATEGORY_READ);
$handlerInstance->setParam($paramInstance);
$handlerInstance->setHeader($headerInstance);
Utility::getFields($moduleAPIName);
$handlerInstance->setModuleAPIName($moduleAPIName);
return $handlerInstance->apiCall(ResponseHandler::class, 'application/json');
Expand Down
14 changes: 14 additions & 0 deletions src/com/zoho/crm/api/record/SearchRecordsHeader.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
namespace com\zoho\crm\api\record;

use com\zoho\crm\api\Header;

class SearchRecordsHeader
{

public static final function XEXTERNAL()
{
return new Header('X-EXTERNAL', 'com.zoho.crm.api.Record.SearchRecordsHeader');

}
}
14 changes: 14 additions & 0 deletions src/com/zoho/crm/api/record/UpdateRecordHeader.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
namespace com\zoho\crm\api\record;

use com\zoho\crm\api\Header;

class UpdateRecordHeader
{

public static final function XEXTERNAL()
{
return new Header('X-EXTERNAL', 'com.zoho.crm.api.Record.UpdateRecordHeader');

}
}
14 changes: 14 additions & 0 deletions src/com/zoho/crm/api/record/UpdateRecordsHeader.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
namespace com\zoho\crm\api\record;

use com\zoho\crm\api\Header;

class UpdateRecordsHeader
{

public static final function XEXTERNAL()
{
return new Header('X-EXTERNAL', 'com.zoho.crm.api.Record.UpdateRecordsHeader');

}
}
14 changes: 14 additions & 0 deletions src/com/zoho/crm/api/record/UpsertRecordsHeader.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
namespace com\zoho\crm\api\record;

use com\zoho\crm\api\Header;

class UpsertRecordsHeader
{

public static final function XEXTERNAL()
{
return new Header('X-EXTERNAL', 'com.zoho.crm.api.Record.UpsertRecordsHeader');

}
}
2 changes: 1 addition & 1 deletion src/com/zoho/crm/api/util/Constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ class Constants

const FORM_REQUEST_EXCEPTION = "Exception in forming request body : ";

const SDK_VERSION = "3.0.3";
const SDK_VERSION = "3.1.0";

const API_CALL_EXCEPTION = "Exception in current API call execution : ";

Expand Down
50 changes: 23 additions & 27 deletions src/com/zoho/crm/api/util/ModuleFieldsHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ class ModuleFieldsHandler
*/
private static function getDirectory()
{
$resourcesPath = Initializer::getInitializer()->getResourcePath() . DIRECTORY_SEPARATOR . Constants::FIELD_DETAILS_DIRECTORY;

return $resourcesPath;
return Initializer::getInitializer()->getResourcePath() . DIRECTORY_SEPARATOR . Constants::FIELD_DETAILS_DIRECTORY;
}

private static function getFileName()
Expand All @@ -35,7 +33,7 @@ private static function getFileName()

return base64_encode(implode(array_map("chr", $input)));
}

/**
* The method to delete fields JSON File of the current user.
* @throws SDKException
Expand All @@ -45,10 +43,10 @@ public static function deleteFieldsFile()
try
{
$fileName = self::getFileName();

$recordFieldDetailsPath = self::getDirectory() . DIRECTORY_SEPARATOR . $fileName . ".json";

if (file_exists($recordFieldDetailsPath))
if (file_exists($recordFieldDetailsPath))
{
unlink($recordFieldDetailsPath);
}
Expand All @@ -58,11 +56,11 @@ public static function deleteFieldsFile()
$sdkException = new SDKException(null, null, null, $e);

SDKLogger::severeError(Constants::DELETE_FIELD_FILE_ERROR, $sdkException);

throw $sdkException;
}
}

/**
* The method to delete all the field JSON files under resources directory.
*/
Expand All @@ -71,15 +69,15 @@ public static function deleteAllFieldFiles()
try
{
$recordFieldDetailsDirectory = self::getDirectory();

$files = glob($recordFieldDetailsDirectory.'/*.json');
// Deleting all the files in the list

// Deleting all the files in the list
foreach($files as $file)
{
if(is_file($file))
// Delete the given file
unlink($file);
{
if(is_file($file))
// Delete the given file
unlink($file);
}
}
catch (\Exception $e)
Expand All @@ -91,7 +89,7 @@ public static function deleteAllFieldFiles()
throw $sdkException;
}
}

/**
* The method to delete fields of the given module from the current user's fields JSON file.
* @param module A string representing the module.
Expand All @@ -101,24 +99,22 @@ private static function deleteFields($module)
try
{
$recordFieldDetailsPath = self::getDirectory() . DIRECTORY_SEPARATOR . self::getFileName() . ".json";
if (file_exists($recordFieldDetailsPath))

if (file_exists($recordFieldDetailsPath))
{
$recordFieldDetailsJSON = Initializer::getJSON($recordFieldDetailsPath);

if(array_key_exists(strtolower($module), $recordFieldDetailsJSON))
{
Utility::deleteFields($recordFieldDetailsJSON, $module);

file_put_contents($recordFieldDetailsPath, json_encode($recordFieldDetailsJSON));
}
}
}
catch (\Exception $e)
{
$sdkException = new SDKException(null, null, null, $e);

throw $sdkException;
throw new SDKException(null, null, null, $e);
}
}

Expand All @@ -133,8 +129,8 @@ public static function refreshFields(string $module)
self::deleteFields($module);

Utility::getFields($module);
}
catch (SDKException $ex)
}
catch (SDKException $ex)
{
SDKLogger::severeError(Constants::REFRESH_SINGLE_MODULE_FIELDS_ERROR . $module, $ex);

Expand All @@ -152,11 +148,11 @@ public static function refreshFields(string $module)

public static function refreshAllModules()
{
try
try
{
Utility::refreshModules();
}
catch (SDKException $ex)
}
catch (SDKException $ex)
{
SDKLogger::severeError(Constants::REFRESH_ALL_MODULE_FIELDS_ERROR, $ex);

Expand Down
Loading

0 comments on commit d146f16

Please sign in to comment.