smartrequest/dist/index.js

63 lines
5.4 KiB
JavaScript
Raw Normal View History

2017-01-28 23:51:47 +00:00
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
2017-06-09 19:48:16 +00:00
Object.defineProperty(exports, "__esModule", { value: true });
2018-06-14 20:48:50 +00:00
const plugins = require("./smartrequest.plugins");
2017-01-28 23:51:47 +00:00
const smartrequest_request_1 = require("./smartrequest.request");
2017-01-29 00:12:42 +00:00
var smartrequest_request_2 = require("./smartrequest.request");
exports.request = smartrequest_request_2.request;
2017-01-28 23:51:47 +00:00
exports.get = (domainArg, optionsArg = {}) => __awaiter(this, void 0, void 0, function* () {
optionsArg.method = 'GET';
let response = yield smartrequest_request_1.request(domainArg, optionsArg);
return response;
});
2018-06-13 21:12:37 +00:00
exports.getBinary = (domainArg, optionsArg = {}) => __awaiter(this, void 0, void 0, function* () {
2018-06-14 20:48:50 +00:00
const done = plugins.smartq.defer();
2018-06-13 21:12:37 +00:00
const response = yield smartrequest_request_1.request(domainArg, optionsArg, true);
var data = [];
response.on('data', function (chunk) {
data.push(chunk);
}).on('end', function () {
//at this point data is an array of Buffers
//so Buffer.concat() can make us a new Buffer
//of all of them together
const buffer = Buffer.concat(data);
response.body = buffer.toString('base64');
2018-06-14 20:48:50 +00:00
done.resolve();
2018-06-13 21:12:37 +00:00
});
2018-06-14 20:48:50 +00:00
yield done.promise;
return response;
2018-06-13 21:12:37 +00:00
});
2017-01-28 23:51:47 +00:00
exports.post = (domainArg, optionsArg = {}) => __awaiter(this, void 0, void 0, function* () {
optionsArg.method = 'POST';
2018-06-13 20:34:49 +00:00
if (typeof optionsArg.requestBody === 'object' &&
(!optionsArg.headers || !optionsArg.headers['Content-Type'])) {
// make sure headers exist
if (!optionsArg.headers) {
optionsArg.headers = {};
}
// assign the right Content-Type, leaving all other headers in place
Object.assign(optionsArg.headers, {
'Content-Type': 'application/json'
});
}
2017-01-28 23:51:47 +00:00
let response = yield smartrequest_request_1.request(domainArg, optionsArg);
return response;
});
exports.put = (domainArg, optionsArg = {}) => __awaiter(this, void 0, void 0, function* () {
optionsArg.method = 'PUT';
let response = yield smartrequest_request_1.request(domainArg, optionsArg);
return response;
});
exports.del = (domainArg, optionsArg = {}) => __awaiter(this, void 0, void 0, function* () {
optionsArg.method = 'DELETE';
let response = yield smartrequest_request_1.request(domainArg, optionsArg);
return response;
});
2018-06-14 20:48:50 +00:00
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7O0FBRUEsa0RBQWtEO0FBR2xELGlFQUEwRTtBQUUxRSwrREFBMEU7QUFBakUseUNBQUEsT0FBTyxDQUFBO0FBR0wsUUFBQSxHQUFHLEdBQUcsQ0FBTyxTQUFpQixFQUFFLGFBQThDLEVBQUUsRUFBRSxFQUFFO0lBQzdGLFVBQVUsQ0FBQyxNQUFNLEdBQUcsS0FBSyxDQUFDO0lBQzFCLElBQUksUUFBUSxHQUFHLE1BQU0sOEJBQU8sQ0FBQyxTQUFTLEVBQUUsVUFBVSxDQUFDLENBQUM7SUFDcEQsT0FBTyxRQUFRLENBQUM7QUFDbEIsQ0FBQyxDQUFBLENBQUM7QUFFUyxRQUFBLFNBQVMsR0FBRyxDQUFPLFNBQWlCLEVBQUUsYUFBOEMsRUFBRSxFQUFFLEVBQUU7SUFDbkcsTUFBTSxJQUFJLEdBQUcsT0FBTyxDQUFDLE1BQU0sQ0FBQyxL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