opengate-js 10.5.1 → 10.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bower.json +1 -1
- package/dist/{opengate-api-bower-10.5.1.js → opengate-api-bower-10.5.2.js} +11 -30
- package/dist/opengate-api-bower-10.5.2.js.map +1 -0
- package/dist/{opengate-api-bower-10.5.1.min.js → opengate-api-bower-10.5.2.min.js} +3 -3
- package/dist/opengate-api-bower-10.5.2.min.js.map +1 -0
- package/dist/src/util/NorthAmpliaREST.js +8 -27
- package/dist/src/util/NorthAmpliaREST.js.map +1 -1
- package/docs/ast/source/util/NorthAmpliaREST.js.json +11552 -16264
- package/docs/class/src/util/NorthAmpliaREST.js~NorthAmpliaREST.html +4 -4
- package/docs/class/src/util/SouthAmpliaREST.js~SouthAmpliaREST.html +1 -1
- package/docs/dump.json +4 -4
- package/docs/file/src/util/NorthAmpliaREST.js.html +8 -27
- package/docs/package.json +1 -1
- package/docs/source.html +193 -193
- package/package.json +1 -1
- package/src/util/NorthAmpliaREST.js +8 -27
- package/dist/opengate-api-bower-10.5.1.js.map +0 -1
- package/dist/opengate-api-bower-10.5.1.min.js.map +0 -1
|
@@ -391,7 +391,7 @@
|
|
|
391
391
|
<p>
|
|
392
392
|
|
|
393
393
|
|
|
394
|
-
<span data-ice="name"><span><a href="class/src/util/NorthAmpliaREST.js~NorthAmpliaREST.html#instance-method-get">get</a></span></span><span data-ice="signature">(url: <span><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a></span>, timeout: <span><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a></span>, headers: <span><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object">object</a></span>, parameters: <span><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object">object</a></span>,
|
|
394
|
+
<span data-ice="name"><span><a href="class/src/util/NorthAmpliaREST.js~NorthAmpliaREST.html#instance-method-get">get</a></span></span><span data-ice="signature">(url: <span><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a></span>, timeout: <span><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a></span>, headers: <span><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object">object</a></span>, parameters: <span><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object">object</a></span>, asBlob: <span><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">boolean</a></span>): <span><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a></span></span>
|
|
395
395
|
</p>
|
|
396
396
|
</div>
|
|
397
397
|
<div>
|
|
@@ -757,7 +757,7 @@
|
|
|
757
757
|
|
|
758
758
|
|
|
759
759
|
|
|
760
|
-
<span data-ice="name">get</span><span data-ice="signature">(url: <span><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a></span>, timeout: <span><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a></span>, headers: <span><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object">object</a></span>, parameters: <span><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object">object</a></span>,
|
|
760
|
+
<span data-ice="name">get</span><span data-ice="signature">(url: <span><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a></span>, timeout: <span><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a></span>, headers: <span><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object">object</a></span>, parameters: <span><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object">object</a></span>, asBlob: <span><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">boolean</a></span>): <span><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a></span></span>
|
|
761
761
|
<span class="right-info">
|
|
762
762
|
|
|
763
763
|
|
|
@@ -810,10 +810,10 @@
|
|
|
810
810
|
</td>
|
|
811
811
|
</tr>
|
|
812
812
|
<tr data-ice="property" data-depth="0">
|
|
813
|
-
<td data-ice="name" data-depth="0">
|
|
813
|
+
<td data-ice="name" data-depth="0">asBlob</td>
|
|
814
814
|
<td data-ice="type"><span><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">boolean</a></span></td>
|
|
815
815
|
<td data-ice="appendix"></td>
|
|
816
|
-
<td data-ice="description"><p>response body as
|
|
816
|
+
<td data-ice="description"><p>response body as Blob</p>
|
|
817
817
|
</td>
|
|
818
818
|
</tr>
|
|
819
819
|
</tbody>
|
|
@@ -392,7 +392,7 @@
|
|
|
392
392
|
<p>
|
|
393
393
|
|
|
394
394
|
|
|
395
|
-
<span data-ice="name"><span><a href="class/src/util/NorthAmpliaREST.js~NorthAmpliaREST.html#instance-method-get">get</a></span></span><span data-ice="signature">(url: <span><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a></span>, timeout: <span><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a></span>, headers: <span><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object">object</a></span>, parameters: <span><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object">object</a></span>,
|
|
395
|
+
<span data-ice="name"><span><a href="class/src/util/NorthAmpliaREST.js~NorthAmpliaREST.html#instance-method-get">get</a></span></span><span data-ice="signature">(url: <span><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a></span>, timeout: <span><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a></span>, headers: <span><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object">object</a></span>, parameters: <span><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object">object</a></span>, asBlob: <span><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">boolean</a></span>): <span><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a></span></span>
|
|
396
396
|
</p>
|
|
397
397
|
</div>
|
|
398
398
|
<div>
|
package/docs/dump.json
CHANGED
|
@@ -56896,7 +56896,7 @@
|
|
|
56896
56896
|
"__docId__": 2143,
|
|
56897
56897
|
"kind": "file",
|
|
56898
56898
|
"name": "src/util/NorthAmpliaREST.js",
|
|
56899
|
-
"content": "'use strict';\r\n\r\nimport merge from 'merge';\r\nimport urlencode from 'urlencode';\r\nimport request from 'superagent';\r\nimport q from 'q';\r\nimport fs from 'fs';\r\n// MOCK user searching\r\nimport _mock from 'superagent-mocker';\r\nconst mock = _mock(request);\r\n//\r\n\r\n/**\r\n * This is a wrapper of a Rest api javascript\r\n */\r\nexport default class NorthAmpliaREST {\r\n /**\r\n * @param {{ url: string,port: string,version: string,apiKey: string}} _options - this is configuration about Opengate North API.\r\n * @param {function} backend - this is a backend selected to manage a request to Opengate North API.\r\n */\r\n constructor(_options, headers) {\r\n this._options = merge.recursive(true, this.default(), _options);\r\n this._headers = headers;\r\n\r\n // ----------------------------------\r\n /*\r\n mock.post(_options.url + '/search/channels', function(req) {\r\n return {\r\n body: {\r\n \"channels\": [{\r\n \"name\": \"default_channel\",\r\n \"description\": \"Automatic channel\",\r\n \"organization\": \"organization_GetSetParam\",\r\n \"certificates\": []\r\n }]\r\n },\r\n statusCode: 200\r\n };\r\n }); \r\n */\r\n // mock.post(_options.url + '/search/catalog/operations', function(req) {\r\n // return {\r\n // body: {\r\n // \"operations\": [\r\n // {\r\n // \"name\": \"ADMINISTRATIVE_STATUS_CHANGE\",\r\n // \"title\": \"Administrative status change params\",\r\n // \"description\": \"Allows to change the administrative status of an entity\",\r\n // \"applicableTo\": [\r\n // \"GATEWAY\",\r\n // \"ASSET\",\r\n // \"SUBSCRIPTION\",\r\n // \"SUBSCRIBER\"\r\n // ],\r\n // \"categoryPath\": \"/admin\",\r\n // \"parameters\": {\r\n // \"schema\": {\r\n // \"type\": \"object\",\r\n // \"properties\": {\r\n // \"admsts\": {\r\n // \"type\": \"string\",\r\n // \"title\": \"Administrative status\"\r\n // }\r\n // },\r\n // \"additionalProperties\": false,\r\n // \"required\": [\"admsts\"]\r\n // }\r\n // },\r\n // \"steps\": [\r\n // {\r\n // \"name\": \"ADMINISTRATIVE_STATUS_CHANGE\",\r\n // \"title\": \"Administrative Status Change\",\r\n // \"description\": \"\"\r\n // }\r\n // ]\r\n // },\r\n // ]\r\n // },\r\n // statusCode: 200\r\n // };\r\n // }); \r\n // ----------------------------------\r\n\r\n }\r\n\r\n /**\r\n * This return a default configuration object\r\n * @return {object}\r\n */\r\n default () {\r\n return {\r\n timeout: 5000\r\n };\r\n }\r\n\r\n _url(options) {\r\n return options.url;\r\n }\r\n\r\n /**\r\n * Invoke GET action to url specified\r\n * @param {!string} url - url to execute GET\r\n * @param {number} timeout - timeout in milliseconds \r\n * @param {object} headers - headers of request\r\n * @param {object} parameters - parameters of request\r\n * @param {boolean} asBuffer - response body as buffer (Uint8Array)\r\n * @return {Promise} \r\n */\r\n get(url, timeout, headers, parameters, asBuffer) {\r\n var req = request.get(this._createUrl(url, parameters));\r\n return this._createPromiseRequest(req, null, timeout, headers, asBuffer);\r\n }\r\n\r\n /**\r\n * Invoke PATCH action to url and data specified\r\n * @param {!string} url - url to execute PATCH\r\n * @param {object} data - attach data to request PATCH\r\n * @param {number} timeout - timeout in milliseconds\r\n * @param {object} headers - headers of request\r\n * @param {object} parameters - parameters of request\r\n * @return {Promise} \r\n */\r\n patch(url, data, timeout, headers, parameters) {\r\n var req = request.patch(this._createUrl(url, parameters))\r\n .send(data);\r\n\r\n return this._createPromiseRequest(req, null, timeout, headers);\r\n }\r\n\r\n /**\r\n * Invoke POST action to url and data specified\r\n * @param {!string} url - url to execute POST\r\n * @param {object} data - attach data to request POST\r\n * @param {number} timeout - timeout in milliseconds\r\n * @param {object} headers - headers of request\r\n * @param {object} parameters - parameters of request\r\n * @return {Promise} \r\n */\r\n post(url, data, timeout, headers, parameters) {\r\n var req = request.post(this._createUrl(url, parameters))\r\n .send(data);\r\n\r\n return this._createPromiseRequest(req, null, timeout, headers);\r\n }\r\n\r\n\r\n /**\r\n * Invoke POST multipart action to url and data specified\r\n * @param {!string} url - url to execute POST\r\n * @param {FormData} formData - attach data to request POST\r\n * @param {object} events - events allowed, xhr.process \r\n * @param {number} timeout - timeout in milliseconds \r\n * @param {object} headers - headers of request\r\n * @param {object} parameters - parameters of request\r\n * @return {Promise} \r\n */\r\n post_multipart(url, formData, events, timeout, headers, parameters) {\r\n let req = request.post(this._createUrl(url, parameters));\r\n\r\n let sendFormData = true\r\n const formDataKeys = Object.keys(formData)\r\n formDataKeys.forEach(key => {\r\n switch (key) {\r\n case 'meta':\r\n case 'json':\r\n case 'file':\r\n req.field(key, formData[key]); \r\n delete formData[key]\r\n break\r\n case 'certificate': \r\n case 'processorBulkFile':\r\n req.attach('file', formData.processorBulkFile);\r\n sendFormData = false\r\n break\r\n case 'bulkFile':\r\n req.set('Content-Type', formData.ext);\r\n formData = formData.bulkFile;\r\n break\r\n default:\r\n break;\r\n }\r\n })\r\n if(sendFormData)\r\n req.send(formData);\r\n return this._createPromiseRequest(req, events, timeout, headers);\r\n \r\n }\r\n\r\n /**\r\n * Invoke PUT action to url and data specified\r\n * @param {!string} url - url to execute PUT\r\n * @param {object} data - attach data to request PUT\r\n * @param {number} timeout - timeout in milliseconds \r\n * @param {object} headers - headers of request\r\n * @param {object} parameters - parameters of request\r\n * @return {Promise} \r\n */\r\n put(url, data, timeout, headers, parameters) {\r\n var req = request.put(this._createUrl(url, parameters)).send(data);\r\n\r\n if (headers) {\r\n headers['Content-Type'] = 'application/json';\r\n } else {\r\n headers = {\r\n 'Content-Type': 'application/json'\r\n };\r\n }\r\n\r\n return this._createPromiseRequest(req, null, timeout, headers);\r\n }\r\n\r\n /**\r\n * Invoke DELETE action to url specified\r\n * @param {!string} url - url to execute DELETE\r\n * @param {number} timeout - timeout in milliseconds \r\n * @param {object} headers - headers of request\r\n * @param {object} parameters - parameters of request\r\n * @return {Promise} \r\n */\r\n delete(url, timeout, headers, parameters) {\r\n var req = request.delete(this._createUrl(url, parameters));\r\n return this._createPromiseRequest(req, null, timeout, headers);\r\n }\r\n\r\n _createUrl(relativeUrl, parameters) {\r\n var encode = [];\r\n\r\n if (parameters) {\r\n var keys = Object.keys(parameters);\r\n for (var i = 0; i < keys.length; i++) {\r\n var key = keys[i];\r\n var queryParameter = key + '=' + parameters[key];\r\n if (i === 0) {\r\n relativeUrl = relativeUrl + '?' + queryParameter;\r\n } else {\r\n relativeUrl = relativeUrl + '&' + queryParameter;\r\n }\r\n\r\n }\r\n console.log(JSON.stringify(parameters));\r\n }\r\n\r\n console.log(relativeUrl);\r\n\r\n var relativeUrlSplit = relativeUrl.split(\"/\");\r\n var length = relativeUrlSplit.length;\r\n\r\n relativeUrlSplit.forEach(function(item, index) {\r\n if (index === (length - 1) && item.indexOf(\"?\") > 0) {\r\n var parameters = item.substring(item.indexOf(\"?\"), item.length);\r\n var _item = item.substring(0, item.indexOf(\"?\"));\r\n encode.push(urlencode(_item) + parameters);\r\n } else {\r\n encode.push(urlencode(item));\r\n }\r\n });\r\n var returnUrl = this._url(this._options) + \"/\" + encode.join(\"/\");\r\n \r\n return returnUrl;\r\n }\r\n\r\n _createPromiseRequest(req, events, timeout, headers, asBuffer) {\r\n let _timeout = timeout;\r\n if (typeof _timeout === \"undefined\" || _timeout === null) {\r\n _timeout = this._options.timeout;\r\n }\r\n let defered = q.defer();\r\n let promise = defered.promise;\r\n let apiKey = this._options.apiKey;\r\n let _req = _timeout === -1 ? req : req.timeout(_timeout);\r\n\r\n if (apiKey) {\r\n _req = _req.set('X-ApiKey', this._options.apiKey);\r\n }\r\n\r\n if (headers) {\r\n var keys = Object.keys(headers);\r\n for (var i = 0; i < keys.length; i++) {\r\n var key = keys[i];\r\n if (headers[key] !== undefined)\r\n _req = _req.set(key, headers[key]);\r\n }\r\n }\r\n\r\n if (events) {\r\n for (let event in events) {\r\n _req = _req.on(event, events[event]);\r\n }\r\n }\r\n _req = _req.end(function(err, res) {\r\n if (err !== null) {\r\n let data;\r\n let status = err.status ? err.status : undefined;\r\n let errorMessage = {\r\n errors: [{\r\n code: status,\r\n message: 'OGAPI: Something is broken. Please contact with your administrator.'\r\n }]\r\n };\r\n \r\n if (typeof err.response !== \"undefined\") {\r\n data = err.response.body ? err.response.body : errorMessage;\r\n status = err.status;\r\n } else {\r\n if (!status) {\r\n data = errorMessage;\r\n status = 500;\r\n } else {\r\n data = err.message;\r\n status = 408;\r\n }\r\n }\r\n defered.reject({\r\n statusCode: status,\r\n 'data': data\r\n });\r\n } else {\r\n if(asBuffer){\r\n var chunks = []\r\n res.on(\"data\", function (chunk) {\r\n chunks.push(chunk);\r\n });\r\n \r\n res.on(\"end\", function (chunk) {\r\n let length = 0\r\n\r\n for(let i = 0; i < chunks.length; i++){\r\n length += chunks[i].length\r\n }\r\n const resultArray = new Uint8Array(length)\r\n let offset = 0\r\n\r\n for(let i = 0; i < chunks.length; i++){\r\n const c = chunks[i]\r\n resultArray.set(c, offset)\r\n offset += c.length\r\n }\r\n res.body = resultArray\r\n });\r\n }\r\n defered.resolve(res);\r\n }\r\n });\r\n\r\n return promise;\r\n }\r\n}",
|
|
56899
|
+
"content": "'use strict';\r\n\r\nimport merge from 'merge';\r\nimport urlencode from 'urlencode';\r\nimport request from 'superagent';\r\nimport q from 'q';\r\nimport fs from 'fs';\r\n// MOCK user searching\r\nimport _mock from 'superagent-mocker';\r\nconst mock = _mock(request);\r\n//\r\n\r\n/**\r\n * This is a wrapper of a Rest api javascript\r\n */\r\nexport default class NorthAmpliaREST {\r\n /**\r\n * @param {{ url: string,port: string,version: string,apiKey: string}} _options - this is configuration about Opengate North API.\r\n * @param {function} backend - this is a backend selected to manage a request to Opengate North API.\r\n */\r\n constructor(_options, headers) {\r\n this._options = merge.recursive(true, this.default(), _options);\r\n this._headers = headers;\r\n\r\n // ----------------------------------\r\n /*\r\n mock.post(_options.url + '/search/channels', function(req) {\r\n return {\r\n body: {\r\n \"channels\": [{\r\n \"name\": \"default_channel\",\r\n \"description\": \"Automatic channel\",\r\n \"organization\": \"organization_GetSetParam\",\r\n \"certificates\": []\r\n }]\r\n },\r\n statusCode: 200\r\n };\r\n }); \r\n */\r\n // mock.post(_options.url + '/search/catalog/operations', function(req) {\r\n // return {\r\n // body: {\r\n // \"operations\": [\r\n // {\r\n // \"name\": \"ADMINISTRATIVE_STATUS_CHANGE\",\r\n // \"title\": \"Administrative status change params\",\r\n // \"description\": \"Allows to change the administrative status of an entity\",\r\n // \"applicableTo\": [\r\n // \"GATEWAY\",\r\n // \"ASSET\",\r\n // \"SUBSCRIPTION\",\r\n // \"SUBSCRIBER\"\r\n // ],\r\n // \"categoryPath\": \"/admin\",\r\n // \"parameters\": {\r\n // \"schema\": {\r\n // \"type\": \"object\",\r\n // \"properties\": {\r\n // \"admsts\": {\r\n // \"type\": \"string\",\r\n // \"title\": \"Administrative status\"\r\n // }\r\n // },\r\n // \"additionalProperties\": false,\r\n // \"required\": [\"admsts\"]\r\n // }\r\n // },\r\n // \"steps\": [\r\n // {\r\n // \"name\": \"ADMINISTRATIVE_STATUS_CHANGE\",\r\n // \"title\": \"Administrative Status Change\",\r\n // \"description\": \"\"\r\n // }\r\n // ]\r\n // },\r\n // ]\r\n // },\r\n // statusCode: 200\r\n // };\r\n // }); \r\n // ----------------------------------\r\n\r\n }\r\n\r\n /**\r\n * This return a default configuration object\r\n * @return {object}\r\n */\r\n default () {\r\n return {\r\n timeout: 5000\r\n };\r\n }\r\n\r\n _url(options) {\r\n return options.url;\r\n }\r\n\r\n /**\r\n * Invoke GET action to url specified\r\n * @param {!string} url - url to execute GET\r\n * @param {number} timeout - timeout in milliseconds \r\n * @param {object} headers - headers of request\r\n * @param {object} parameters - parameters of request\r\n * @param {boolean} asBlob - response body as Blob\r\n * @return {Promise} \r\n */\r\n get(url, timeout, headers, parameters, asBlob) {\r\n var req = request.get(this._createUrl(url, parameters));\r\n return this._createPromiseRequest(req, null, timeout, headers, asBlob);\r\n }\r\n\r\n /**\r\n * Invoke PATCH action to url and data specified\r\n * @param {!string} url - url to execute PATCH\r\n * @param {object} data - attach data to request PATCH\r\n * @param {number} timeout - timeout in milliseconds\r\n * @param {object} headers - headers of request\r\n * @param {object} parameters - parameters of request\r\n * @return {Promise} \r\n */\r\n patch(url, data, timeout, headers, parameters) {\r\n var req = request.patch(this._createUrl(url, parameters))\r\n .send(data);\r\n\r\n return this._createPromiseRequest(req, null, timeout, headers);\r\n }\r\n\r\n /**\r\n * Invoke POST action to url and data specified\r\n * @param {!string} url - url to execute POST\r\n * @param {object} data - attach data to request POST\r\n * @param {number} timeout - timeout in milliseconds\r\n * @param {object} headers - headers of request\r\n * @param {object} parameters - parameters of request\r\n * @return {Promise} \r\n */\r\n post(url, data, timeout, headers, parameters) {\r\n var req = request.post(this._createUrl(url, parameters))\r\n .send(data);\r\n\r\n return this._createPromiseRequest(req, null, timeout, headers);\r\n }\r\n\r\n\r\n /**\r\n * Invoke POST multipart action to url and data specified\r\n * @param {!string} url - url to execute POST\r\n * @param {FormData} formData - attach data to request POST\r\n * @param {object} events - events allowed, xhr.process \r\n * @param {number} timeout - timeout in milliseconds \r\n * @param {object} headers - headers of request\r\n * @param {object} parameters - parameters of request\r\n * @return {Promise} \r\n */\r\n post_multipart(url, formData, events, timeout, headers, parameters) {\r\n let req = request.post(this._createUrl(url, parameters));\r\n\r\n let sendFormData = true\r\n const formDataKeys = Object.keys(formData)\r\n formDataKeys.forEach(key => {\r\n switch (key) {\r\n case 'meta':\r\n case 'json':\r\n case 'file':\r\n req.field(key, formData[key]); \r\n delete formData[key]\r\n break\r\n case 'certificate': \r\n case 'processorBulkFile':\r\n req.attach('file', formData.processorBulkFile);\r\n sendFormData = false\r\n break\r\n case 'bulkFile':\r\n req.set('Content-Type', formData.ext);\r\n formData = formData.bulkFile;\r\n break\r\n default:\r\n break;\r\n }\r\n })\r\n if(sendFormData)\r\n req.send(formData);\r\n return this._createPromiseRequest(req, events, timeout, headers);\r\n \r\n }\r\n\r\n /**\r\n * Invoke PUT action to url and data specified\r\n * @param {!string} url - url to execute PUT\r\n * @param {object} data - attach data to request PUT\r\n * @param {number} timeout - timeout in milliseconds \r\n * @param {object} headers - headers of request\r\n * @param {object} parameters - parameters of request\r\n * @return {Promise} \r\n */\r\n put(url, data, timeout, headers, parameters) {\r\n var req = request.put(this._createUrl(url, parameters)).send(data);\r\n\r\n if (headers) {\r\n headers['Content-Type'] = 'application/json';\r\n } else {\r\n headers = {\r\n 'Content-Type': 'application/json'\r\n };\r\n }\r\n\r\n return this._createPromiseRequest(req, null, timeout, headers);\r\n }\r\n\r\n /**\r\n * Invoke DELETE action to url specified\r\n * @param {!string} url - url to execute DELETE\r\n * @param {number} timeout - timeout in milliseconds \r\n * @param {object} headers - headers of request\r\n * @param {object} parameters - parameters of request\r\n * @return {Promise} \r\n */\r\n delete(url, timeout, headers, parameters) {\r\n var req = request.delete(this._createUrl(url, parameters));\r\n return this._createPromiseRequest(req, null, timeout, headers);\r\n }\r\n\r\n _createUrl(relativeUrl, parameters) {\r\n var encode = [];\r\n\r\n if (parameters) {\r\n var keys = Object.keys(parameters);\r\n for (var i = 0; i < keys.length; i++) {\r\n var key = keys[i];\r\n var queryParameter = key + '=' + parameters[key];\r\n if (i === 0) {\r\n relativeUrl = relativeUrl + '?' + queryParameter;\r\n } else {\r\n relativeUrl = relativeUrl + '&' + queryParameter;\r\n }\r\n\r\n }\r\n console.log(JSON.stringify(parameters));\r\n }\r\n\r\n console.log(relativeUrl);\r\n\r\n var relativeUrlSplit = relativeUrl.split(\"/\");\r\n var length = relativeUrlSplit.length;\r\n\r\n relativeUrlSplit.forEach(function(item, index) {\r\n if (index === (length - 1) && item.indexOf(\"?\") > 0) {\r\n var parameters = item.substring(item.indexOf(\"?\"), item.length);\r\n var _item = item.substring(0, item.indexOf(\"?\"));\r\n encode.push(urlencode(_item) + parameters);\r\n } else {\r\n encode.push(urlencode(item));\r\n }\r\n });\r\n var returnUrl = this._url(this._options) + \"/\" + encode.join(\"/\");\r\n \r\n return returnUrl;\r\n }\r\n\r\n _createPromiseRequest(req, events, timeout, headers, asBlob) {\r\n let _timeout = timeout;\r\n if (typeof _timeout === \"undefined\" || _timeout === null) {\r\n _timeout = this._options.timeout;\r\n }\r\n let defered = q.defer();\r\n let promise = defered.promise;\r\n let apiKey = this._options.apiKey;\r\n let _req = _timeout === -1 ? req : req.timeout(_timeout);\r\n\r\n if (apiKey) {\r\n _req = _req.set('X-ApiKey', this._options.apiKey);\r\n }\r\n\r\n if (headers) {\r\n var keys = Object.keys(headers);\r\n for (var i = 0; i < keys.length; i++) {\r\n var key = keys[i];\r\n if (headers[key] !== undefined)\r\n _req = _req.set(key, headers[key]);\r\n }\r\n }\r\n\r\n if (events) {\r\n for (let event in events) {\r\n _req = _req.on(event, events[event]);\r\n }\r\n }\r\n if(asBlob){\r\n req.responseType('blob')\r\n }\r\n _req = _req.end(function(err, res) {\r\n if (err !== null) {\r\n let data;\r\n let status = err.status ? err.status : undefined;\r\n let errorMessage = {\r\n errors: [{\r\n code: status,\r\n message: 'OGAPI: Something is broken. Please contact with your administrator.'\r\n }]\r\n };\r\n \r\n if (typeof err.response !== \"undefined\") {\r\n data = err.response.body ? err.response.body : errorMessage;\r\n status = err.status;\r\n } else {\r\n if (!status) {\r\n data = errorMessage;\r\n status = 500;\r\n } else {\r\n data = err.message;\r\n status = 408;\r\n }\r\n }\r\n defered.reject({\r\n statusCode: status,\r\n 'data': data\r\n });\r\n } else {\r\n \r\n defered.resolve(res);\r\n }\r\n });\r\n\r\n return promise;\r\n }\r\n}",
|
|
56900
56900
|
"static": true,
|
|
56901
56901
|
"longname": "src/util/NorthAmpliaREST.js",
|
|
56902
56902
|
"access": null,
|
|
@@ -57140,8 +57140,8 @@
|
|
|
57140
57140
|
],
|
|
57141
57141
|
"spread": false,
|
|
57142
57142
|
"optional": false,
|
|
57143
|
-
"name": "
|
|
57144
|
-
"description": "response body as
|
|
57143
|
+
"name": "asBlob",
|
|
57144
|
+
"description": "response body as Blob"
|
|
57145
57145
|
}
|
|
57146
57146
|
],
|
|
57147
57147
|
"return": {
|
|
@@ -57602,7 +57602,7 @@
|
|
|
57602
57602
|
]
|
|
57603
57603
|
},
|
|
57604
57604
|
{
|
|
57605
|
-
"name": "
|
|
57605
|
+
"name": "asBlob",
|
|
57606
57606
|
"types": [
|
|
57607
57607
|
"*"
|
|
57608
57608
|
]
|
|
@@ -347,12 +347,12 @@ export default class NorthAmpliaREST {
|
|
|
347
347
|
* @param {number} timeout - timeout in milliseconds
|
|
348
348
|
* @param {object} headers - headers of request
|
|
349
349
|
* @param {object} parameters - parameters of request
|
|
350
|
-
* @param {boolean}
|
|
350
|
+
* @param {boolean} asBlob - response body as Blob
|
|
351
351
|
* @return {Promise}
|
|
352
352
|
*/
|
|
353
|
-
get(url, timeout, headers, parameters,
|
|
353
|
+
get(url, timeout, headers, parameters, asBlob) {
|
|
354
354
|
var req = request.get(this._createUrl(url, parameters));
|
|
355
|
-
return this._createPromiseRequest(req, null, timeout, headers,
|
|
355
|
+
return this._createPromiseRequest(req, null, timeout, headers, asBlob);
|
|
356
356
|
}
|
|
357
357
|
|
|
358
358
|
/**
|
|
@@ -503,7 +503,7 @@ export default class NorthAmpliaREST {
|
|
|
503
503
|
return returnUrl;
|
|
504
504
|
}
|
|
505
505
|
|
|
506
|
-
_createPromiseRequest(req, events, timeout, headers,
|
|
506
|
+
_createPromiseRequest(req, events, timeout, headers, asBlob) {
|
|
507
507
|
let _timeout = timeout;
|
|
508
508
|
if (typeof _timeout === "undefined" || _timeout === null) {
|
|
509
509
|
_timeout = this._options.timeout;
|
|
@@ -531,6 +531,9 @@ export default class NorthAmpliaREST {
|
|
|
531
531
|
_req = _req.on(event, events[event]);
|
|
532
532
|
}
|
|
533
533
|
}
|
|
534
|
+
if(asBlob){
|
|
535
|
+
req.responseType('blob')
|
|
536
|
+
}
|
|
534
537
|
_req = _req.end(function(err, res) {
|
|
535
538
|
if (err !== null) {
|
|
536
539
|
let data;
|
|
@@ -559,29 +562,7 @@ export default class NorthAmpliaREST {
|
|
|
559
562
|
'data': data
|
|
560
563
|
});
|
|
561
564
|
} else {
|
|
562
|
-
|
|
563
|
-
var chunks = []
|
|
564
|
-
res.on("data", function (chunk) {
|
|
565
|
-
chunks.push(chunk);
|
|
566
|
-
});
|
|
567
|
-
|
|
568
|
-
res.on("end", function (chunk) {
|
|
569
|
-
let length = 0
|
|
570
|
-
|
|
571
|
-
for(let i = 0; i < chunks.length; i++){
|
|
572
|
-
length += chunks[i].length
|
|
573
|
-
}
|
|
574
|
-
const resultArray = new Uint8Array(length)
|
|
575
|
-
let offset = 0
|
|
576
|
-
|
|
577
|
-
for(let i = 0; i < chunks.length; i++){
|
|
578
|
-
const c = chunks[i]
|
|
579
|
-
resultArray.set(c, offset)
|
|
580
|
-
offset += c.length
|
|
581
|
-
}
|
|
582
|
-
res.body = resultArray
|
|
583
|
-
});
|
|
584
|
-
}
|
|
565
|
+
|
|
585
566
|
defered.resolve(res);
|
|
586
567
|
}
|
|
587
568
|
});
|