Source: morphology.js

  1. /**
  2. * Analytics API.
  3. *
  4. * @copyright 2016-2024 Basis Technology Corporation.
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance
  7. * with the License. You may obtain a copy of the License at
  8. * @license http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software distributed under the License is
  11. * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and limitations under the License.
  13. **/
  14. "use strict";
  15. var URL = require("url");
  16. var RosetteConstants = require("./rosetteConstants");
  17. var RosetteException = require("./rosetteExceptions");
  18. var rosetteRequest = require("./rosetteRequest");
  19. /**
  20. * @class
  21. *
  22. * @copyright 2016-2024 Basis Technology Corporation.
  23. * @license http://www.apache.org/licenses/LICENSE-2.0
  24. */
  25. function morphology() {
  26. //constructor function
  27. }
  28. /**
  29. * Makes an HTTP request to the specified Analytics API endpoint and returns the result
  30. * @param {string} parameters - The Analytics API endpoint parameters
  31. * @param {string} userKey - The Analytics API user access key
  32. * @param {string} serviceURL - The base service URL to be used to access the Analytics API
  33. * @param {function} callback - Callback function to be executed after the function to which it is passed is complete
  34. */
  35. morphology.prototype.getResults = function(parameters, userKey, protocol, serviceURL, callback) {
  36. if (parameters.documentFile != null) {
  37. parameters.loadFile(parameters.documentFile, parameters, userKey, protocol, serviceURL, `morphology/${parameters.morphology}`, callback);
  38. } else {
  39. var responseMessage = "bad arguments";
  40. // validate parameters
  41. if (!parameters.loadParams().content && !parameters.loadParams().contentUri) {
  42. return callback(new RosetteException("badArgument", "Must supply one of Content or ContentUri", responseMessage));
  43. } else if (parameters.loadParams().content && parameters.loadParams().contentUri) {
  44. return callback(new RosetteException("badArgument", "Cannot supply both Content and ContentUri", responseMessage));
  45. } else if (!parameters.morphology) {
  46. return callback(new RosetteException("badArgument", "Must supply type of morphology", responseMessage));
  47. } else {
  48. // configure URL
  49. var urlParts = URL.parse(serviceURL + `morphology/${parameters.morphology}`);
  50. var req = new rosetteRequest();
  51. req.makeRequest('POST', userKey, protocol, urlParts, parameters, callback);
  52. }
  53. }
  54. };
  55. module.exports = morphology;