Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add capability to set host address and data base name #45

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 35 additions & 34 deletions src/crm/api/handler/MassEntityAPIHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@

class MassEntityAPIHandler extends APIHandler
{

private $module = null;

public function __construct($moduleInstance)
{
$this->module = $moduleInstance;
}

public static function getInstance($moduleInstance)
{
return new MassEntityAPIHandler($moduleInstance);
}

public function createRecords($records, $trigger,$lar_id)
{
if (sizeof($records) > 100) {
Expand All @@ -49,9 +49,9 @@ public function createRecords($records, $trigger,$lar_id)
if ($lar_id !== null) {
$requestBodyObj["lar_id"] = $lar_id;
}

$this->requestBody = $requestBodyObj;

// Fire Request
$bulkAPIResponse = APIRequest::getInstance($this)->getBulkAPIResponse();
$createdRecords = array();
Expand All @@ -76,7 +76,7 @@ public function createRecords($records, $trigger,$lar_id)
throw $e;
}
}

public function upsertRecords($records, $trigger,$lar_id,$duplicate_check_fields)
{
if (sizeof($records) > 100) {
Expand Down Expand Up @@ -107,7 +107,7 @@ public function upsertRecords($records, $trigger,$lar_id,$duplicate_check_fields
$requestBodyObj["lar_id"] = $lar_id;
}
$this->requestBody = $requestBodyObj;

// Fire Request
$bulkAPIResponse = APIRequest::getInstance($this)->getBulkAPIResponse();
$upsertRecords = array();
Expand All @@ -132,7 +132,7 @@ public function upsertRecords($records, $trigger,$lar_id,$duplicate_check_fields
throw $e;
}
}

public function updateRecords($records, $trigger)
{
if (sizeof($records) > 100) {
Expand All @@ -155,9 +155,9 @@ public function updateRecords($records, $trigger)
if ($trigger !== null && is_array($trigger)) {
$requestBodyObj["trigger"] = $trigger;
}

$this->requestBody = $requestBodyObj;

// Fire Request
$bulkAPIResponse = APIRequest::getInstance($this)->getBulkAPIResponse();
$upsertRecords = array();
Expand All @@ -182,7 +182,7 @@ public function updateRecords($records, $trigger)
throw $e;
}
}

public function deleteRecords($entityIds)
{
if (sizeof($entityIds) > 100) {
Expand All @@ -193,11 +193,11 @@ public function deleteRecords($entityIds)
$this->requestMethod = APIConstants::REQUEST_METHOD_DELETE;
$this->addHeader("Content-Type", "application/json");
$this->addParam("ids", implode(",", $entityIds)); // converts array to string with specified seperator

// Fire Request
$bulkAPIResponse = APIRequest::getInstance($this)->getBulkAPIResponse();
$responses = $bulkAPIResponse->getEntityResponses();

foreach ($responses as $entityResIns) {
$responseData = $entityResIns->getResponseJSON();
$responseJSON = $responseData["details"];
Expand All @@ -210,22 +210,22 @@ public function deleteRecords($entityIds)
throw $exception;
}
}

public function getAllDeletedRecords($param_map,$header_map)
{
return self::getDeletedRecords($param_map,$header_map,"all");
}

public function getRecycleBinRecords($param_map,$header_map)
{
return self::getDeletedRecords($param_map,$header_map,"recycle");
}

public function getPermanentlyDeletedRecords($param_map,$header_map)
{
return self::getDeletedRecords($param_map,$header_map,"permanent");
}

private function getDeletedRecords($param_map,$header_map,$type)
{
try {
Expand All @@ -248,16 +248,16 @@ private function getDeletedRecords($param_map,$header_map,$type)
self::setTrashRecordProperties($trashRecordInstance, $trashRecord);
array_push($trashRecordList, $trashRecordInstance);
}

$responseInstance->setData($trashRecordList);

return $responseInstance;
} catch (ZCRMException $exception) {
APIExceptionHandler::logException($exception);
throw $exception;
}
}

public function setTrashRecordProperties($trashRecordInstance, $recordProperties)
{
if ($recordProperties['display_name'] != null) {
Expand All @@ -275,7 +275,7 @@ public function setTrashRecordProperties($trashRecordInstance, $recordProperties
}
$trashRecordInstance->setDeletedTime($recordProperties['deleted_time']);
}

public function getRecords($param_map,$header_map)
{
try {
Expand All @@ -297,24 +297,25 @@ public function getRecords($param_map,$header_map)
EntityAPIHandler::getInstance($recordInstance)->setRecordProperties($record);
array_push($recordsList, $recordInstance);
}

$responseInstance->setData($recordsList);

return $responseInstance;
} catch (ZCRMException $exception) {
APIExceptionHandler::logException($exception);
throw $exception;
}
}

public function searchRecords($param_map,$type,$search_value)
{
try {
$this->urlPath = $this->module->getAPIName() . "/search";
$this->requestMethod = APIConstants::REQUEST_METHOD_GET;

$exclusion_array = ["word","phone","email","criteria"];
foreach($exclusion_array as $exclusion){
if(array_key_exists($exclusion, $param_map)){
if(!empty($param_map[$exclusion]) && array_key_exists($exclusion, $param_map)){
unset($param_map[$exclusion]);
}
}
Expand All @@ -332,16 +333,16 @@ public function searchRecords($param_map,$type,$search_value)
EntityAPIHandler::getInstance($recordInstance)->setRecordProperties($record);
array_push($recordsList, $recordInstance);
}

$responseInstance->setData($recordsList);

return $responseInstance;
} catch (ZCRMException $exception) {
APIExceptionHandler::logException($exception);
throw $exception;
}
}

public function massUpdateRecords($idList, $apiName, $value)
{
if (sizeof($idList) > 100) {
Expand All @@ -355,7 +356,7 @@ public function massUpdateRecords($idList, $apiName, $value)
$this->requestBody = $inputJSON;
$this->apiKey = 'data';
$bulkAPIResponse = APIRequest::getInstance($this)->getBulkAPIResponse();

$updatedRecords = array();
$responses = $bulkAPIResponse->getEntityResponses();
$size = sizeof($responses);
Expand All @@ -364,7 +365,7 @@ public function massUpdateRecords($idList, $apiName, $value)
if (APIConstants::STATUS_SUCCESS === $entityResIns->getStatus()) {
$responseData = $entityResIns->getResponseJSON();
$recordJSON = $responseData["details"];

$updatedRecord = ZCRMRecord::getInstance($this->module->getAPIName(), $recordJSON["id"]);
EntityAPIHandler::getInstance($updatedRecord)->setRecordProperties($recordJSON);
array_push($updatedRecords, $updatedRecord);
Expand All @@ -374,14 +375,14 @@ public function massUpdateRecords($idList, $apiName, $value)
}
}
$bulkAPIResponse->setData($updatedRecords);

return $bulkAPIResponse;
} catch (ZCRMException $exception) {
APIExceptionHandler::logException($exception);
throw $exception;
}
}

public function constructJSONForMassUpdate($idList, $apiName, $value)
{
$massUpdateArray = array();
Expand All @@ -391,7 +392,7 @@ public function constructJSONForMassUpdate($idList, $apiName, $value)
$updateJson[$apiName] = $value;
array_push($massUpdateArray, $updateJson);
}

return array(
"data" => $massUpdateArray
);
Expand Down
42 changes: 22 additions & 20 deletions src/oauth/ZohoOAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

class ZohoOAuth
{

private static $configProperties = array();

public static function initialize($configuration)
{
self::setConfigValues($configuration);
Expand Down Expand Up @@ -40,7 +40,7 @@ public static function initialize($configuration)
$oAuthParams->setRedirectURL(self::getConfigValue(ZohoOAuthConstants::REDIRECT_URL));
ZohoOAuthClient::getInstance($oAuthParams);
}

private static function setConfigValues($configuration)
{
$config_keys = array(
Expand All @@ -51,12 +51,14 @@ private static function setConfigValues($configuration)
ZohoOAuthConstants::PERSISTENCE_HANDLER_CLASS,
ZohoOAuthConstants::IAM_URL,
ZohoOAuthConstants::TOKEN_PERSISTENCE_PATH,
ZohoOAuthConstants::HOST_ADDRESS,
ZohoOAuthConstants::DATABASE_NAME,
ZohoOAuthConstants::DATABASE_PORT,
ZohoOAuthConstants::DATABASE_PASSWORD,
ZohoOAuthConstants::DATABASE_USERNAME,
ZohoOAuthConstants::PERSISTENCE_HANDLER_CLASS_NAME
);

if (! array_key_exists(ZohoOAuthConstants::ACCESS_TYPE, $configuration) || $configuration[ZohoOAuthConstants::ACCESS_TYPE] == "") {
self::$configProperties[ZohoOAuthConstants::ACCESS_TYPE] = "offline";
}
Expand All @@ -66,73 +68,73 @@ private static function setConfigValues($configuration)
if (! array_key_exists(ZohoOAuthConstants::IAM_URL, $configuration) || $configuration[ZohoOAuthConstants::IAM_URL] == "") {
self::$configProperties[ZohoOAuthConstants::IAM_URL] = "https://accounts.zoho.com";
}

foreach ($config_keys as $key) {
if (array_key_exists($key, $configuration))
self::$configProperties[$key] = $configuration[$key];
}
}

public static function getConfigValue($key)
{
return isset(self::$configProperties[$key])?self::$configProperties[$key]:"";
}

public static function getAllConfigs()
{
return self::$configProperties;
}

public static function getIAMUrl()
{
return self::getConfigValue(ZohoOAuthConstants::IAM_URL);
}

public static function getGrantURL()
{
return self::getIAMUrl() . "/oauth/v2/auth";
}

public static function getTokenURL()
{
return self::getIAMUrl() . "/oauth/v2/token";
}

public static function getRefreshTokenURL()
{
return self::getIAMUrl() . "/oauth/v2/token";
}

public static function getRevokeTokenURL()
{
return self::getIAMUrl() . "/oauth/v2/token/revoke";
}

public static function getUserInfoURL()
{
return self::getIAMUrl() . "/oauth/user/info";
}

public static function getClientID()
{
return self::getConfigValue(ZohoOAuthConstants::CLIENT_ID);
}

public static function getClientSecret()
{
return self::getConfigValue(ZohoOAuthConstants::CLIENT_SECRET);
}

public static function getRedirectURL()
{
return self::getConfigValue(ZohoOAuthConstants::REDIRECT_URL);
}

public static function getAccessType()
{
return self::getConfigValue(ZohoOAuthConstants::ACCESS_TYPE);
}

public static function getPersistenceHandlerInstance()
{
try {
Expand All @@ -151,12 +153,12 @@ public static function getPersistenceHandlerInstance()
throw new ZohoOAuthException($ex);
}
}

public static function getClientInstance()
{
if (ZohoOAuthClient::getInstanceWithOutParam() == null) {
throw new ZohoOAuthException("ZCRMRestClient::initialize(\$configMap) must be called before this.");

}
return ZohoOAuthClient::getInstanceWithOutParam();
}
Expand Down