Skip to content

Commit

Permalink
replace get() with HttpClient in Role API
Browse files Browse the repository at this point in the history
  • Loading branch information
Art4 committed Feb 16, 2024
1 parent 0ef4c14 commit 8701a38
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/Redmine/Api/Role.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
use Redmine\Exception;
use Redmine\Exception\SerializerException;
use Redmine\Exception\UnexpectedResponseException;
use Redmine\Http\HttpFactory;
use Redmine\Serializer\JsonSerializer;

/**
* Listing roles.
Expand Down Expand Up @@ -96,10 +98,25 @@ public function listing($forceUpdate = false)
*
* @param int $id the role id
*
* @return array
* @return array|false|string information about the role as array or false|string on error
*/
public function show($id)
{
return $this->get('/roles/' . urlencode(strval($id)) . '.json');
$this->lastResponse = $this->getHttpClient()->request(HttpFactory::makeJsonRequest(
'GET',
'/roles/' . urlencode(strval($id)) . '.json'
));

$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();
}
}
}

0 comments on commit 8701a38

Please sign in to comment.