Compare commits

...

2 Commits
5.x ... staging

2 changed files with 1034 additions and 1034 deletions

View File

@ -1,13 +1,13 @@
<?php <?php
/** /**
* @package Joomla.Component.Builder * @package Joomla.Component.Builder
* *
* @created 4th September, 2022 * @created 4th September, 2022
* @author Llewellyn van der Merwe <https://dev.vdm.io> * @author Llewellyn van der Merwe <https://dev.vdm.io>
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder> * @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved. * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt * @license GNU General Public License version 2 or later; see LICENSE.txt
*/ */
namespace VDM\Joomla\Gitea; namespace VDM\Joomla\Gitea;
@ -16,320 +16,320 @@ use VDM\Joomla\Gitea\Abstraction\Api;
/** /**
* The Gitea User * The Gitea User
* *
* @since 3.2.0 * @since 3.2.0
*/ */
class User extends Api class User extends Api
{ {
/** /**
* Get the authenticated user. * Get the authenticated user.
* *
* @return object|null * @return object|null
* @since 3.2.0 * @since 3.2.0
**/ **/
public function authenticate(): ?object public function authenticate(): ?object
{ {
// Build the request path. // Build the request path.
$path = '/user'; $path = '/user';
// Send the get request. // Send the get request.
return $this->response->get( return $this->response->get(
$this->http->get( $this->http->get(
$this->uri->get($path) $this->uri->get($path)
) )
); );
} }
/** /**
* Search for users. * Search for users.
* *
* @param string $keyword The search keyword. * @param string $keyword The search keyword.
* @param int|null $uid Optional. ID of the user to search for. * @param int|null $uid Optional. ID of the user to search for.
* @param int $page Page number of results to return (1-based). * @param int $page Page number of results to return (1-based).
* @param int $limit Page size of results. * @param int $limit Page size of results.
* *
* @return object|null * @return object|null
* @since 3.2.0 * @since 3.2.0
**/ **/
public function search( public function search(
string $keyword, string $keyword,
?int $uid = null, ?int $uid = null,
int $page = 1, int $page = 1,
int $limit = 10 int $limit = 10
): ?object ): ?object
{ {
// Build the request path. // Build the request path.
$path = '/users/search'; $path = '/users/search';
// Build the URI with query parameters. // Build the URI with query parameters.
$uri = $this->uri->get($path); $uri = $this->uri->get($path);
$uri->setVar('q', $keyword); $uri->setVar('q', $keyword);
if ($uid !== null) if ($uid !== null)
{ {
$uri->setVar('uid', $uid); $uri->setVar('uid', $uid);
} }
$uri->setVar('page', $page); $uri->setVar('page', $page);
$uri->setVar('limit', $limit); $uri->setVar('limit', $limit);
// Send the get request. // Send the get request.
return $this->response->get( return $this->response->get(
$this->http->get($uri) $this->http->get($uri)
); );
} }
/** /**
* Get a user by their username. * Get a user by their username.
* *
* @param string $username The username of the user to retrieve. * @param string $username The username of the user to retrieve.
* *
* @return object|null * @return object|null
* @since 3.2.0 * @since 3.2.0
**/ **/
public function get(string $username): o?bject public function get(string $username): ?object
{ {
// Build the request path. // Build the request path.
$path = "/users/{$username}"; $path = "/users/{$username}";
// Send the get request. // Send the get request.
return $this->response->get( return $this->response->get(
$this->http->get( $this->http->get(
$this->uri->get($path) $this->uri->get($path)
) )
); );
} }
/** /**
* List the given user's followers. * List the given user's followers.
* *
* @param string $userName The username of the user to retrieve followers for. * @param string $userName The username of the user to retrieve followers for.
* @param int $page Page number of results to return (1-based). * @param int $page Page number of results to return (1-based).
* @param int $limit Page size of results. * @param int $limit Page size of results.
* *
* @return array|null * @return array|null
* @since 3.2.0 * @since 3.2.0
**/ **/
public function followers( public function followers(
string $userName, string $userName,
int $page = 1, int $page = 1,
int $limit = 10 int $limit = 10
): ?array ): ?array
{ {
// Build the request path. // Build the request path.
$path = "/users/{$userName}/followers"; $path = "/users/{$userName}/followers";
// Build the URI with query parameters. // Build the URI with query parameters.
$uri = $this->uri->get($path); $uri = $this->uri->get($path);
$uri->setVar('page', $page); $uri->setVar('page', $page);
$uri->setVar('limit', $limit); $uri->setVar('limit', $limit);
// Send the get request. // Send the get request.
return $this->response->get( return $this->response->get(
$this->http->get($uri) $this->http->get($uri)
); );
} }
/** /**
* List the users that the given user is following. * List the users that the given user is following.
* *
* @param string $userName The username of the user to retrieve the following users for. * @param string $userName The username of the user to retrieve the following users for.
* @param int $page Page number of results to return (1-based). * @param int $page Page number of results to return (1-based).
* @param int $limit Page size of results. * @param int $limit Page size of results.
* *
* @return array|null * @return array|null
* @since 3.2.0 * @since 3.2.0
**/ **/
public function following( public function following(
string $userName, string $userName,
int $page = 1, int $page = 1,
int $limit = 10 int $limit = 10
): ?array ): ?array
{ {
// Build the request path. // Build the request path.
$path = "/users/{$userName}/following"; $path = "/users/{$userName}/following";
// Build the URI with query parameters. // Build the URI with query parameters.
$uri = $this->uri->get($path); $uri = $this->uri->get($path);
$uri->setVar('page', $page); $uri->setVar('page', $page);
$uri->setVar('limit', $limit); $uri->setVar('limit', $limit);
// Send the get request. // Send the get request.
return $this->response->get( return $this->response->get(
$this->http->get($uri) $this->http->get($uri)
); );
} }
/** /**
* Check if one user is following another user. * Check if one user is following another user.
* *
* @param string $username The username of the user to check. * @param string $username The username of the user to check.
* @param string $target The username of the target user. * @param string $target The username of the target user.
* *
* @return string * @return string
* @since 3.2.0 * @since 3.2.0
**/ **/
public function check(string $username, string $target): string public function check(string $username, string $target): string
{ {
// Build the request path. // Build the request path.
$path = "/users/{$username}/following/{$target}"; $path = "/users/{$username}/following/{$target}";
// Send the get request. // Send the get request.
return $this->response->get( return $this->response->get(
$this->http->get( $this->http->get(
$this->uri->get($path) $this->uri->get($path)
), 204, 'success' ), 204, 'success'
); );
} }
/** /**
* List the given user's GPG keys. * List the given user's GPG keys.
* *
* @param string $userName The username of the user to retrieve GPG keys for. * @param string $userName The username of the user to retrieve GPG keys for.
* @param int $page The page number of results to return (1-based). * @param int $page The page number of results to return (1-based).
* @param int $limit The page size of results. * @param int $limit The page size of results.
* *
* @return array|null * @return array|null
* @since 3.2.0 * @since 3.2.0
**/ **/
public function gpg( public function gpg(
string $userName, string $userName,
int $page = 1, int $page = 1,
int $limit = 10 int $limit = 10
): ?array ): ?array
{ {
// Build the request path. // Build the request path.
$path = "/users/{$userName}/gpg_keys"; $path = "/users/{$userName}/gpg_keys";
// Build the URI with query parameters. // Build the URI with query parameters.
$uri = $this->uri->get($path); $uri = $this->uri->get($path);
$uri->setVar('page', $page); $uri->setVar('page', $page);
$uri->setVar('limit', $limit); $uri->setVar('limit', $limit);
// Send the get request. // Send the get request.
return $this->response->get( return $this->response->get(
$this->http->get($uri) $this->http->get($uri)
); );
} }
/** /**
* Get a user's heatmap. * Get a user's heatmap.
* *
* @param string $username The username of the user to retrieve heatmap for. * @param string $username The username of the user to retrieve heatmap for.
* *
* @return array|null * @return array|null
* @since 3.2.0 * @since 3.2.0
**/ **/
public function heatmap(string $username): ?array public function heatmap(string $username): ?array
{ {
// Build the request path. // Build the request path.
$path = "/users/{$username}/heatmap"; $path = "/users/{$username}/heatmap";
// Send the get request. // Send the get request.
return $this->response->get( return $this->response->get(
$this->http->get( $this->http->get(
$this->uri->get($path) $this->uri->get($path)
) )
); );
} }
/** /**
* List the given user's public keys. * List the given user's public keys.
* *
* @param string $userName The username of the user to retrieve public keys for. * @param string $userName The username of the user to retrieve public keys for.
* @param string|null $fingerprint Optional. The fingerprint of the key. * @param string|null $fingerprint Optional. The fingerprint of the key.
* @param int $page The page number of results to return (1-based). * @param int $page The page number of results to return (1-based).
* @param int $limit The page size of results. * @param int $limit The page size of results.
* *
* @return array|null * @return array|null
* @since 3.2.0 * @since 3.2.0
**/ **/
public function keys( public function keys(
string $userName, string $userName,
?string $fingerprint = null, ?string $fingerprint = null,
int $page = 1, int $page = 1,
int $limit = 10 int $limit = 10
): ?array ): ?array
{ {
// Build the request path. // Build the request path.
$path = "/users/{$userName}/keys"; $path = "/users/{$userName}/keys";
// Build the URI with query parameters. // Build the URI with query parameters.
$uri = $this->uri->get($path); $uri = $this->uri->get($path);
$uri->setVar('page', $page); $uri->setVar('page', $page);
$uri->setVar('limit', $limit); $uri->setVar('limit', $limit);
if ($fingerprint !== null) if ($fingerprint !== null)
{ {
$uri->setVar('fingerprint', $fingerprint); $uri->setVar('fingerprint', $fingerprint);
} }
// Send the get request. // Send the get request.
return $this->response->get( return $this->response->get(
$this->http->get($uri) $this->http->get($uri)
); );
} }
/** /**
* List the repos that the given user has starred. * List the repos that the given user has starred.
* *
* @param string $userName The username of the user to retrieve starred repos for. * @param string $userName The username of the user to retrieve starred repos for.
* @param int $page The page number of results to return (1-based). * @param int $page The page number of results to return (1-based).
* @param int $limit The page size of results. * @param int $limit The page size of results.
* *
* @return array|null * @return array|null
* @since 3.2.0 * @since 3.2.0
**/ **/
public function repos( public function repos(
string $userName, string $userName,
int $page = 1, int $page = 1,
int $limit = 10 int $limit = 10
): ?array ): ?array
{ {
// Build the request path. // Build the request path.
$path = "/users/{$userName}/starred"; $path = "/users/{$userName}/starred";
// Build the URI with query parameters. // Build the URI with query parameters.
$uri = $this->uri->get($path); $uri = $this->uri->get($path);
$uri->setVar('page', $page); $uri->setVar('page', $page);
$uri->setVar('limit', $limit); $uri->setVar('limit', $limit);
// Send the get request. // Send the get request.
return $this->response->get( return $this->response->get(
$this->http->get($uri) $this->http->get($uri)
); );
} }
/** /**
* List the repositories watched by a user. * List the repositories watched by a user.
* *
* @param string $userName The username of the user to retrieve watched repositories for. * @param string $userName The username of the user to retrieve watched repositories for.
* @param int $page The page number of results to return (1-based). * @param int $page The page number of results to return (1-based).
* @param int $limit The page size of results. * @param int $limit The page size of results.
* *
* @return array|null * @return array|null
* @since 3.2.0 * @since 3.2.0
**/ **/
public function watched( public function watched(
string $userName, string $userName,
int $page = 1, int $page = 1,
int $limit = 10 int $limit = 10
): ?array ): ?array
{ {
// Build the request path. // Build the request path.
$path = "/users/{$userName}/subscriptions"; $path = "/users/{$userName}/subscriptions";
// Build the URI with query parameters. // Build the URI with query parameters.
$uri = $this->uri->get($path); $uri = $this->uri->get($path);
$uri->setVar('page', $page); $uri->setVar('page', $page);
$uri->setVar('limit', $limit); $uri->setVar('limit', $limit);
// Send the get request. // Send the get request.
return $this->response->get( return $this->response->get(
$this->http->get($uri) $this->http->get($uri)
); );
} }
} }