<commit_before><commit_msg>Adding grant endpoint methods and basic docs<commit_after><?php
namespace Auth0\SDK\API\Management;

use Auth0\SDK\Exception\CoreException;

class Grants extends GenericResource
{
    /**
     * @param array $params
     * @param null $page
     * @param null $per_page
     * @return mixed|string
     * @throws \Exception
     */
    public function getAll(array $params = [], $page = null, $per_page = null)
    {
        if (null !== $page) {
            $params['page'] = abs(intval($page));
        }

        if (null !== $per_page) {
            $params['per_page'] = abs(intval($per_page));
        }

        return $this->apiClient->method('get')
            ->addPath('grants')
            ->withDictParams($params)
            ->call();
    }

    /**
     * @param $client_id
     * @param null $page
     * @param null $per_page
     * @return mixed|string
     * @throws CoreException
     * @throws \Exception
     */
    public function getByClientId($client_id, $page = null, $per_page = null)
    {
        if (empty($client_id) || ! is_string($client_id)) {
            throw new CoreException('Empty or invalid "client_id" parameter.');
        }

        return $this->getAll($page, $per_page, ['client_id' => $client_id]);
    }

    /**
     * @param $audience
     * @param null $page
     * @param null $per_page
     * @return mixed|string
     * @throws CoreException
     * @throws \Exception
     */
    public function getByAudience($audience, $page = null, $per_page = null)
    {
        if (empty($audience) || ! is_string($audience)) {
            throw new CoreException('Empty or invalid "audience" parameter.');
        }

        return $this->getAll($page, $per_page, ['audience' => $audience]);
    }

    /**
     * @param $user_id
     * @param null $page
     * @param null $per_page
     * @return mixed|string
     * @throws CoreException
     * @throws \Exception
     */
    public function getByUserId($user_id, $page = null, $per_page = null)
    {
        if (empty($user_id) || ! is_string($user_id)) {
            throw new CoreException('Empty or invalid "user_id" parameter.');
        }

        return $this->getAll($page, $per_page, ['user_id' => $user_id]);
    }

    /**
     * @param $id
     * @return mixed|string
     * @throws \Exception
     */
    public function delete($id)
    {
        return $this->apiClient->method('delete')
            ->addPath('grants', $id)
            ->call();
    }

    /**
     * @param $user_id
     * @return mixed|string
     * @throws \Exception
     */
    public function deleteUserGrants($user_id)
    {
        return $this->delete($user_id);
    }
}
{'fraction_non_alphanumeric': 0.14774841831038332, 'fraction_numerical': 0.000744324525493115, 'mean_word_length': 2.188612099644128, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1337060', 'n_tokens_mistral': 835, 'n_tokens_neox': 825, 'n_words': 184}