|
13 | 13 | use Zoho\Desk\Exception\CouldNotReadException;
|
14 | 14 | use Zoho\Desk\Exception\CouldNotSaveException;
|
15 | 15 | use Zoho\Desk\Gateway;
|
| 16 | +use Zoho\OAuth\ZohoOAuth; |
| 17 | + |
| 18 | +// Optional, it's used by the zoho/oauth package |
| 19 | +define('LOGGER_PATH', __DIR__ . '/'); |
16 | 20 |
|
17 | 21 | $configBuilder = ConfigProviderBuilder::getInstance();
|
18 | 22 | $configBuilder->setClientId(/* Client ID */)
|
|
26 | 30 | ->setAccountsUrl(/* Accounts Url */)
|
27 | 31 | ->setTokenPersistencePath(/* Persistence Path */);
|
28 | 32 |
|
29 |
| -$gateway = new Gateway($configBuilder->create()); |
| 33 | +$config = $configBuilder->create(); |
| 34 | +$gateway = new Gateway($config); |
| 35 | + |
| 36 | +// Optional: if you need to register the token first |
| 37 | +// ZohoOAuth::initialize($config->get()); |
| 38 | +// ZohoOAuth::getClientInstance()->generateAccessToken(/* Grant Code */); |
30 | 39 |
|
31 | 40 | /** CRUD Operations **/
|
32 | 41 |
|
33 |
| -$ticketDataObject = $gateway->dataObjectFactory->create('tickets', /* Entity values */); |
| 42 | +$ticketDataObject = $gateway->getDataObjectFactory()->create('tickets', /* Entity values */); |
34 | 43 |
|
35 | 44 | try {
|
36 |
| - $ticketDataObject = $gateway->operationPool->getCreateOperation('tickets')->create($ticketDataObject); |
| 45 | + $ticketDataObject = $gateway->getOperationPool()->getCreateOperation('tickets')->create($ticketDataObject); |
37 | 46 | } catch (CouldNotSaveException $e) {
|
38 | 47 | // Handle the exception...
|
39 | 48 | }
|
40 | 49 |
|
41 | 50 | try {
|
42 |
| - $ticketDataObject = $gateway->operationPool->getReadOperation('tickets')->get(1234); |
| 51 | + $ticketDataObject = $gateway->getOperationPool()->getReadOperation('tickets')->get(1234); |
43 | 52 | } catch (CouldNotReadException $e) {
|
44 | 53 | // Handle the exception...
|
45 | 54 | }
|
46 | 55 |
|
47 | 56 | try {
|
48 |
| - $ticketDataObject = $gateway->operationPool->getUpdateOperation('tickets')->update($ticketDataObject); |
| 57 | + $ticketDataObject = $gateway->getOperationPool()->getUpdateOperation('tickets')->update($ticketDataObject); |
49 | 58 | } catch (CouldNotSaveException $e) {
|
50 | 59 | // Handle the exception...
|
51 | 60 | }
|
52 | 61 |
|
53 | 62 | try {
|
54 |
| - $gateway->operationPool->getDeleteOperation('tickets', ['resolution'])->delete(1234); |
| 63 | + $gateway->getOperationPool()->getDeleteOperation('tickets', ['resolution'])->delete(1234); |
55 | 64 | } catch (CouldNotDeleteException $e) {
|
56 | 65 | // Handle the exception...
|
57 | 66 | }
|
0 commit comments