Code coverage report for modules/helpers.js

Statements: 100% (17 / 17)      Branches: 100% (2 / 2)      Functions: 100% (4 / 4)      Lines: 100% (17 / 17)      Ignored: none     

All files » modules/ » helpers.js
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      1 1             1   27 27   27 1 1     26 26 26             1   9 9   9   8       9      
 
'use strict';
 
var BPromise = require('bluebird');
var request = require('request');
 
/**
 * Custom promise-wrap around request.get()
 * @param requestParam
 * @returns {Promise}
 */
exports.getHTTP = function(url) {
 
    return new BPromise(function(resolve, reject) {
        request.get({ url: url, encoding: null }, function (error, response, body) {
 
            if(error) {
                console.log('Error: ' + error);
                reject(error);
            }
            else {
                console.log('Status: %d', response.statusCode);
                console.log('Size: %d', body.length);
                resolve({response: response, body: body});
            }
        });
    });
 
};
 
exports.getMatches = function(string, regex) {
 
    var matches = [];
    var match;
 
    while (match = regex.exec(string)) {
 
        matches.push(match[1]);
 
    }
 
    return matches;
 
};