Skip to content

Commit

Permalink
Replace get() with HttpClient in Issue API
Browse files Browse the repository at this point in the history
  • Loading branch information
Art4 committed Feb 16, 2024
1 parent b2c70cd commit 2dc34f7
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/Redmine/Api/Issue.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Redmine\Exception;
use Redmine\Exception\SerializerException;
use Redmine\Exception\UnexpectedResponseException;
use Redmine\Http\HttpFactory;
use Redmine\Serializer\JsonSerializer;
use Redmine\Serializer\PathSerializer;
use Redmine\Serializer\XmlSerializer;
Expand Down Expand Up @@ -132,17 +133,30 @@ public function all(array $params = [])
* @param int $id the issue id
* @param array $params extra associated data
*
* @return array information about the issue
* @return array|false|string information about the issue as array or false|string on error
*/
public function show($id, array $params = [])
{
if (isset($params['include']) && is_array($params['include'])) {
$params['include'] = implode(',', $params['include']);
}

return $this->get(
$this->lastResponse = $this->getHttpClient()->request(HttpFactory::makeJsonRequest(
'GET',
PathSerializer::create('/issues/' . urlencode(strval($id)) . '.json', $params)->getPath()
);
));

$body = $this->lastResponse->getContent();

if ('' === $body) {
return false;
}

try {
return JsonSerializer::createFromString($body)->getNormalized();
} catch (SerializerException $e) {
return 'Error decoding body as JSON: ' . $e->getPrevious()->getMessage();
}
}

/**
Expand Down

0 comments on commit 2dc34f7

Please sign in to comment.