|  | 
|  | 1 | +from __future__ import annotations | 
|  | 2 | +from typing import TYPE_CHECKING | 
|  | 3 | + | 
|  | 4 | +if TYPE_CHECKING: | 
|  | 5 | +    from vonage import Client | 
|  | 6 | + | 
|  | 7 | +from .errors import UsersError | 
|  | 8 | +from ._internal import set_auth_type | 
|  | 9 | + | 
|  | 10 | + | 
|  | 11 | +class Users: | 
|  | 12 | +    """Class containing methods for user management as part of the Application API.""" | 
|  | 13 | + | 
|  | 14 | +    def __init__(self, client: Client): | 
|  | 15 | +        self._client = client | 
|  | 16 | +        self._auth_type = set_auth_type(self._client) | 
|  | 17 | + | 
|  | 18 | +    def list_users( | 
|  | 19 | +        self, | 
|  | 20 | +        page_size: int = None, | 
|  | 21 | +        order: str = 'asc', | 
|  | 22 | +        cursor: str = None, | 
|  | 23 | +        name: str = None, | 
|  | 24 | +    ): | 
|  | 25 | +        """ | 
|  | 26 | +        Lists the name and user id of all users associated with the account. | 
|  | 27 | +        For complete information on a user, call Users.get_user, passing in the user id. | 
|  | 28 | +        """ | 
|  | 29 | + | 
|  | 30 | +        if order.lower() not in ('asc', 'desc'): | 
|  | 31 | +            raise UsersError( | 
|  | 32 | +                'Invalid order parameter. Must be one of: "asc", "desc", "ASC", "DESC".' | 
|  | 33 | +            ) | 
|  | 34 | + | 
|  | 35 | +        params = {'page_size': page_size, 'order': order.lower(), 'cursor': cursor, 'name': name} | 
|  | 36 | +        return self._client.get( | 
|  | 37 | +            self._client.api_host(), | 
|  | 38 | +            '/v1/users', | 
|  | 39 | +            params, | 
|  | 40 | +            auth_type=self._auth_type, | 
|  | 41 | +        ) | 
|  | 42 | + | 
|  | 43 | +    def create_user(self, params: dict = None): | 
|  | 44 | +        self._client.headers['Content-Type'] = 'application/json' | 
|  | 45 | +        return self._client.post( | 
|  | 46 | +            self._client.api_host(), | 
|  | 47 | +            '/v1/users', | 
|  | 48 | +            params, | 
|  | 49 | +            auth_type=self._auth_type, | 
|  | 50 | +        ) | 
|  | 51 | + | 
|  | 52 | +    def get_user(self, user_id: str): | 
|  | 53 | +        return self._client.get( | 
|  | 54 | +            self._client.api_host(), | 
|  | 55 | +            f'/v1/users/{user_id}', | 
|  | 56 | +            auth_type=self._auth_type, | 
|  | 57 | +        ) | 
|  | 58 | + | 
|  | 59 | +    def update_user(self, user_id: str, params: dict): | 
|  | 60 | +        return self._client.patch( | 
|  | 61 | +            self._client.api_host(), | 
|  | 62 | +            f'/v1/users/{user_id}', | 
|  | 63 | +            params, | 
|  | 64 | +            auth_type=self._auth_type, | 
|  | 65 | +        ) | 
|  | 66 | + | 
|  | 67 | +    def delete_user(self, user_id: str): | 
|  | 68 | +        return self._client.delete( | 
|  | 69 | +            self._client.api_host(), | 
|  | 70 | +            f'/v1/users/{user_id}', | 
|  | 71 | +            auth_type=self._auth_type, | 
|  | 72 | +        ) | 
0 commit comments