35 lines
992 B
JavaScript
35 lines
992 B
JavaScript
/**
|
|
* Generates a properly formatted Cpteller API URL
|
|
* @param {Object} options - URL configuration options
|
|
* @param {string} options.apiType - 'webapi' or 'custapi'
|
|
* @param {string} [options.version] - API version (e.g., '26' for webapi)
|
|
* @param {Object} [options.params] - URL query parameters
|
|
* @returns {string} - The formatted Cpteller URL
|
|
*/
|
|
const getCptellerUrl = (options) => {
|
|
const domain = process.env?.NODE_ENV === "production" ? "secure" : "test";
|
|
|
|
const { apiType = "webapi", version, params = {} } = options;
|
|
|
|
// Base URL construction
|
|
let url = `https://${domain}.cpteller.com/api/`;
|
|
|
|
// Add version if specified for webapi
|
|
if (apiType === "webapi" && version) {
|
|
url += `${version}/`;
|
|
}
|
|
|
|
// Add the API endpoint
|
|
url += `${apiType}.cfc`;
|
|
|
|
// Add query parameters if any exist
|
|
const queryParams = new URLSearchParams(params).toString();
|
|
if (queryParams) {
|
|
url += `?${queryParams}`;
|
|
}
|
|
|
|
return url;
|
|
};
|
|
|
|
module.exports = getCptellerUrl;
|