mirror of
https://github.com/sitelease/sugar-cube-client.git
synced 2025-10-29 19:12:30 +01:00
+ Created new a new interface and abstract class for Api classes that support the all() method + Refactored the Repositories Api class + Moved the abstract classes into an "Abstracts" folder + Moved Api Interfaces into an "Interfaces" folder + Corrected namespaces
47 lines
1.1 KiB
PHP
47 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace Gitea\Api;
|
|
|
|
use GuzzleHttp\Psr7\Response;
|
|
|
|
use Gitea\Client;
|
|
use Gitea\Models\Organization;
|
|
|
|
use Gitea\Api\Abstracts\AbstractApi;
|
|
|
|
class Organizations extends AbstractApi
|
|
{
|
|
|
|
/**
|
|
* Get an organization using its username and parse
|
|
* it's information into an organization object
|
|
*
|
|
* Example:
|
|
* ```
|
|
* $giteaClient->organizations()->getByUsername($orgUsername);
|
|
* ```
|
|
*
|
|
* @param string $username
|
|
* @author Benjamin Blake (sitelease.ca)
|
|
*
|
|
* @return Organization|Response
|
|
*/
|
|
public function getByUsername(string $username)
|
|
{
|
|
$client = $this->getClient();
|
|
try {
|
|
$response = $this->get("orgs/$username");
|
|
$statusCode = $response->getStatusCode();
|
|
$body = $response->getBody();
|
|
if ($statusCode == 200) {
|
|
return Organization::fromJson(json_decode($body));
|
|
} else {
|
|
return $response;
|
|
}
|
|
} catch (ServerException $serverError) {
|
|
return $response;
|
|
}
|
|
}
|
|
|
|
}
|