1.6.1 • Published 8 months ago

@wjunt/dwp v1.6.1

Weekly downloads
-
License
MIT
Repository
-
Last release
8 months ago

@wjunt/dwp

DWP (Duola Wireless Platform) JavaScript SDK

Usage

Send a DWP request

F.dwp.request('dwp.cheetah.get', '1', { pid: 142 })
    .then((data) => {
        console.log(data); // {info: {…}, isEnd: true, list: Array(6)}
    })
    .catch((err) => {
        console.error(err.message, err.code); // "xxxxx" dddd
    });

Send a POST request

F.dwp.post('dwp.cheetah.get', '1', { pid: 142 })
    .then((data) => {
        console.log(data); // {info: {…}, isEnd: true, list: Array(6)}
    })
    .catch((err) => {
        console.error(err.message, err.code); // "xxxxx" dddd
    });

Send a DSL request

Since 1.3.0

F.dwp.getDsl()
    .add('dwp.item_api.getItemDetail', '1', { 'itemId': 7086970 })
    .request('dsl.common.gacha_itemDetail', '1')
    .on('dwp.item_api.getItemDetail@1', (err, data) => {
        if (err || !data) {
            console.error(err || new Error('No data'));
        } else {
            console.log(data);
        }
    })
    .on('dwp.item_api.getShopDetail@1', (err, data) => {
        if (err || !data) {
            console.error(err || new Error('No data'));
        } else {
            console.log(data);
        }
    })
    .on('dwp.item_api.listComments@1', (err, data) => {
        if (err || !data) {
            console.error(err || new Error('No data'));
        } else {
            console.log(data);
        }
    })
    .catch((error) => {
        console.error(error);
    });

API

/**
 * Send a DWP request. Method is `GET` by default.
 * @param api - API name.
 * @param version - API version.
 * @param [data] - API data.
 * @param [options] - Request options.
 * @param [options.method] - Request method: `undefined`, `'post'`. `undefined` by default.
 * @param [options.timeout] - Request timeout. `10000` (ms) by default.
 */
F.dwp.request(api: string, version: string, data?: any, options?: DwpRequestOptions): Promise<any>;

/**
 * Send a POST DWP request.
 * @param api - API name.
 * @param version - API version.
 * @param data - API data.
 * @param [options] - Request options.
 * @param [options.timeout] - Request timeout. `10000` (ms) by default.
 */
F.dwp.post(api: string, version: string, data: any, options?: Omit<DwpRequestOptions, 'method'>): Promise<any>;

Development

$ cd dwp
$ yarn
$ yarn build
1.6.1

8 months ago