Skip to content

Commit

Permalink
Merge pull request #2 from zoho/beta
Browse files Browse the repository at this point in the history
Beta
  • Loading branch information
Aswin97 authored Nov 11, 2020
2 parents 10a5726 + 94d1f4c commit 7b15792
Show file tree
Hide file tree
Showing 31 changed files with 24,543 additions and 1 deletion.
614 changes: 614 additions & 0 deletions samples/main/Test.php

Large diffs are not rendered by default.

821 changes: 821 additions & 0 deletions samples/src/com/zoho/crm/api/attachments/Attachment.php

Large diffs are not rendered by default.

579 changes: 579 additions & 0 deletions samples/src/com/zoho/crm/api/blueprint/BluePrint.php

Large diffs are not rendered by default.

479 changes: 479 additions & 0 deletions samples/src/com/zoho/crm/api/bulkread/BulkRead.php

Large diffs are not rendered by default.

616 changes: 616 additions & 0 deletions samples/src/com/zoho/crm/api/bulkwrite/BulkWrite.php

Large diffs are not rendered by default.

852 changes: 852 additions & 0 deletions samples/src/com/zoho/crm/api/contactroles/ContactRoles.php

Large diffs are not rendered by default.

1,118 changes: 1,118 additions & 0 deletions samples/src/com/zoho/crm/api/currencies/Currency.php

Large diffs are not rendered by default.

381 changes: 381 additions & 0 deletions samples/src/com/zoho/crm/api/customview/CustomView.php

Large diffs are not rendered by default.

1,023 changes: 1,023 additions & 0 deletions samples/src/com/zoho/crm/api/fields/Fields.php

Large diffs are not rendered by default.

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

use com\zoho\crm\api\ParameterMap;

use com\zoho\crm\api\file\APIException;

use com\zoho\crm\api\file\ActionWrapper;

use com\zoho\crm\api\file\BodyWrapper;

use com\zoho\crm\api\file\FileOperations;

use com\zoho\crm\api\file\SuccessResponse;

use com\zoho\crm\api\file\GetFileParam;

use com\zoho\crm\api\file\FileBodyWrapper;

use com\zoho\crm\api\util\StreamWrapper;

class File
{
/**
* <h3> Upload File</h3>
* This method is used to upload a file and print the response.
* @throws Exception
*/
public static function uploadFiles()
{
//Get instance of RecordOperations Class
$fileOperations = new FileOperations();

//Get instance of FileBodyWrapper Class that will contain the request body
$bodyWrapper = new BodyWrapper();

//Get instance of StreamWrapper class that takes absolute path of the file to be attached as parameter
$streamWrapper = new StreamWrapper(null, null, "/Users/abc-XXX/Desktop/py.html");

//Get instance of StreamWrapper class that takes absolute path of the file to be attached as parameter
$streamWrapper1 = new StreamWrapper(null, null, "/Users/abc-XXX/Desktop/one.txt");

//Get instance of StreamWrapper class that takes absolute path of the file to be attached as parameter
$streamWrapper2 = new StreamWrapper(null, null, "/Users/abc-XXX/Desktop/pic.jpg");

//Set file to the FileBodyWrapper instance
$bodyWrapper->setFile([$streamWrapper, $streamWrapper1, $streamWrapper2 ]);

//Get instance of ParameterMap Class
$paramInstance = new ParameterMap();

//Call uploadFiles method that takes BodyWrapper instance as parameter.
$response = $fileOperations->uploadFiles($bodyWrapper, $paramInstance);

if($response != null)
{
//Get the status code from response
echo("Status code " . $response->getStatusCode() . "\n");

//Get object from response
$actionHandler = $response->getObject();

if($actionHandler instanceof ActionWrapper)
{
//Get the received ActionWrapper instance
$actionWrapper = $actionHandler;

//Get the list of obtained action responses
$actionResponses = $actionWrapper->getData();

foreach ($actionResponses as $actionResponse)
{
//Check if the request is successful
if($actionResponse instanceof SuccessResponse)
{
//Get the received SuccessResponse instance
$successResponse = $actionResponse;

//Get the Status
echo("Status: " . $successResponse->getStatus()->getValue() . "\n");

//Get the Code
echo("Code: " . $successResponse->getCode()->getValue() . "\n");

echo("Details: " );

if($successResponse->getDetails() != null)
{
//Get the details map
foreach ($successResponse->getDetails() as $keyName => $keyValue)
{
//Get each value in the map
echo($keyName . ": " . $keyValue . "\n");
}
}

//Get the Message
echo("Message: " . $successResponse->getMessage()->getValue() . "\n");
}
//Check if the request returned an exception
else if($actionResponse instanceof APIException)
{
//Get the received APIException instance
$exception = $actionResponse;

//Get the Status
echo("Status: " . $exception->getStatus()->getValue() . "\n");

//Get the Code
echo("Code: " . $exception->getCode()->getValue() . "\n");

echo("Details: " );

if($exception->getDetails() != null)
{
//Get the details map
foreach ($exception->getDetails() as $keyName => $keyValue)
{
//Get each value in the map
echo($keyName . ": " . $keyValue . "\n");
}
}

//Get the Message
echo("Message: " . $exception->getMessage()->getValue() . "\n");
}
}
}
//Check if the request returned an exception
else if($actionHandler instanceof APIException)
{
//Get the received APIException instance
$exception = $actionHandler;

//Get the Status
echo("Status: " . $exception->getStatus()->getValue() . "\n");

//Get the Code
echo("Code: " . $exception->getCode()->getValue() . "\n");

echo("Details: " );

if($exception->getDetails() != null)
{
//Get the details map
foreach ($exception->getDetails() as $keyName => $keyValue)
{
//Get each value in the map
echo($keyName . ": " . $keyValue . "\n");
}
}

//Get the Message
echo("Message: " . $exception->getMessage()->getValue() . "\n");
}
}
}

/**
* <h3> Get File</h3>
* @param id - The ID of the uploaded File.
* @param destinationFolder - The absolute path of the destination folder to store the File
* @throws Exception
*/
public static function getFile(string $id, string $destinationFolder)
{
//example
//id = "3477061000005177002";
//destinationFolder = "/Users/user_name/Desktop"

//Get instance of FileOperations Class
$fileOperations = new FileOperations();

//Get instance of ParameterMap Class
$paramInstance = new ParameterMap();

$paramInstance->add(GetFileParam::id(), $id);

//Call getFile method that takes paramInstance as parameters
$response = $fileOperations->getFile($paramInstance);

if($response != null)
{
//Get the status code from response
echo("Status code " . $response->getStatusCode() . "\n");

if(in_array($response->getStatusCode(), array(204, 304)))
{
echo($response->getStatusCode() == 204? "No Content\n" : "Not Modified\n");

return;
}

//Get object from response
$responseHandler = $response->getObject();

if($responseHandler instanceof FileBodyWrapper)
{
//Get object from response
$fileBodyWrapper = $responseHandler;

//Get StreamWrapper instance from the returned FileBodyWrapper instance
$streamWrapper = $fileBodyWrapper->getFile();

//Create a file instance with the absolute_file_path
$fp = fopen($destinationFolder."/".$streamWrapper->getName(), "w");

//Get stream from the response
$stream = $streamWrapper->getStream();

fputs($fp, $stream);

fclose($fp);
}
//Check if the request returned an exception
else if($responseHandler instanceof APIException)
{
//Get the received APIException instance
$exception = $responseHandler;

//Get the Status
echo("Status: " . $exception->getStatus()->getValue() . "\n");

//Get the Code
echo("Code: " . $exception->getCode()->getValue() . "\n");

if($exception->getDetails() != null)
{
echo("Details: \n");

//Get the details map
foreach ($exception->getDetails() as $keyName => $keyValue)
{
//Get each value in the map
echo($keyName . ": " . $keyValue . "\n");
}
}

//Get the Message
echo("Message: " . $exception->getMessage()->getValue() . "\n");
}
}
}
}
85 changes: 85 additions & 0 deletions samples/src/com/zoho/crm/api/initializer/Initialize.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php
namespace samples\src\com\zoho\crm\api\initializer;

