<commit_before>var request = require('request');
var qs = require('querystring');

exports.search = function (req, res) {
    search('http://api.deezer.com/search?', req.query.q, res, searchSuccess, searchError);
};

exports.searchByAlbum = function (req, res) {
    search('http://api.deezer.com/search/album?', req.query.q, res, searchSuccess, searchError);
};

exports.searchByArtist = function (req, res) {
    search('http://api.deezer.com/search/album?', req.query.q, res, searchSuccess, searchError);
};

function search(url, searchQuery, res, successCallback, errorCallback) {
    url += qs.stringify({
        q: searchQuery
    });
    request({
            uri: url,
            method: 'GET'
        },
        function (error, response, body) {
            if (!error && response.statusCode === 200) {
                successCallback(res, JSON.parse(body));
            } else {
                errorCallback(res, error, response, body);
            }
        }
    );
}

function searchSuccess(res, body) {
    res.status(200).send(body.data);
}

function searchError(res, error, response, body) {
    console.error(error, body);
    res.status(response.statusCode).send(body);<commit_msg>* Review code climate issues<commit_after>var request = require('request');
var qs = require('querystring');

exports.search = function (req, res) {
    search({
        url: 'http://api.deezer.com/search?',
        searchQuery: req.query.q,
        res: res,
        successCallback: searchSuccess,
        errorCallback: searchError
    });
};

exports.searchByAlbum = function (req, res) {
    search({
        url: 'http://api.deezer.com/search/album?',
        searchQuery: req.query.q,
        res: res,
        successCallback: searchSuccess,
        errorCallback: searchError
    });
};

exports.searchByArtist = function (req, res) {
    search({
        url: 'http://api.deezer.com/search/album?',
        searchQuery: req.query.q,
        res: res,
        successCallback: searchSuccess,
        errorCallback: searchError
    });
};

function search(options) {
    options.url += qs.stringify({
        q: options.searchQuery
    });
    request({
            uri: options.url,
            method: 'GET'
        },
        function (error, response, body) {
            if (!error && response.statusCode === 200) {
                options.successCallback(options.res, JSON.parse(body));
            } else {
                options.errorCallback(options.res, error, response, body);
            }
        }
    );
}

function searchSuccess(res, body) {
    res.status(200).send(body.data);
}

function searchError(res, error, response, body) {
    console.error(error, body);
    res.status(response.statusCode).send(body);
{'fraction_non_alphanumeric': 0.14562043795620438, 'fraction_numerical': 0.004379562043795621, 'mean_word_length': 2.527670527670528, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7510348', 'n_tokens_mistral': 830, 'n_tokens_neox': 805, 'n_words': 167}