From 685ea929135b9370a95317aa8eb6fc98b72362c5 Mon Sep 17 00:00:00 2001 From: "Erik Trapin (ecoologic)" Date: Fri, 17 Nov 2023 11:30:23 +1000 Subject: [PATCH] Zendesk\API\Http log_api_calls --- CBP_UPGRADE_GUIDE.md | 4 ++++ README.md | 19 +++++++++++++++++++ src/Zendesk/API/Http.php | 4 +++- src/Zendesk/API/HttpClient.php | 8 ++++++++ 4 files changed, 34 insertions(+), 1 deletion(-) diff --git a/CBP_UPGRADE_GUIDE.md b/CBP_UPGRADE_GUIDE.md index 33d20ac9..feaac997 100644 --- a/CBP_UPGRADE_GUIDE.md +++ b/CBP_UPGRADE_GUIDE.md @@ -26,6 +26,10 @@ The iterator is available in `v3.0`, which you can download with: composer update zendesk/zendesk_api_client_php ``` +## Debugging + +Please refer to the [README](./README.md#debugging). + ## API calls Note the query parameters change in these two URL examples: diff --git a/README.md b/README.md index bf7e2cd8..73282390 100755 --- a/README.md +++ b/README.md @@ -275,11 +275,30 @@ speed up the process and would make sure that everybody follows the community's ### Debugging +#### REPL + To help would be contributors, we've added a REPL tool. It is a simple wrapper for [psysh](http://psysh.org) and symfony's console. On your terminal, run `bin/console `. This would automatically create an instance of `Zendesk\API\HttpClient` on $client variable. After that you would be able to enter any valid php statement. The goal of the tool is to speed up the process in which developers can experiment on the code base. +#### HTTP client print API calls + +You can print a line with details about every API call with: + +```php +$client = new ZendeskAPI($subdomain); +$client->log_api_calls = true; +``` + +#### HTTP client debug + +You can inspect this object for info about requests and responses: + +```php +$client->getDebug(); +``` + ## Copyright and license Copyright 2013-present Zendesk diff --git a/src/Zendesk/API/Http.php b/src/Zendesk/API/Http.php index 6e9f9a4a..14fba49f 100644 --- a/src/Zendesk/API/Http.php +++ b/src/Zendesk/API/Http.php @@ -90,7 +90,9 @@ public static function send( if ($client->getAuth()) { list ($request, $requestOptions) = $client->getAuth()->prepareRequest($request, $requestOptions); } - // echo "\nExternal API call: " . $request->getMethod() . " " . $request->getUri() . "\n"; + if ($client->log_api_calls) { + echo "\nZendesk\API\Http: " . $request->getMethod() . " " . $request->getUri() . "\n"; + } $response = $client->guzzle->send($request, $requestOptions); } catch (RequestException $e) { $requestException = RequestException::create($e->getRequest(), $e->getResponse(), $e); diff --git a/src/Zendesk/API/HttpClient.php b/src/Zendesk/API/HttpClient.php index 9895ba8f..4a54ec0d 100644 --- a/src/Zendesk/API/HttpClient.php +++ b/src/Zendesk/API/HttpClient.php @@ -159,6 +159,14 @@ class HttpClient */ protected $debug; + /** + * Whether or not to print every API call details right before execution + * + * E.G.: Zendesk\API\Http: GET https://my_company.zendesk.com/api/v2/tickets.json + * + * @var boolean + */ + public $log_api_calls = false; /** * @var \GuzzleHttp\Client */