Link/ShortenedLink.js

  1. const superagent = require("superagent");
  2. /**
  3. * @exports ShortenedLink
  4. * @class Shortened link handler.
  5. * @description Used to handle a link you shortened.
  6. */
  7. module.exports = class ShortenedLink {
  8. /**
  9. * @description Constructs the handler for shortened link.
  10. * @param {object} link_data The json object you get after shortening the link.
  11. * @hideconstructor
  12. */
  13. constructor(link_data) {
  14. /**@private */
  15. this.url = link_data.url;
  16. /**@private */
  17. this.del_url = link_data.del_url;
  18. }
  19. /**
  20. * @returns {String} The shortened link.
  21. * @function getUrl
  22. * @description Get the shortened URL.
  23. * @memberof ShortenedLink
  24. * @instance
  25. */
  26. getUrl = () => this.url;
  27. /**
  28. * @memberof ShortenedLink
  29. * @instance
  30. * @function getDelUrl
  31. * @description Get the delete URL to this shortened link.
  32. * @returns {String} The delete url of the shortified link.
  33. */
  34. getDelUrl = () => this.del_url;
  35. /**
  36. * @memberof ShortenedLink
  37. * @instance
  38. * @function delete
  39. * @description Delete the shortened link.
  40. * @returns {Promise<undefined|Error>} Promise, deletes the shortened link. Returns undefined on success.
  41. */
  42. delete = () => new Promise((resolve, reject) => {
  43. superagent.get(this.getDelUrl())
  44. .end((err, res) => {
  45. if(err) return reject(err);
  46. resolve();
  47. })
  48. })
  49. }
    JAVASCRIPT
    Copied!