示例#1
0
    def destroy_room(self, jabber_id: str) -> bool:
        """destroy a MUC room."""
        logger.debug(f'destroy a MUC room by {jabber_id}')

        api_url = f'{self.root_path}/api/destroy_room'
        jid = JID(jabber_id)
        body = {'name': jid.user, 'service': jid.host}
        try:
            post(api_url, json=body)
            return True
        except RemoteAPIError:
            return False
示例#2
0
    def unregister(self, jabber_id: str) -> bool:
        """unregister a user."""
        logger.debug(f'unregister account {jabber_id}')

        api_url = f'{self.root_path}/api/unregister'
        jid = JID(jabber_id)
        body = {'user': jid.user, 'host': jid.host}
        try:
            post(api_url, json=body)
            return True
        except RemoteAPIError:
            return False
示例#3
0
 def _load_auth_header(self) -> Dict[str, str]:
     api_url = f'{self.root_path}/security/login'
     body = {
         'username': self.username,
         'password': self.password,
         'provider': self.provider
     }
     r = post(api_url, json=body)
     token = r['access_token']
     return {'Authorization': f'Bearer {token}'}
示例#4
0
    def check_account(self, jabber_id: str) -> bool:
        """check if an account exists or not."""
        logger.debug(f'check if account {jabber_id} exists or not')

        api_url = f'{self.root_path}/api/check_account'
        jid = JID(jabber_id)
        body = {'user': jid.user, 'host': jid.host}
        try:
            return post(api_url, json=body) == 0
        except RemoteAPIError:
            return False
示例#5
0
    def check_room(self, jabber_id: str) -> bool:
        """check if a room exists or not."""
        logger.debug(f'check if room {jabber_id} exists or not')

        api_url = f'{self.root_path}/api/get_room_options'
        jid = JID(jabber_id)
        body = {'name': jid.user, 'service': jid.host}
        try:
            props = post(api_url, json=body)
            return len(props) > 0
        except RemoteAPIError:
            return False
示例#6
0
    def create_room(self,
                    jabber_id: str,
                    host: str = 'localhost',
                    **kwargs) -> bool:
        """create a MUC room in host with given options."""
        logger.debug(f'create a MUC room using {jabber_id}')

        api_url = f'{self.root_path}/api/create_room_with_opts'
        jid = JID(jabber_id)
        options = [{'name': k, 'value': v} for k, v in kwargs.items()]
        body = {
            'name': jid.user,
            'service': jid.host,
            'host': host,
            'options': options
        }
        try:
            post(api_url, json=body)
            return True
        except RemoteAPIError:
            return False