const axios = require("axios"); class Core { lang = "pt"; signId = null; service = "https://helpers.arjos.com.br" endpoints = [ { id: "ip", urls: [ { id: "get", path: "ip" }, ] }, { id: "email", urls: [ { id: "verify", path: "email/verify" }, { id: "glossary", path: "" }, ] }, { id: "horoscope", urls: [ { id: "sign", path: `horoscope/${this.lang}/${this.signId}` }, { id: "glossary", path: "" }, ] }, { id: "pix", urls: [ { id: "generate", path: "generate" }, { id: "glossary", path: "" }, ] }, ] requestGet(endpoint) { axios.get(`${this.service}/${endpoint}`) .then(function (response) { // handle success console.log(JSON.stringify(response.data)); }) .catch(function (error) { // handle error console.log(error); }) .finally(function () { // always executed }); } requestPost() { axios.post(`${this.service}/${endpoint}`) .then(function (response) { // handle success console.log(JSON.stringify(response.data)); }) .catch(function (error) { // handle error console.log(error); }) .finally(function () { // always executed }); } getEndpointObject(key, value) { const object = this.endpoints.find(item => { return item[`${key}`] === value; }); return object === undefined ? {} : object; } getObjectGroup(group, key, value) { const object = group.find(item => { return item[`${key}`] === value; }); return object === undefined ? {} : object; } getIp() { let endpoint = this.getObjectGroup(this.getEndpointObject("id", "ip").urls, "id", "get").path return this.requestGet(endpoint) } } exports.module = new Core(); // new Core().requestGet();