Skip to content

Commit

Permalink
Merge pull request #139 from ringcentral/demoJwt
Browse files Browse the repository at this point in the history
Extract Truncated error response
  • Loading branch information
SushilMallRC authored Aug 6, 2024
2 parents 67c9a42 + 0850794 commit 856f9f6
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 11 deletions.
64 changes: 64 additions & 0 deletions demo/errorResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

require_once (__DIR__ . '/_bootstrap.php');

use RingCentral\SDK\SDK;

function errorResponse()
{
$credentials = require (__DIR__ . '/_credentials.php');
$accountId = '~';
$extensionId = '~';
$queryParams = array(
);
$rcsdk = new SDK($credentials['clientId'], $credentials['clientSecret'], $credentials['server'], 'Demo', '1.0.0');

$platform = $rcsdk->platform();
$platform->login(["jwt" => $credentials['RC_JWT']]);

$r = $platform->get("/restapi/v1.0/account/23/extension/{$extensionId}/call-log", $queryParams);

echo $r->text();

echo "\n";
}
function successfulResponse()
{
$credentials = require (__DIR__ . '/_credentials.php');
$accountId = '~';
$extensionId = '~';
$queryParams = array(
);
$rcsdk = new SDK($credentials['clientId'], $credentials['clientSecret'], $credentials['server'], 'Demo', '1.0.0');

$platform = $rcsdk->platform();
$platform->login(["jwt" => $credentials['RC_JWT']]);

$r = $platform->get("/restapi/v1.0/account/{$accountId}/extension/{$extensionId}/call-log", $queryParams);

echo $r->text();

echo "\n";
}
/*
function errorResponseDeleteMethod()
{
$credentials = require (__DIR__ . '/_credentials.php');
$accountId = '~';
$extensionId = '~';
$queryParams = array(
'dateTo' => 'sss'
);
$rcsdk = new SDK($credentials['clientId'], $credentials['clientSecret'], $credentials['server'], 'Demo', '1.0.0');
$platform = $rcsdk->platform();
$platform->login(["jwt" => $credentials['RC_JWT']]);
$r = $platform->delete("/restapi/v1.0/account/{$accountId}/extension/{$extensionId}/call-log", $queryParams);
echo $r->text();
echo "\n";
}*/
successfulResponse();
errorResponse();
22 changes: 11 additions & 11 deletions src/Http/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ protected function loadResponse(RequestInterface $request)
$request->getBody()->rewind();
}

$response = $this->_guzzle->send($request, ['exceptions' => false]);
$response = $this->_guzzle->send($request, ['http_errors' => false, 'exceptions' => false]);

return new ApiResponse($request, $response);

Expand Down Expand Up @@ -127,16 +127,16 @@ protected function parseProperties($method, $url, $queryParams = [], $body = nul
$query = "";
if (!empty($queryParams) && is_array($queryParams)) {
foreach ($queryParams as $key => $value) {
if (is_array($value)){
foreach ($value as $val) {
$query .= $key."=".urlencode($val)."&";
if (is_array($value)) {
foreach ($value as $val) {
$query .= $key . "=" . urlencode($val) . "&";
}
} else {
$query .= $key . "=" . urlencode($value) . "&";
}
}else{
$query .= $key."=".urlencode($value)."&";
}
}
}
$query = rtrim($query,'&');
$query = rtrim($query, '&');
if ($query != "") {
$url = $url . (stristr($url, '?') ? '&' : '?') . $query;
}
Expand Down Expand Up @@ -188,10 +188,10 @@ protected function parseProperties($method, $url, $queryParams = [], $body = nul
// Create request

return [
'method' => $method,
'url' => $url,
'method' => $method,
'url' => $url,
'headers' => $headers,
'body' => $body,
'body' => $body,
];

}
Expand Down

0 comments on commit 856f9f6

Please sign in to comment.