Skip to content

Commit

Permalink
Merge pull request #7 from zoho/beta
Browse files Browse the repository at this point in the history
Beta
  • Loading branch information
raja-7453 authored Jan 6, 2021
2 parents b9200da + f340c14 commit c34d8a9
Show file tree
Hide file tree
Showing 9 changed files with 139 additions and 30 deletions.
39 changes: 32 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
# ZOHO CRM PHP SDK

## Table Of Contents

* [Overview](#overview)
* [Registering a Zoho Client](#registering-a-zoho-client)
* [Environmental Setup](#environmental-setup)
* [Including the SDK in your project](#including-the-sdk-in-your-project)
* [Persistence](#token-persistence)
* [DataBase Persistence](#database-persistence)
* [File Persistence](#file-persistence)
* [Custom Persistence](#custom-persistence)
* [Configuration](#configuration)
* [Initialization](#initializing-the-application)
* [Class Hierarchy](#class-hierarchy)
* [Responses And Exceptions](#responses-and-exceptions)
* [Multi-User support in the PHP SDK](#multi-user-support-in-the-php-sdk)
* [Sample Code](#sdk-sample-code)

## Overview

Zoho CRM PHP SDK offers a way to create client PHP applications that can be integrated with Zoho CRM.
Expand Down Expand Up @@ -61,7 +78,7 @@ You can include the SDK to your project using:
- Run the command below:

```sh
composer require zohocrm/php-sdk:3.0.0
composer require zohocrm/php-sdk:3.0.1
```

- The PHP SDK will be installed and a package named vendor will be created in the workspace of your client app.
Expand All @@ -82,11 +99,12 @@ Token persistence refers to storing and utilizing the authentication tokens that

### Table of Contents

- DataBase Persistence
- [DataBase Persistence](#database-persistence)

- [File Persistence](#file-persistence)

- File Persistence
- [Custom Persistence](#custom-persistence)

- Custom Persistence

### Implementing OAuth Persistence

Expand Down Expand Up @@ -311,20 +329,27 @@ Before you get started with creating your PHP application, you need to register
```php
/*
* autoRefreshFields
* autoRefreshFields (default value is false)
* true - all the modules' fields will be auto-refreshed in the background, every hour.
* false - the fields will not be auto-refreshed in the background. The user can manually delete the file(s) or refresh the fields using methods from ModuleFieldsHandler(com\zoho\crm\api\util\ModuleFieldsHandler)
*
* pickListValidation
* pickListValidation (default value is true)
* A boolean field that validates user input for a pick list field and allows or disallows the addition of a new value to the list.
* true - the SDK validates the input. If the value does not exist in the pick list, the SDK throws an error.
* false - the SDK does not validate the input and makes the API request with the user’s input to the pick list
*
* enableSSLVerification (default value is true)
* A boolean field to enable or disable curl certificate verification
* true - the SDK verifies the authenticity of certificate
* false - the SDK skips the verification
*/
$autoRefreshFields = false;
$pickListValidation = false;
$sdkConfig = (new SDKConfigBuilder())->setAutoRefreshFields($autoRefreshFields)->setPickListValidation($pickListValidation)->build();
$enableSSLVerification = true;
$sdkConfig = (new SDKConfigBuilder())->setAutoRefreshFields($autoRefreshFields)->setPickListValidation($pickListValidation)->setSSLVerification($enableSSLVerification)->build();
```
- Create an instance of RequestProxy containing the proxy properties of the user.
Expand Down
5 changes: 5 additions & 0 deletions src/com/zoho/api/authenticator/OAuthToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,11 @@ public function getResponseFromServer($request_params)

curl_setopt($curl_pointer, CURLOPT_CUSTOMREQUEST, Constants::REQUEST_METHOD_POST);

if(!Initializer::getInitializer()->getSDKConfig()->isSSLVerificationEnabled())
{
curl_setopt($curl_pointer, CURLOPT_SSL_VERIFYPEER, false);
}

$result = curl_exec($curl_pointer);

curl_close($curl_pointer);
Expand Down
35 changes: 32 additions & 3 deletions src/com/zoho/crm/api/SDKConfigBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,20 @@ class SDKConfigBuilder

private $pickListValidation;

private $enableSSLVerification;

public function __Construct()
{
$this->autoRefreshFields = false;

$this->pickListValidation = true;

$this->enableSSLVerification = true;
}

/**
* This is a setter method to set autoRefreshFields.
* @param autoRefreshFields
* @param autoRefreshFields
*/
public function setAutoRefreshFields(bool $autoRefreshFields)
{
Expand All @@ -39,13 +43,24 @@ public function setPickListValidation(bool $pickListValidation)
return $this;
}

/**
* This is a setter method to set enableSSLVerification.
* @param enableSSLVerification
*/
public function setSSLVerification(bool $enableSSLVerification)
{
$this->enableSSLVerification = $enableSSLVerification;

return $this;
}

/**
* The method to build the SDKConfig instance
* @returns An instance of SDKConfig
*/
public function build()
{
return new \com\zoho\crm\api\sdkconfigbuilder\SDKConfig($this->autoRefreshFields, $this->pickListValidation);
return new \com\zoho\crm\api\sdkconfigbuilder\SDKConfig($this->autoRefreshFields, $this->pickListValidation, $this->enableSSLVerification);
}
}

Expand All @@ -60,16 +75,21 @@ class SDKConfig

private $pickListValidation;

private $enableSSLVerification;

/**
* Creates an instance of SDKConfig with the given parameters
* @param autoRefreshFields - A boolean representing autoRefreshFields
* @param pickListValidation - A boolean representing pickListValidation
* @param enableSSLVerification - A boolean representing enableSSLVerification
*/
public function __Construct(bool $autoRefreshFields, bool $pickListValidation)
public function __Construct(bool $autoRefreshFields, bool $pickListValidation, bool $enableSSLVerification)
{
$this->autoRefreshFields = $autoRefreshFields;

$this->pickListValidation = $pickListValidation;

$this->enableSSLVerification = $enableSSLVerification;
}

/**
Expand All @@ -89,5 +109,14 @@ public function getPickListValidation()
{
return $this->pickListValidation;
}

/**
* This is a getter method to get enableSSLVerification.
* @return A boolean representing enableSSLVerification
*/
public function isSSLVerificationEnabled()
{
return $this->enableSSLVerification;
}
}
?>
11 changes: 8 additions & 3 deletions src/com/zoho/crm/api/util/APIHTTPConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,16 +193,21 @@ public function fireRequest($converterInstance)
}

$this->setQueryHeaders($curl_options);


if(!Initializer::getInitializer()->getSDKConfig()->isSSLVerificationEnabled())
{
$curl_options[CURLOPT_SSL_VERIFYPEER] = false;
}

curl_setopt_array($curl_pointer, $curl_options);

SDKLogger::info($this->toString());

$response = array();

$response[Constants::RESPONSE] = curl_exec($curl_pointer);

if (curl_errno($curl_pointer))
if (curl_errno($curl_pointer))
{
$response[Constants::ERROR] = curl_error($curl_pointer);
}
Expand Down
47 changes: 41 additions & 6 deletions src/com/zoho/crm/api/util/CommonAPIHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ public function apiCall($className, $encodeType)
}

$converterInstance = $this->getConverterClassInstance(strtolower($responseContentType));

$returnObject = $converterInstance->getWrappedResponse($response[Constants::RESPONSE], $className);

if ($returnObject !== null)
Expand Down Expand Up @@ -393,25 +393,60 @@ private function isExpectedType(Model $model, string $className)
*/
public function getConverterClassInstance($encodeType)
{
switch ($encodeType)
switch ($encodeType)
{
case "application/json":
case "text/plain":
case "application/ld+json":
return new JSONConverter($this);
case "application/xml":
case "text/xml":
return new XMLConverter($this);
case "multipart/form-data":
return new FormDataConverter($this);
case "application/x-download":
case "image/png":
case "image/jpeg":
case "application/zip":
case "image/gif":
case "text/csv":
case "image/tiff":
case "application/octet-stream":
case "image/svg+xml":
case "image/bmp":
case "image/webp":
case "text/csv":
case "text/html":
case "text/css":
case "text/javascript":
case "text/calendar":
case "application/x-download":
case "application/zip":
case "application/pdf":
case "application/java-archive":
case "application/javascript":
case "application/octet-stream":
case "application/xhtml+xml":
case "application/x-bzip":
case "application/msword":
case "application/vnd.openxmlformats-officedocument.wordprocessingml.document":
case "application/gzip":
case "application/x-httpd-php":
case "application/vnd.ms-powerpoint":
case "application/vnd.rar":
case "application/x-sh":
case "application/x-tar":
case "application/vnd.ms-excel":
case "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":
case "application/x-7z-compressed":
case "audio/mpeg":
case "audio/x-ms-wma":
case "audio/vnd.rn-realaudio":
case "audio/x-wav":
case "audio/3gpp":
case "audio/3gpp2":
case "video/mpeg":
case "video/mp4":
case "video/webm":
case "video/3gpp":
case "video/3gpp2":
case "font/ttf":
return new Downloader($this);
}

Expand Down
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.0";
const SDK_VERSION = "3.0.1";

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

Expand Down
17 changes: 11 additions & 6 deletions src/com/zoho/crm/api/util/Downloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,19 @@ public function getResponse($response, $pack)
$responseHeaders = $response[Constants::HEADERS];

$responseContent = $response[Constants::CONTENT];
$contentDisposition = $responseHeaders[Constants::CONTENT_DISPOSITION];
if ($contentDisposition == null)

$contentDisposition = "";

if(array_key_exists(Constants::CONTENT_DISPOSITION, $responseHeaders))
{
$contentDisposition = $responseHeaders[Constants::CONTENT_DISPOSITION1];
}
$contentDisposition = $responseHeaders[Constants::CONTENT_DISPOSITION];

if ($contentDisposition == null)
{
$contentDisposition = $responseHeaders[Constants::CONTENT_DISPOSITION1];
}
}

$fileName = substr($contentDisposition, strrpos($contentDisposition, "'") + 1, strlen($contentDisposition));

if (strpos($fileName, "=") !== false)
Expand Down
9 changes: 7 additions & 2 deletions src/com/zoho/crm/api/util/JSONConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -1103,9 +1103,14 @@ public function buildName($memberName)

$sdkName = lcfirst($name[0]);

for ($nameIndex = 1; $nameIndex < count($name); $nameIndex ++)
for ($nameIndex = 1; $nameIndex < count($name); $nameIndex ++)
{
$firstLetterUppercase = ucfirst($name[$nameIndex]);
$firstLetterUppercase = "";

if(strlen(($name[$nameIndex])) > 0)
{
$firstLetterUppercase = ucfirst($name[$nameIndex]);
}

$sdkName = $sdkName . $firstLetterUppercase;
}
Expand Down
4 changes: 2 additions & 2 deletions src/com/zoho/crm/api/util/Utility.php
Original file line number Diff line number Diff line change
Expand Up @@ -843,13 +843,13 @@ public static function fillDataType()
return;
}

$fieldAPINamesString = ["textarea", "text", "website", "email", "phone", "mediumtext","multiselectlookup", "profileimage"];
$fieldAPINamesString = ["textarea", "text", "website", "email", "phone", "mediumtext","multiselectlookup", "profileimage", "autonumber"];

$fieldAPINamesInteger = ["integer"];

$fieldAPINamesBoolean = ["boolean"];

$fieldAPINamesLong = ["long", "bigint", "autonumber"];
$fieldAPINamesLong = ["long", "bigint"];

$fieldAPINamesDouble = ["double", "percent", "lookup", "currency"];

Expand Down

0 comments on commit c34d8a9

Please sign in to comment.