gitea/src/b3f6728b-8c88-4ee8-9aa0-bce.../code.power

85 lines
1.9 KiB
Plaintext

/**
* List the current user's organizations.
*
* @param int $pageNumber The page number of results to return (1-based).
* @param int $pageSize The page size of results.
*
* @return array|null
* @since 3.2.0
**/
public function list(
int $pageNumber = 1,
int $pageSize = 10
): ?array
{
// Build the request path.
$path = "/user/orgs";
// Get the URI object.
$uri = $this->uri->get($path);
// Add the query parameters for page number and page size.
$uri->setVar('page', $pageNumber);
$uri->setVar('limit', $pageSize);
// Send the get request.
return $this->response->get(
$this->http->get($uri)
);
}
/**
* List a user's organizations.
*
* @param string $username The user's username.
* @param int $pageNumber The page number of results to return (1-based).
* @param int $pageSize The page size of results.
*
* @return array|null
* @since 3.2.0
**/
public function get(
string $username,
int $pageNumber = 1,
int $pageSize = 10
): ?array
{
// Build the request path.
$path = "/users/{$username}/orgs";
// Get the URI object.
$uri = $this->uri->get($path);
// Add the query parameters for page number and page size.
$uri->setVar('page', $pageNumber);
$uri->setVar('limit', $pageSize);
// Send the get request.
return $this->response->get(
$this->http->get($uri)
);
}
/**
* Get user permissions in an organization.
*
* @param string $username The user's username.
* @param string $org The organization name.
*
* @return object|null
* @since 3.2.0
**/
public function permissions(string $username, string $org): ?object
{
// Build the request path.
$path = "/users/{$username}/orgs/{$org}/permissions";
// Send the get request.
return $this->response->get(
$this->http->get(
$this->uri->get($path)
)
);
}