Repositories - Added a new "getById" method

+ Added a new method for retrieving repositories using their ID
This commit is contained in:
Benjamin Blake
2020-03-31 17:19:46 -06:00
parent cc6bd39f82
commit e60312fab3

View File

@ -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