Files
sugar-cube-client/src/Api/Organizations.php
Benjamin Blake 70f978847e Large changes to inter-object interfaces + More
+ 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
2020-02-26 20:23:06 -07:00

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