Example #1
0
export function evalExpression(gist: string, scriptId: string, expr: string) {
    if (!expr)
        return;

    const request = new EvaluateExpression();
    request.scriptId = scriptId;
    request.expression = expr;
    request.includeJson = true;

    ReactGA.event({ category: 'preview', action: 'Evaluate Expression', label: gist + ": " + expr.substring(0, 50) });

    client.post(request)
        .then(r => {
            if (r.result.errors && r.result.errors.length > 0) {
                r.result.errors.forEach(x => {
                    store.dispatch({ type: 'CONSOLE_LOG', logs: [{ msg: x.info, cls: "error" }] });
                });
            } else {
                store.dispatch({ type: 'EXPRESSION_LOAD', expressionResult: r.result });
            }
        })
        .catch(e => {
            var status = e.responseStatus || e; //both have schema `{ message }`
            store.dispatch({ type: 'CONSOLE_LOG', logs: [statusToError(status)] });
        });
};
Example #2
0
function testClient() {
    client.get(Object.assign(new Hello(), { name: "GET" })).then(show);
    client.post(Object.assign(new Hello(), { name: "POST" })).then(show);
    client.put(Object.assign(new Hello(), { name: "PUT" })).then(show);
};
Example #3
0
        });
    },
    helloTypes () {
        var request = new HelloTypes();
        request.string = this.value;
        request.bool = false;
        request.int = 0;
        client.get(request).then((r) => {
            $("#helloTypesResult").html(JSON.stringify(r));
        });
    },
    echoTypes() {
        var request = new EchoTypes();
        request.string = this.value;

        client.post(request).then(r => {
            $("#echoTypesResult").html(r.string);
        });
    },
    rawString() {
        var request = new ReturnString();
        request.data = this.value;

        client.get(request)
            .then(text => {
                $("#rawStringResult").html(text);
            });
    },
    rawBytes() {
        const bytesToBase64 = (array) => btoa(String.fromCharCode.apply(null, new Uint8Array(array)));
        const base64ToBytes = (b64) => new Uint8Array(atob(b64).split("").map(c => c.charCodeAt(0)));