src/api.js
function _request( options ) {
    options.headers = options.headers || {};
    options.headers[ 'X-OpenRosa-Version' ] = '1.0';

    const method = options.method || 'get';

    return new Promise( ( resolve, reject ) => {
        request[ method ]( options, ( error, response, body ) => {
            if ( error ) {
                console.log( `Error occurred when requesting ${options.url}`, error );
                reject( error );
            } else if ( response.statusCode === 401 ) {
                const error = new Error( 'Forbidden. Authorization Required.' );
                error.status = response.statusCode;
                reject( error );
            } else if ( response.statusCode < 200 || response.statusCode >= 300 ) {
                const error = new Error( `Request to ${options.url} failed.` );
                error.status = response.statusCode;
                reject( error );
            } else {
                console.log( `response of request to ${options.url} has status code: `, response.statusCode );
                resolve( body );
            }
        } );
    } );
}
function _request( options ) {
    options.headers = options.headers || {};
    options.headers[ 'X-OpenRosa-Version' ] = '1.0';

    const method = options.method || 'get';

    return new Promise( ( resolve, reject ) => {
        request[ method ]( options, ( error, response, body ) => {
            if ( error ) {
                console.log( `Error occurred when requesting ${options.url}`, error );
                reject( error );
            } else if ( response.statusCode === 401 ) {
                const error = new Error( 'Forbidden. Authorization Required.' );
                error.status = response.statusCode;
                reject( error );
            } else if ( response.statusCode < 200 || response.statusCode >= 300 ) {
                const error = new Error( `Request to ${options.url} failed.` );
                error.status = response.statusCode;
                reject( error );
            } else {
                console.log( `response of request to ${options.url} has status code: `, response.statusCode );
                resolve( body );
            }
        } );
    } );
}
function _request ( options ) { options . headers = options . headers || { } ; options . headers [ 'X-OpenRosa-Version' ] = '1.0' ; const method = options . method || 'get' ; return new Promise ( ( resolve , reject ) => { request [ method ] ( options , ( error , response , body ) => { if ( error ) { console . log ( ` ${ options . url } ` , error ) ; reject ( error ) ; } else if ( response . statusCode === 401 ) { const error = new Error ( 'Forbidden. Authorization Required.' ) ; error . status = response . statusCode ; reject ( error ) ; } else if ( response . statusCode < 200 || response . statusCode >= 300 ) { const error = new Error ( ` ${ options . url } ` ) ; error . status = response . statusCode ; reject ( error ) ; } else { console . log ( ` ${ options . url } ` , response . statusCode ) ; resolve ( body ) ; } } ) ; } ) ; }
Sends a request to an OpenRosa server. Only for basic retrieval of
public forms that do not require authentication.

@param  { {url: string, method: string} } options  request options object
@return { Promise }
Sends a request to an OpenRosa server . Only for basic retrieval of public forms that do not require authentication .