mirror of
https://github.com/sitelease/sugar-cube-client.git
synced 2025-11-02 04:52:30 +01:00
Huge number of updates, too tired to list them all
+ Added a bunch of API handler classes that will use the already created models + Created a new Client class that will connect to new API handler classes + Created new collection classes
This commit is contained in:
46
src/Api/Organizations.php
Normal file
46
src/Api/Organizations.php
Normal file
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace Gitea\Api;
|
||||
|
||||
use GuzzleHttp\Psr7\Response;
|
||||
|
||||
use Gitea\Client;
|
||||
use Gitea\Models\Organization;
|
||||
|
||||
use Gitea\Api\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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user