cce-unified-config
Advanced tools
Comparing version 0.8.1 to 0.9.0
45
index.js
const axios = require('axios') | ||
const parseXmlString = require('./parse-xml') | ||
@@ -76,2 +77,12 @@ class UnifiedConfig { | ||
async get(type, id, q) { | ||
// pass params from input | ||
const params = {q} | ||
try { | ||
return await axios.get(`${this.url}${type.toLowerCase()}/${id}`, body, {auth: this.auth, params}) | ||
} catch (e) { | ||
throw e | ||
} | ||
} | ||
async modify(type, body, q) { | ||
@@ -106,15 +117,29 @@ // pass params from input | ||
} | ||
const headers = { | ||
// 'Content-Type' | ||
'Accept': 'application/xml' | ||
} | ||
const options = { | ||
auth: this.auth, | ||
params, | ||
headers | ||
} | ||
try { | ||
let response = await axios.get(this.url + type.toLowerCase(), {auth: this.auth, params}) | ||
let totalResults = response.data.pageInfo.totalResults | ||
const response = await axios.get(this.url + type.toLowerCase(), options) | ||
const jsonData = (await parseXmlString(response.data)).results | ||
// console.log('json',jsonData) | ||
let totalResults = jsonData.pageInfo.totalResults | ||
// console.log('totalResults', totalResults) | ||
// console.log('data', response.data[`${type}s`][0][`${type}`]) | ||
// console.log('data', jsonData[`${type}s`][0][`${type}`]) | ||
// good response? | ||
if (totalResults === 0) { | ||
// console.log('jsonData', jsonData) | ||
if (totalResults === '0') { | ||
// no results | ||
return [] | ||
} else if (totalResults === '1') { | ||
// return single result as an array of 1 element | ||
return [jsonData[`${type}s`][`${type}`]] | ||
} else { | ||
// console.log('response.data', response.data) | ||
// 1 or more results | ||
let data = response.data[`${type}s`][0][`${type}`] | ||
// 2 or more results | ||
let data = jsonData[`${type}s`][`${type}`] | ||
// console.log('data', data) | ||
@@ -126,7 +151,7 @@ while (totalResults > params.startIndex + 100) { | ||
// fetch next data set | ||
response = await axios.get(this.url + type.toLowerCase(), {auth: this.auth, params}) | ||
response = await axios.get(this.url + type.toLowerCase(), options) | ||
// append data | ||
data = data.concat(response.data[`${type}s`][0][`${type}`]) | ||
data = data.concat(jsonData[`${type}s`][`${type}`]) | ||
} | ||
// all done, return data array | ||
// all done, return data as an array | ||
return data | ||
@@ -133,0 +158,0 @@ } |
{ | ||
"name": "cce-unified-config", | ||
"version": "0.8.1", | ||
"version": "0.9.0", | ||
"description": "JavaScript library for Cisco Contact Center Enterprise APIs", | ||
@@ -8,3 +8,3 @@ "main": "index.js", | ||
"start": "node index", | ||
"test": "NODE_TLS_REJECT_UNAUTHORIZED=0 node test" | ||
"test": "NODE_TLS_REJECT_UNAUTHORIZED=0 mocha" | ||
}, | ||
@@ -27,4 +27,5 @@ "repository": { | ||
"dependencies": { | ||
"axios": "^0.16.2" | ||
"axios": "^0.16.2", | ||
"xml2js": "^0.4.19" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8687
2
259
+ Addedxml2js@^0.4.19
+ Addedsax@1.4.1(transitive)
+ Addedxml2js@0.4.23(transitive)
+ Addedxmlbuilder@11.0.1(transitive)