use com\zoho\api\authenticator\OAuthToken;

use com\zoho\api\authenticator\TokenType;

use com\zoho\api\authenticator\store\DBStore;

use com\zoho\api\authenticator\store\FileStore;

use com\zoho\crm\api\Initializer;

use com\zoho\crm\api\UserSignature;

use com\zoho\crm\api\dc\USDataCenter;

use com\zoho\api\logger\Logger;

use com\zoho\api\logger\Levels;

use com\zoho\crm\api\SDKConfigBuilder;

use com\zoho\crm\api\RequestProxy;

class Initialize
{
public static function initialize()
{
/*
* Create an instance of Logger Class that takes two parameters
* 1 -> Level of the log messages to be logged. Can be configured by typing Levels "." and choose any level from the list displayed.
* 2 -> Absolute file path, where messages need to be logged.
*/
$logger = Logger::getInstance(Levels::INFO, "/Users/user_name/Documents/php_sdk_log.log");

//Create an UserSignature instance that takes user Email as parameter
$user = new UserSignature("[email protected]");

/*
* Configure the environment
* which is of the pattern Domain.Environment
* Available Domains: USDataCenter, EUDataCenter, INDataCenter, CNDataCenter, AUDataCenter
* Available Environments: PRODUCTION, DEVELOPER, SANDBOX
*/
$environment = USDataCenter::PRODUCTION();

//Create a Token instance
$token = new OAuthToken("clientId", "clientSecret", "REFRESH/GRANT token", TokenType::REFRESH/GRANT, "redirectURL");

//Create an instance of TokenStore

$tokenstore = new DBStore("hostName", "dataBaseName", "userName", "password", "portNumber");

// $tokenstore = new FileStore("absolute_file_path");

$resourcePath = "/Users/user_name/Documents/phpsdk-application";

$autoRefreshFields = true;

$pickListValidation = false;

$builderInstance = new SDKConfigBuilder();

//Create an instance of SDKConfig
$configInstance = $builderInstance->setPickListValidation($pickListValidation)->setAutoRefreshFields($autoRefreshFields)->build();

//Create an instance of RequestProxy
$requestProxy = new RequestProxy("proxyHost", "proxyPort", "proxyUser", "password");

/*
* Call static initialize method of Initializer class that takes the arguments
* 1 -> UserSignature instance
* 2 -> Environment instance
* 3 -> Token instance
* 4 -> TokenStore instance
* 5 -> SDKConfig instance
* 6 -> The path containing the absolute directory path to store user specific JSON files containing module fields information.
* 7 -> Logger instance (Optional)
* 8 -> RequestProxy instance (Optional)
*/
Initializer::initialize($user, $environment, $token, $tokenstore, $configInstance, $resourcePath, $logger, $requestProxy);
}
}
?>
Loading

0 comments on commit 7b15792

Please sign in to comment.