mirror of
https://github.com/sitelease/sugar-cube-client.git
synced 2025-10-29 19:12:30 +01:00
+ Created a new core interface (called RequestChainable) and applied it to most of the objects using a trait + Altered the `__construct()` and `fromJson()` methods of all model classes by replacing the second parameter ($apiRequester) with a $caller parameter + Altered the `__construct()` method of all requester classes to make them accept $client by reference instead of by value + Altered the `__construct()` method of all requester classes by replacing the second parameter ($authToken) with a $caller parameter + Changed the name of several methods and properties + Altered several docblocks
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\Model\Organization;
|
|
|
|
use Gitea\Api\Abstracts\AbstractApiRequester;
|
|
|
|
class Organizations extends AbstractApiRequester
|
|
{
|
|
|
|
/**
|
|
* Get an organization using its username and parse
|
|
* it's information into an organization object
|
|
*
|
|
* Example:
|
|
* ```
|
|
* $client->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($client, $this, json_decode($body));
|
|
} else {
|
|
return $response;
|
|
}
|
|
} catch (ServerException $serverError) {
|
|
return $response;
|
|
}
|
|
}
|
|
|
|
}
|