/* */ 
{
    var _ns_ = {
        id: 'atomita.http.request',
        doc: 'http request module'
    };
    var superagent = require('superagent');
    var bluebird = require('bluebird');
    var lodash = require('lodash');
}
var request = function request(method, url, params, options, clazz) {
    options = options || {};
    clazz = clazz || Object;
    return bluebird.resolve().then(function callApi() {
        return new bluebird(function (resolve, reject) {
            return function () {
                var apiø1 = superagent(method.toLowerCase(), url);
                lodash.has(options, 'query') ? apiø1.query(options.query) : void 0;
                lodash.has(options, 'header') ? apiø1.set(options.header) : void 0;
                return apiø1.send(params).end(function (err, response) {
                    return err || !response.ok ? reject(err || newError('undefined error.', response, err)) : resolve(response);
                });
            }.call(this);
        });
    }).then(function isObject(response) {
        return new bluebird(function (resolve, reject) {
            return options.isArray ? lodash.isArray(response.body) ? resolve(response) : reject(newError('Is not Array.', response)) : lodash.isObject(response.body) ? resolve(response) : reject(newError('Is not Object.', response));
        });
    }).then(function toResource(response) {
        return new bluebird(function (resolve, reject) {
            return options.isArray ? resolve(lodash.map(function (record) {
                return new clazz(record, response);
            })) : resolve(new clazz(response.body, response));
        });
    });
};
module.exports = request;
var newError = function newError(msg, response, err) {
    return function () {
        var newErrø1 = new Error(msg);
        return lodash.extend(newErrø1, {
            original: err,
            response: response,
            status: response ? response.status : null
        });
    }.call(this);
};
void 0;
