UNPKG

2.04 kBJavaScriptView Raw
1!function(){var e=require("./Logger.js"),t=require("superagent");require("superagent-proxy")(t),require("dotenv").config();var o=process.env.httpProxy;module.exports=new function(){return{executeGetRequest:function(n,s,u){function r(t,o){t||!o.ok?u(t,o):o.ok&&(e.info("Get response status="+o.status),"function"==typeof u&&u(t,o))}e.info("\r\nExecuted get request :"+n),null!=o?t.get(n).proxy(o).set(s).end(r):t.get(n).set(s).end(r)},executePostRequest:function(n,s,u,r){function c(t,o){t||!o.ok?r(t,o):o.ok&&(e.info("Post response status="+o.status),"function"==typeof r&&r(t,o))}e.info("Executed post request : "+n),null!=o?t.post(n).proxy(o).type("form").send(u).set(s).end(c):t.post(n).type("form").send(u).set(s).end(c)},executePutRequest:function(n,s,u,r){function c(t,o){t||!o.ok?r(t,o):o.ok&&(e.info("Put response status="+o.status),"function"==typeof r&&r(t,o))}e.info("Executed put request : "+n),null!=o?t.put(n).proxy(o).type("form").send(u).set(s).end(c):t.put(n).type("form").send(u).set(s).end(c)},executePatchRequest:function(n,s,u,r){function c(t,o){t||!o.ok?r(t,o):o.ok&&(e.info("Patch response status="+o.status),"function"==typeof r&&r(t,o))}e.info("Executed patch request : "+n),null!=o?t.patch(n).proxy(o).type("form").send(u).set(s).end(c):t.patch(n).type("form").send(u).set(s).end(c)},executeDeleteRequest:function(n,s,u){function r(t,o){t||!o.ok?u(t,o):o.ok&&(e.info("Delete response status="+o.status),"function"==typeof u&&u(t,o))}e.info("Executed delete request :"+n),null!=o?t.del(n).proxy(o).set(s).end(r):t.del(n).set(s).end(r)},getAccessToken:function(n,s,u,r){function c(t,o){if(t||!o.ok)r(t,o);else if(o.ok){e.info("Executed getAccessToken : "+JSON.stringify(o.body));var n=JSON.parse(JSON.stringify(o.body));"function"==typeof r&&r(t,n.access_token)}}e.info("Get access token url :"+n),console.log("Get access token url :"+n),null!=o?(console.log("Use proxy : "+o),t.post(n).proxy(o).type("form").send(u).set(s).end(c)):(console.log("No proxy setting"),t.post(n).type("form").send(u).set(s).end(c))}}}}();
\No newline at end of file