hnhdigital-os/php-linode-api

View on GitHub
src/endpoints/Account/User.php

Summary

Maintainability
A
0 mins
Test Coverage
<?php

namespace HnhDigital\LinodeApi\Account;

/*
 * This file is part of the PHP Linode API.
 *
 * (c) H&H|Digital <hello@hnh.digital>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

use HnhDigital\LinodeApi\Foundation\Base;

/**
 * This is the User class.
 *
 * This file is automatically generated.
 *
 * @link https://developers.linode.com/api/v4#tag/Account-Users
 *
 * @author Rocco Howard <rocco@hnh.digital>
 */
class User extends Base
{
    /**
     * Endpoint.
     *
     * @var string
     */
    protected $endpoint = 'account/users/%s';

    /**
     * Username.
     *
     * @var string
     */
    protected $username;

    /**
     * This model is fillable.
     *
     * @var bool
     */
    protected $fillable = true;

    /**
     * This model's method that provides the data to fill it.
     *
     * @var string
     */
    protected $fill_method = 'get';

    /**
     * Constructor.
     *
     * @return void
     */
    public function __construct($username, $fill = [])
    {
        $this->username = $username;
        parent::__construct($username, $fill);
    }

    /**
     * Returns information about a single User on your Account.
     *
     * @link https://developers.linode.com/api/v4#operation/getUser
     *
     * @return array
     */
    public function get()
    {
        return $this->apiCall('get', '', [], ['auto-fill' => true]);
    }

    /**
     * Returns the full grants structure for this User. This includes all entities on the Account alongside what level of
     * access this User has to each of them. Individual users may view their own grants at the
     * [/profile/grants](/#operation/getProfileGrants) endpoint, but will not see entities that they have no access to.
     *
     * @link https://developers.linode.com/api/v4#operation/getUserGrants
     *
     * @return array
     */
    public function getUserGrants()
    {
        return $this->apiCall('get', '/grants', [], ['auto-fill' => true]);
    }

    /**
     * Update the grants a User has. This can be used to give a User access to new entities or actions, or take access away.
     * You do not need to include the grant for every entity on the Account in this request; any that are not included will
     * remain unchanged.
     *
     * @param string $username The username to look up.
     *
     * @link https://developers.linode.com/api/v4#operation/updateUserGrants
     *
     * @return void
     */
    public function update($optional = [])
    {
        return $this->apiCall('put', '/grants', ['json' => $this->getDirty($optional)]);
    }

    /**
     * Deletes a User. The deleted User will be immediately logged out and may no longer log in or perform any actions. All of
     * the User's Grants will be removed.
     *
     * @param string $username The username to look up.
     *
     * @link https://developers.linode.com/api/v4#operation/deleteUser
     *
     * @return void
     */
    public function delete()
    {
        return $this->apiCall('delete', '');
    }
}