Пример #1
0
def watch(ctx: Configuration, event_type):
    """Subscribe and print events.

    EVENT-TYPE even type to subscribe to. if empty subscribe to all.
    """
    frame = {'type': 'subscribe_events'}

    if event_type:
        frame['event_type'] = event_type

    api.wsapi(ctx, frame, True)
Пример #2
0
def watch(ctx: Configuration, event_type):
    """Subscribe and print events.

    EVENT-TYPE even type to subscribe to. if empty subscribe to all.
    """
    frame = {'type': 'subscribe_events'}

    cols = [('EVENT_TYPE', 'event_type'), ('DATA', '$.data')]

    def _msghandler(msg: Dict) -> None:
        if msg['type'] == 'event':
            ctx.echo(
                format_output(
                    ctx,
                    msg['event'],
                    columns=ctx.columns if ctx.columns else cols,
                ))

    if event_type:
        frame['event_type'] = event_type

    api.wsapi(ctx, frame, _msghandler)
Пример #3
0
def watch(ctx: Configuration, event_type):
    """Subscribe and print events.

    EVENT-TYPE even type to subscribe to. if empty subscribe to all.
    """
    frame = {'type': 'subscribe_events'}

    cols = [('EVENT_TYPE', 'event_type'), ('DATA', '$.data')]

    def _msghandler(msg: Dict) -> None:
        if msg['type'] == 'event':
            ctx.echo(
                format_output(
                    ctx,
                    msg['event'],
                    columns=ctx.columns if ctx.columns else cols,
                )
            )

    if event_type:
        frame['event_type'] = event_type

    api.wsapi(ctx, frame, _msghandler)
Пример #4
0
def websocket(ctx: Configuration, wstype, json):  # noqa: D301
    """Send a websocket request against /api/websocket.

    WSTYPE is name of websocket methods.

    \b
    --json is dictionary to pass in addition to the type.
           Example: --json='{ "area_id":"2c8bf93c8082492f99c989896962f207" }'
    """
    if json:
        data = json_.loads(json)
    else:
        data = {}

    frame = {'type': wstype}
    frame = {**frame, **data}  # merging data into frame

    response = cast(List[Dict[str, Any]], api.wsapi(ctx, frame))

    ctx.echo(format_output(ctx, response))