Skip to content

Commit c4e1cbb

Browse files
authored
Merge pull request #19 from zoho/beta
Supported External ID and improved Utility methods
2 parents d9c8b55 + d146f16 commit c4e1cbb

14 files changed

+159
-42
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ You can include the SDK to your project using:
7878
- Run the command below:
7979

8080
```sh
81-
composer require zohocrm/php-sdk:3.0.3
81+
composer require zohocrm/php-sdk:3.1.0
8282
```
8383

8484
- The PHP SDK will be installed and a package named vendor will be created in the workspace of your client app.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
namespace com\zoho\crm\api\record;
3+
4+
use com\zoho\crm\api\Header;
5+
6+
class DeleteRecordHeader
7+
{
8+
9+
public static final function XEXTERNAL()
10+
{
11+
return new Header('X-EXTERNAL', 'com.zoho.crm.api.Record.DeleteRecordHeader');
12+
13+
}
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
namespace com\zoho\crm\api\record;
3+
4+
use com\zoho\crm\api\Header;
5+
6+
class DeleteRecordsHeader
7+
{
8+
9+
public static final function XEXTERNAL()
10+
{
11+
return new Header('X-EXTERNAL', 'com.zoho.crm.api.Record.DeleteRecordsHeader');
12+
13+
}
14+
}

src/com/zoho/crm/api/record/GetRecordHeader.php

+5
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,9 @@ public static final function IfModifiedSince()
1111
return new Header('If-Modified-Since', 'com.zoho.crm.api.Record.GetRecordHeader');
1212

1313
}
14+
public static final function XEXTERNAL()
15+
{
16+
return new Header('X-EXTERNAL', 'com.zoho.crm.api.Record.GetRecordHeader');
17+
18+
}
1419
}

src/com/zoho/crm/api/record/GetRecordsHeader.php

+5
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,9 @@ public static final function IfModifiedSince()
1111
return new Header('If-Modified-Since', 'com.zoho.crm.api.Record.GetRecordsHeader');
1212

1313
}
14+
public static final function XEXTERNAL()
15+
{
16+
return new Header('X-EXTERNAL', 'com.zoho.crm.api.Record.GetRecordsHeader');
17+
18+
}
1419
}

src/com/zoho/crm/api/record/RecordOperations.php

