Skip to content

Commit

Permalink
Zendesk\API\Http log_api_calls
Browse files Browse the repository at this point in the history
  • Loading branch information
ecoologic committed Nov 17, 2023
1 parent 660d798 commit 685ea92
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CBP_UPGRADE_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <subdomain> <email> <api token>`. 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
Expand Down
4 changes: 3 additions & 1 deletion src/Zendesk/API/Http.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 8 additions & 0 deletions src/Zendesk/API/HttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down

0 comments on commit 685ea92

Please sign in to comment.