UNPKG

ngx-restful-client

Version:

The ultimate Angular library to exquisitely declare and implement the REST APIs you'll use in your application.

55 lines (54 loc) 2.14 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var core_1 = require("../../core"); var http_options_builder_1 = require("../http-options-builder"); var utils_1 = require("../../utils"); var configureCharset = function (charset) { return "charset=" + charset; }; var configureBoundary = function (boundary) { return "boundary=" + boundary; }; var FormUrlEncoded = /** @class */ (function () { function FormUrlEncoded(params, options) { this.contentTypeVars = []; this.optsBuilder = http_options_builder_1.HttpOptionsBuilder.fresh(); this._boundary = '&'; this._params = params; this.optsBuilder.addOptions(options); this.contentTypeVars.push(core_1.ContentType.FORM_URL_ENCODED); } FormUrlEncoded.of = function (json, extras) { var map = utils_1.CoreUtil.objectToPlainMap(json); var params = []; map.forEach(function (v, k) { return params.push(k + "=" + v); }); return new FormUrlEncoded(params, extras); }; FormUrlEncoded.prototype.configure = function (charset, boundary) { if (!!charset) { this.contentTypeVars.push(configureCharset(charset)); } if (!!boundary) { this._boundary = boundary; this.contentTypeVars.push(configureBoundary(boundary)); } return this; }; FormUrlEncoded.prototype.getOptions = function (charset, boundary) { this.configure(charset, boundary); return this.options; }; Object.defineProperty(FormUrlEncoded.prototype, "options", { get: function () { var _this = this; return this.optsBuilder.headers(function (h) { return h.contentType(_this.contentTypeVars.join(';')); }).build(); }, enumerable: true, configurable: true }); Object.defineProperty(FormUrlEncoded.prototype, "body", { get: function () { return this._params.join(this._boundary); }, enumerable: true, configurable: true }); return FormUrlEncoded; }()); exports.FormUrlEncoded = FormUrlEncoded;