All files / src/api index.js

100% Statements 16/16
56.25% Branches 9/16
100% Functions 6/6
100% Lines 16/16
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49    27x 4x 4x 4x   4x 22x 22x     4x         2x                       2x     1x 1x       2x       2x     1x 1x      
import config from '../config';
 
const compose = (url, queryParams) => {
    let newUrl = url;
    Eif (url.indexOf('?') === -1) {
        newUrl += '?';
    }
    Object.keys(queryParams).forEach((key) => {
        Eif ({}.hasOwnProperty.call(queryParams, key)) {
            newUrl += `${key}=${queryParams[key]}&`;
        }
    });
    return newUrl;
};
 
export default {
    smartstatus(options) {
        const url = compose(`${config.get('domain')}v01/section.smart`, {
            apikey: config.get('apikey'),
            country: config.get('country'),
            subsection: options.subsection || '',
            content_id: options.contentId || '',
            hybridnews: config.get('hybridnews'),
            store_type: config.get('store_type'),
            skip: options.skip ? options.skip : 0,
            sentpin: options.sentpin ? options.sentpin : 0,
            access_token: options.access_token ? options.access_token : '',
            return_url: options.returnUrl ? options.returnUrl : ''
        });
        return fetch(url, {
            credentials: 'same-origin'
        }).then(
            response => response.json(),
            error => error
        );
    },
    getAlias(options) {
        const url = compose(config.get('aliasCheckUrl'), {
            msisdn: options.msisdn
        });
 
        return fetch(url, {
            credentials: 'same-origin'
        }).then(
            response => response.json(),
            error => error
        );
    }
};