+18-6
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,10 @@ public function getRecord(string $id, string $moduleAPIName, ParameterMap $para
4646
* @param string $id A string
4747
* @param string $moduleAPIName A string
4848
* @param BodyWrapper $request An instance of BodyWrapper
49+
* @param HeaderMap $headerInstance An instance of HeaderMap
4950
* @return APIResponse An instance of APIResponse
5051
*/
51-
public function updateRecord(string $id, string $moduleAPIName, BodyWrapper $request)
52+
public function updateRecord(string $id, string $moduleAPIName, BodyWrapper $request, HeaderMap $headerInstance=null)
5253
{
5354
$handlerInstance=new CommonAPIHandler();
5455
$apiPath="";
@@ -61,6 +62,7 @@ public function updateRecord(string $id, string $moduleAPIName, BodyWrapper $re
6162
$handlerInstance->setCategoryMethod(Constants::REQUEST_CATEGORY_UPDATE);
6263
$handlerInstance->setContentType('application/json');
6364
$handlerInstance->setRequest($request);
65+
$handlerInstance->setHeader($headerInstance);
6466
Utility::getFields($moduleAPIName);
6567
$handlerInstance->setModuleAPIName($moduleAPIName);
6668
return $handlerInstance->apiCall(ActionHandler::class, 'application/json');
@@ -72,9 +74,10 @@ public function updateRecord(string $id, string $moduleAPIName, BodyWrapper $re
7274
* @param string $id A string
7375
* @param string $moduleAPIName A string
7476
* @param ParameterMap $paramInstance An instance of ParameterMap
77+
* @param HeaderMap $headerInstance An instance of HeaderMap
7578
* @return APIResponse An instance of APIResponse
7679
*/
77-
public function deleteRecord(string $id, string $moduleAPIName, ParameterMap $paramInstance=null)
80+
public function deleteRecord(string $id, string $moduleAPIName, ParameterMap $paramInstance=null, HeaderMap $headerInstance=null)
7881
{
7982
$handlerInstance=new CommonAPIHandler();
8083
$apiPath="";
@@ -86,6 +89,7 @@ public function deleteRecord(string $id, string $moduleAPIName, ParameterMap $p
8689
$handlerInstance->setHttpMethod(Constants::REQUEST_METHOD_DELETE);
8790
$handlerInstance->setCategoryMethod(Constants::REQUEST_METHOD_DELETE);
8891
$handlerInstance->setParam($paramInstance);
92+
$handlerInstance->setHeader($headerInstance);
8993
return $handlerInstance->apiCall(ActionHandler::class, 'application/json');
9094

9195
}
@@ -142,9 +146,10 @@ public function createRecords(string $moduleAPIName, BodyWrapper $request)
142146
* The method to update records
143147
* @param string $moduleAPIName A string
144148
* @param BodyWrapper $request An instance of BodyWrapper
149+
* @param HeaderMap $headerInstance An instance of HeaderMap
145150
* @return APIResponse An instance of APIResponse
146151
*/
147-
public function updateRecords(string $moduleAPIName, BodyWrapper $request)
152+
public function updateRecords(string $moduleAPIName, BodyWrapper $request, HeaderMap $headerInstance=null)
148153
{
149154
$handlerInstance=new CommonAPIHandler();
150155
$apiPath="";
@@ -156,6 +161,7 @@ public function updateRecords(string $moduleAPIName, BodyWrapper $request)
156161
$handlerInstance->setContentType('application/json');
157162
$handlerInstance->setRequest($request);
158163
$handlerInstance->setMandatoryChecker(true);
164+
$handlerInstance->setHeader($headerInstance);
159165
Utility::getFields($moduleAPIName);
160166
$handlerInstance->setModuleAPIName($moduleAPIName);
161167
return $handlerInstance->apiCall(ActionHandler::class, 'application/json');
@@ -166,9 +172,10 @@ public function updateRecords(string $moduleAPIName, BodyWrapper $request)
166172
* The method to delete records
167173
* @param string $moduleAPIName A string
168174
* @param ParameterMap $paramInstance An instance of ParameterMap
175+
* @param HeaderMap $headerInstance An instance of HeaderMap
169176
* @return APIResponse An instance of APIResponse
170177
*/
171-
public function deleteRecords(string $moduleAPIName, ParameterMap $paramInstance=null)
178+
public function deleteRecords(string $moduleAPIName, ParameterMap $paramInstance=null, HeaderMap $headerInstance=null)
172179
{
173180
$handlerInstance=new CommonAPIHandler();
174181
$apiPath="";
@@ -178,6 +185,7 @@ public function deleteRecords(string $moduleAPIName, ParameterMap $paramInstanc
178185
$handlerInstance->setHttpMethod(Constants::REQUEST_METHOD_DELETE);
179186
$handlerInstance->setCategoryMethod(Constants::REQUEST_METHOD_DELETE);
180187
$handlerInstance->setParam($paramInstance);
188+
$handlerInstance->setHeader($headerInstance);
181189
return $handlerInstance->apiCall(ActionHandler::class, 'application/json');
182190

183191
}
@@ -186,9 +194,10 @@ public function deleteRecords(string $moduleAPIName, ParameterMap $paramInstanc
186194
* The method to upsert records
187195
* @param string $moduleAPIName A string
188196
* @param BodyWrapper $request An instance of BodyWrapper
197+
* @param HeaderMap $headerInstance An instance of HeaderMap
189198
* @return APIResponse An instance of APIResponse
190199
*/
191-
public function upsertRecords(string $moduleAPIName, BodyWrapper $request)
200+
public function upsertRecords(string $moduleAPIName, BodyWrapper $request, HeaderMap $headerInstance=null)
192201
{
193202
$handlerInstance=new CommonAPIHandler();
194203
$apiPath="";
@@ -200,6 +209,7 @@ public function upsertRecords(string $moduleAPIName, BodyWrapper $request)
200209
$handlerInstance->setCategoryMethod(Constants::REQUEST_CATEGORY_ACTION);
201210
$handlerInstance->setContentType('application/json');
202211
$handlerInstance->setRequest($request);
212+
$handlerInstance->setHeader($headerInstance);
203213
Utility::getFields($moduleAPIName);
204214
$handlerInstance->setModuleAPIName($moduleAPIName);
205215
return $handlerInstance->apiCall(ActionHandler::class, 'application/json');
@@ -233,9 +243,10 @@ public function getDeletedRecords(string $moduleAPIName, ParameterMap $paramIns
233243
* The method to search records
234244
* @param string $moduleAPIName A string
235245
* @param ParameterMap $paramInstance An instance of ParameterMap
246+
* @param HeaderMap $headerInstance An instance of HeaderMap
236247
* @return APIResponse An instance of APIResponse
237248
*/
238-
public function searchRecords(string $moduleAPIName, ParameterMap $paramInstance=null)
249+
public function searchRecords(string $moduleAPIName, ParameterMap $paramInstance=null, HeaderMap $headerInstance=null)
239250
{
240251
$handlerInstance=new CommonAPIHandler();
241252
$apiPath="";
@@ -246,6 +257,7 @@ public function searchRecords(string $moduleAPIName, ParameterMap $paramInstanc
246257
$handlerInstance->setHttpMethod(Constants::REQUEST_METHOD_GET);
247258
$handlerInstance->setCategoryMethod(Constants::REQUEST_CATEGORY_READ);
248259
$handlerInstance->setParam($paramInstance);
260+
$handlerInstance->setHeader($headerInstance);
249261
Utility::getFields($moduleAPIName);
250262
$handlerInstance->setModuleAPIName($moduleAPIName);
251263
return $handlerInstance->apiCall(ResponseHandler::class, 'application/json');
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
namespace com\zoho\crm\api\record;
3+
4+
use com\zoho\crm\api\Header;
5+
6+
class SearchRecordsHeader
7+
{
8+
9+
public static final function XEXTERNAL()
10+
{
11+
return new Header('X-EXTERNAL', 'com.zoho.crm.api.Record.SearchRecordsHeader');
12+
13+
}
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
namespace com\zoho\crm\api\record;
3+
4+
use com\zoho\crm\api\Header;
5+
6+
class UpdateRecordHeader
7+
{
8+
9+
public static final function XEXTERNAL()
10+
{
11+
return new Header('X-EXTERNAL', 'com.zoho.crm.api.Record.UpdateRecordHeader');
12+
13+
}
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
namespace com\zoho\crm\api\record;
3+
4+
use com\zoho\crm\api\Header;
5+
6+
class UpdateRecordsHeader
7+
{
8+
9+
public static final function XEXTERNAL()
10+
{
11+
return new Header('X-EXTERNAL', 'com.zoho.crm.api.Record.UpdateRecordsHeader');
12+
13+
}
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
namespace com\zoho\crm\api\record;
3+
4+
use com\zoho\crm\api\Header;
5+
6+
class UpsertRecordsHeader
7+
{
8+
9+
public static final function XEXTERNAL()
10+
{
11+
return new Header('X-EXTERNAL', 'com.zoho.crm.api.Record.UpsertRecordsHeader');
12+
13+
}
14+
}

src/com/zoho/crm/api/util/Constants.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ class Constants
464464

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

467-
const SDK_VERSION = "3.0.3";
467+
const SDK_VERSION = "3.1.0";
468468

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

src/com/zoho/crm/api/util/ModuleFieldsHandler.php

+23-27
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ class ModuleFieldsHandler
2020
*/
2121
private static function getDirectory()
2222
{
23-
$resourcesPath = Initializer::getInitializer()->getResourcePath() . DIRECTORY_SEPARATOR . Constants::FIELD_DETAILS_DIRECTORY;
24-
25-
return $resourcesPath;
23+
return Initializer::getInitializer()->getResourcePath() . DIRECTORY_SEPARATOR . Constants::FIELD_DETAILS_DIRECTORY;
2624
}
2725

2826
private static function getFileName()
@@ -35,7 +33,7 @@ private static function getFileName()
3533

3634
return base64_encode(implode(array_map("chr", $input)));
3735
}
38-
36+
3937
/**
4038
* The method to delete fields JSON File of the current user.
4139
* @throws SDKException
@@ -45,10 +43,10 @@ public static function deleteFieldsFile()
4543
try
4644
{
4745
$fileName = self::getFileName();
48-
46+
4947
$recordFieldDetailsPath = self::getDirectory() . DIRECTORY_SEPARATOR . $fileName . ".json";
5048

51-
if (file_exists($recordFieldDetailsPath))
49+
if (file_exists($recordFieldDetailsPath))
5250
{
5351
unlink($recordFieldDetailsPath);
5452
}
@@ -58,11 +56,11 @@ public static function deleteFieldsFile()
5856
$sdkException = new SDKException(null, null, null, $e);
5957

6058
SDKLogger::severeError(Constants::DELETE_FIELD_FILE_ERROR, $sdkException);
61-
59+
6260
throw $sdkException;
6361
}
6462
}
65-
63+
6664
/**
6765
* The method to delete all the field JSON files under resources directory.
6866
*/
@@ -71,15 +69,15 @@ public static function deleteAllFieldFiles()
7169
try
7270
{
7371
$recordFieldDetailsDirectory = self::getDirectory();
74-
72+
7573
$files = glob($recordFieldDetailsDirectory.'/*.json');
76-
77-
// Deleting all the files in the list
74+
75+
// Deleting all the files in the list
7876
foreach($files as $file)
79-
{
80-
if(is_file($file))
81-
// Delete the given file
82-
unlink($file);
77+
{
78+
if(is_file($file))
79+
// Delete the given file
80+
unlink($file);
8381
}
8482
}
8583
catch (\Exception $e)
@@ -91,7 +89,7 @@ public static function deleteAllFieldFiles()
9189
throw $sdkException;
9290
}
9391
}
94-
92+
9593
/**
9694
* The method to delete fields of the given module from the current user's fields JSON file.
9795
* @param module A string representing the module.
@@ -101,24 +99,22 @@ private static function deleteFields($module)
10199
try
102100
{
103101
$recordFieldDetailsPath = self::getDirectory() . DIRECTORY_SEPARATOR . self::getFileName() . ".json";
104-
105-
if (file_exists($recordFieldDetailsPath))
102+
103+
if (file_exists($recordFieldDetailsPath))
106104
{
107105
$recordFieldDetailsJSON = Initializer::getJSON($recordFieldDetailsPath);
108106

109107
if(array_key_exists(strtolower($module), $recordFieldDetailsJSON))
110108
{
111109
Utility::deleteFields($recordFieldDetailsJSON, $module);
112-
110+
113111
file_put_contents($recordFieldDetailsPath, json_encode($recordFieldDetailsJSON));
114112
}
115113
}
116114
}
117115
catch (\Exception $e)
118116
{
119-
$sdkException = new SDKException(null, null, null, $e);
120-
121-
throw $sdkException;
117+
throw new SDKException(null, null, null, $e);
122118
}
123119
}
124120

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

135131
Utility::getFields($module);
136-
}
137-
catch (SDKException $ex)
132+
}
133+
catch (SDKException $ex)
138134
{
139135
SDKLogger::severeError(Constants::REFRESH_SINGLE_MODULE_FIELDS_ERROR . $module, $ex);
140136

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

153149
public static function refreshAllModules()
154150
{
155-
try
151+
try
156152
{
157153
Utility::refreshModules();
158-
}
159-
catch (SDKException $ex)
154+
}
155+
catch (SDKException $ex)
160156
{
161157
SDKLogger::severeError(Constants::REFRESH_ALL_MODULE_FIELDS_ERROR, $ex);
162158

0 commit comments

Comments
 (0)