dist/lib/api.js
function get(endpoint, data, auth = true, ignore) {
    return __awaiter(this, void 0, void 0, function* () {
        try {
            log_1.logger.debug(`[API] GET: ${endpoint}`, data);
            if (auth && !loggedIn())
                yield login();
            let headers = getHeaders(auth);
            const query = getQueryString(data);
            const result = yield new Promise((resolve, reject) => {
                exports.client.get(exports.url + endpoint + query, { headers }, (result) => {
                    if (Buffer.isBuffer(result))
                        reject('Result was buffer (HTML, not JSON)');
                    else if (!success(result, ignore))
                        reject(result);
                    else
                        resolve(result);
                }).on('error', (err) => reject(err));
            });
            log_1.logger.debug('[API] GET result:', result);
            return result;
        }
        catch (err) {
            log_1.logger.error(`[API] GET error (${endpoint}):`, err);
        }
    });
}
function get(endpoint, data, auth = true, ignore) {
    return __awaiter(this, void 0, void 0, function* () {
        try {
            log_1.logger.debug(`[API] GET: ${endpoint}`, data);
            if (auth && !loggedIn())
                yield login();
            let headers = getHeaders(auth);
            const query = getQueryString(data);
            const result = yield new Promise((resolve, reject) => {
                exports.client.get(exports.url + endpoint + query, { headers }, (result) => {
                    if (Buffer.isBuffer(result))
                        reject('Result was buffer (HTML, not JSON)');
                    else if (!success(result, ignore))
                        reject(result);
                    else
                        resolve(result);
                }).on('error', (err) => reject(err));
            });
            log_1.logger.debug('[API] GET result:', result);
            return result;
        }
        catch (err) {
            log_1.logger.error(`[API] GET error (${endpoint}):`, err);
        }
    });
}
function get ( endpoint , data , auth = true , ignore ) { return __awaiter ( this , void 0 , void 0 , function * ( ) { try { log_1 . logger . debug ( ` ${ endpoint } ` , data ) ; if ( auth && ! loggedIn ( ) ) yield login ( ) ; let headers = getHeaders ( auth ) ; const query = getQueryString ( data ) ; const result = yield new Promise ( ( resolve , reject ) => { exports . client . get ( exports . url + endpoint + query , { headers } , ( result ) => { if ( Buffer . isBuffer ( result ) ) reject ( 'Result was buffer (HTML, not JSON)' ) ; else if ( ! success ( result , ignore ) ) reject ( result ) ; else resolve ( result ) ; } ) . on ( 'error' , ( err ) => reject ( err ) ) ; } ) ; log_1 . logger . debug ( '[API] GET result:' , result ) ; return result ; } catch ( err ) { log_1 . logger . error ( ` ${ endpoint } ` , err ) ; } } ) ; }
Do a GET request to an API endpoint
@param endpoint   The API endpoint (including version) e.g. `users.info`
@param data       Object to serialise for GET request query string
@param auth       Require auth headers for endpoint, default true
@param ignore     Allows certain matching error messages to not count as errors
Do a GET request to an API endpoint