gitea/src/af4b8b77-d773-42a7-9f54-19de463bc49b/code.power

68 lines
1.4 KiB
Plaintext
Raw Normal View History

2023-04-15 15:08:07 +00:00
/**
* List the authenticated user's email addresses.
*
* @return array|null
* @since 3.2.0
**/
public function list(): ?array
{
// Build the request path.
$path = '/user/emails';
// Send the get request.
return $this->response->get(
$this->http->get(
$this->uri->get($path)
)
);
}
/**
* Add email addresses for the authenticated user.
*
* @param array $emails An array of email addresses to add.
*
* @return array|null
* @since 3.2.0
**/
public function add(array $emails): ?array
{
// Build the request path.
$path = '/user/emails';
// Create the request body.
$body = new \stdClass();
$body->emails = $emails;
// Send the post request.
return $this->response->get(
$this->http->post(
$this->uri->get($path),
json_encode($body)
), 201
);
}
/**
* Delete email addresses for the authenticated user.
*
* @param array $$emails An array of email addresses to delete.
*
* @return string
* @since 3.2.0
**/
public function delete(array $emails): string
{
// Build the request path.
$path = '/user/emails';
// Build the URI.
$uri = $this->uri->get($path);
$uri->setVar('emails', json_encode($emails));
// Send the delete request.
return $this->response->get(
$this->http->delete($uri), 204, 'success'
);
}