From e60312fab336268e12c096b0d7feb4189a266f27 Mon Sep 17 00:00:00 2001 From: Benjamin Blake Date: Tue, 31 Mar 2020 17:19:46 -0600 Subject: [PATCH] Repositories - Added a new "getById" method + Added a new method for retrieving repositories using their ID --- src/Api/Repositories.php | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/Api/Repositories.php b/src/Api/Repositories.php index e46f426..fc0e528 100644 --- a/src/Api/Repositories.php +++ b/src/Api/Repositories.php @@ -111,6 +111,38 @@ class Repositories extends AbstractAllApiRequester } } + /** + * Get a repository using its ID + * + * Example: + * ``` + * $client->repositories()->getByID($repoId); + * ``` + * + * @param string repoId The ID of the repository + * @return Repository + */ + public function getById(int $repoId) + { + $client = $this->getClient(); + try { + $response = $this->get("/repositories/$repoId"); + $statusCode = $response->getStatusCode(); + $body = (string) $response->getBody(); + if ($statusCode == 200) { + return Repository::fromJson( + $client, + $this, + json_decode($body) + ); + } + return false; + + } catch (ServerException $serverError) { + return false; + } + } + /** * Get the raw contents of a file stored inside a repository * using the repository's name and owner