Files
sugar-cube-client/src/Api/Organizations.php
Benjamin Blake b17224ce39 Refactored and reorganized
+ 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
2020-02-20 13:08:41 -07:00

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;
}
}
}