Exemplo n.º 1
0
async def create_and_update_node():
    async with RfApiClient(auth=UserAuth(USERNAME, PASSWORD), ) as api_client:
        sleep_time = 5.0

        m = await api_client.maps.get_map_by_id(MAP_ID)

        props = CreateNodePropertiesDto.empty()
        props.global_.title = f'New node title  \nWait {sleep_time} seconds to update'
        node = await api_client.nodes.create(
            CreateNodeDto(map_id=m.id,
                          parent=m.root_node_id,
                          position=(PositionType.P, '-1'),
                          properties=props))

        print('New node properties:', node.body.properties.dict(by_alias=True))

        await sleep(sleep_time)

        updated_node = await api_client.nodes.update_by_id(
            node.id,
            NodeUpdateDto(properties=PropertiesUpdateDto(
                update=[GlobalPropertyUpdateDto(value='Title updated')],
                add=[
                    UserPropertyCreateDto(
                        key='user property',
                        type_id=NodePropertyType.TEXT,
                        value='Value of user property',
                        visible=True,
                    )
                ])))

        print('Updated node properties:',
              updated_node.body.properties.dict(by_alias=True))
Exemplo n.º 2
0
async def load_map():
    async with RfApiClient(auth=UserAuth(USERNAME, PASSWORD), ) as api_client:
        m = await api_client.maps.get_map_by_id(MAP_ID)
        print('Map name:', m.name)
        print('Nodes total:', m.node_count)

        root = await api_client.maps.get_map_nodes(MAP_ID)
        print('Root node title:', root.body.properties.global_.title)
async def main():
    # set logging level
    logging.basicConfig(level=logging.DEBUG)
    main_logger.setLevel(logging.DEBUG)

    async with RfApiClient(
        auth=UserAuth(USERNAME, PASSWORD),
        log_response_body=True  # log response bodies
    ) as api_client:
        user = await api_client.users.get_current()
        print('Current user is', user)
Exemplo n.º 4
0
    async def post(self):
        """
        This is an example command handler, that returns request arguments and the title of the node,
        at which it was called.
        """

        # A session in general used to distinguish web app instances of a single user.
        # In this case it allows to send notifications back to the specific web app that called this extension
        session = self.request.headers.get('Rf-Session-Id')

        # Temporary user token, that allows the extension to access the RedForester API.
        # It will works, while this request is running and will be revoked after request termination.
        user_token = self.request.headers['Rf-Extension-Token']

        # Id of the user, that started this command.
        user_id = self.get_query_argument('userId')

        # Id of the map, that contains the node, on which this command was called.
        map_id = self.get_query_argument('mapId')

        # Id of the node, on which this command was called.
        node_id = self.get_query_argument('nodeId')

        logging.info(
            f'user_token : {user_token}, user_id: {user_id}, map_id: {map_id}, node_id: {node_id}'
        )

        api = RfApiClient(auth=ExtensionAuth(user_token),
                          session_id=session,
                          base_url=URL(RF_BACKEND_BASE_URL))

        async with RfClient(api) as rf:
            map_ = await rf.maps.load_map(map_id=map_id)
            node = map_.tree.find_by_id(node_id)
            node_title = node.body.properties.global_.title

        # Build response
        self.finish({
            'notify': {
                'userId': user_id,
                'session': session,
                'content':
                f'Hello, RedForester! user = {user_id}, map = {map_id}, node = {node_title} (id: {node_id})',
                'style': 'SUCCESS'
            }
        })
Exemplo n.º 5
0
async def get_favorite_nodes():
    async with RfApiClient(
            auth=UserAuth(USERNAME, PASSWORD),
    ) as api_client:
        m = await api_client.maps.get_map_by_id(MAP_ID)
        print(m)

        me = await api_client.users.get_current()
        print(me)

        favorite_tag = me.tags[0]
        favorite_nodes = await api_client.tags.get_nodes(favorite_tag.id)
        print(favorite_nodes)

        tagged = await api_client.tags.add_tag(favorite_tag.id, m.root_node_id)
        print("tagged: ", tagged)

        await api_client.tags.remove_tag(favorite_tag.id, m.root_node_id)
        print("and removed")
Exemplo n.º 6
0
async def get_current_user():
    async with RfApiClient(
            auth=UserAuth(USERNAME, PASSWORD),
    ) as api_client:
        me = await api_client.users.get_current()
        print(me)
Exemplo n.º 7
0
import os

from rf_api_client import RfApiClient
from rf_api_client.rf_api_client import UserAuth

from rf_client import RfClient

USERNAME = os.getenv('USERNAME')
PASSWORD = os.getenv('PASSWORD')

MAP_ID = os.getenv('MAP_ID')

logging.basicConfig(level=logging.INFO)

api_client = RfApiClient(
    auth=UserAuth(USERNAME, PASSWORD),
)


async def load_map():
    async with RfClient(api_client) as client:
        m = await client.maps.load_map(MAP_ID)
        print('Map name:', m.map_info.name)
        print('Map users:', m.users)
        print('Map types:', m.types)
        print('Root node title:', m.tree.root.body.properties.global_.title)
        print('Nodes count:', len(list(m.tree.root.get_all_descendants())))


if __name__ == '__main__':
    loop = asyncio.get_event_loop()
Exemplo n.º 8
0
async def api(secret: Secret):
    async with RfApiClient(auth=UserAuth(secret.username, secret.password),
                           base_url=URL(secret.base_url)) as api:
        yield api
Exemplo n.º 9
0
async def create_map():
    async with RfApiClient(auth=UserAuth(USERNAME, PASSWORD), ) as api_client:
        m = await api_client.maps.create_map(
            NewMapDto(name='Example Map', layout=MapLayout.LR))
        print('New map name:', m.name)
Exemplo n.º 10
0
async def auth():
    async with RfApiClient(
        auth=UserAuth(USERNAME, PASSWORD),
    ) as api_client:
        user = await api_client.users.get_current()
        print('Current user is', user)