Skip to content

json native calls generatetablescript

Kevin Mathmann edited this page Mar 18, 2019 · 8 revisions

JSONCalls GenerateTableScript

This Script generates the table for the JSON NativeCalls list wiki page.
To update the table just update the config at the bottom of this script.

const getWrapper = (body) => (
    `<table dir="auto">
    <thead>
        <tr>
            <th style="text-align: center;">name</th>
            <th style="text-align: center;">action</th>
            <th>example</th>
            <th>note</th>
        </tr>
    </thead>
    <tbody>
        ${body}
    </tbody>
</table>

### How to update the table?
To update the table, use the [generateTableScript](./json-native-calls-generatetablescript).
Update the [generateTableScript wiki entrie](./json-native-calls-generatetablescript) and executes the script after that in the chrome console. Then replace the content of this entrie with your clipboard.`
);

const getRow = ({name, action, data = {}, note = {}}) => (
    `<tr>
    <td style="text-align: center">${name}</td>
    <td style="text-align: center">${action}</td>
    <td style="width:auto">
        <pre lang="json">${JSON.stringify({
        "action": action,
        "value": {
            "callback": "path.callbackName",
            "id": "b3546680-1ac2-11e7-b54f-e7385e90e951",
            "parameter": {},
            "data": data
        }
    }, null, 4)}</pre>
    </td>
    <td>${note.text || ''}
        ${note.json ? `<pre lang="json">${JSON.stringify(note.json, null, 4)}</pre>` : ''} </td>
</tr>`
);

const outputTable = (config) => {
    const rows = config.map(itemConfig => getRow(itemConfig));

    const text = getWrapper(rows.join(''));

    console.log(text);
    copyToClipboard(text);
};

function copyToClipboard(text) {
    var input = document.createElement('textarea');
    document.body.appendChild(input);
    input.value = text;
    input.focus();
    input.select();
    document.execCommand('Copy');
    input.remove();
}

const config = [
    {
        name: 'getAccessToken',
        action: 1,
        data: {},
        note: {
            text: 'Needs to be a userToken.<br/> result object -> data',
            json: {
                tobitAccessToken: 'testToken'
            }
        }
    },
    {
        name: 'setAccessToken',
        action: 2,
        data: {
            tobitAccessToken: 'testToken'
        },
        note: {
            text: 'The Token is a renew Token.<br/> default result object.'
        }
    },
    {
        name: 'getKeyValue',
        action: 3,
        data: {
            key: 'myKey'
        },
        note: {
            text: 'result object -> data.',
            json: {
                value: 'myValue'
            }
        }
    },
    {
        name: 'setKeyValue',
        action: 4,
        data: {
            key: 'myKey',
            value: 'myValue'
        },
        note: {
            text: 'default result object.',
        }
    },
    {
        name: 'refreshChaynsIdIcons',
        action: 5,
        data: {},
        note: {
            text: 'default result object.',
        }
    },
    {
        name: 'closeWindow',
        action: 6,
        data: {},
        note: {
            text: 'default result object.',
        }
    },
    {
        name: 'resizeWindow',
        action: 7,
        data: {
            x: 566,
            y: 1200
        },
        note: {
            text: 'default result object.',
        }
    },
    {
        name:'getSavedIntercomChats',
        action: 8,
        data:{
            itemId: 'eyJhIjoiXFxcXHctdGpcXGRhdmlkXFxhcmNoaXZlXFx1c2VyXFwxMDAwNDAwMFxcaW4iLCJyIjo2NSwicyI6MzR9Cg=='
        },
        note: {
            text: 'default result object.',
        }
    },
    {
        name:'setIntercomChatData',
        action: 9,
        data: { 
            somedata: 'asjhdajhsd',
            moredata: 'ddddddddddd' 
        },
        note: {
            text: '<div style="margin-bottom: 5px;">default result object.</div> Everything in data you will get back with call 8 under data.Message.MessageData.intercom.data.more data.',
        }
    },
    {
        name:'download',
        action: 10,
        data: { 
            url: 'https://....',
            name: 'xyc.pdf'
        },
        note: {
            text: 'default result object.',
        }
    }
];

outputTable(config);