I'm wondering if you can help me. I have some code that works that I have been trying to restructure. This is how it looks now:
function myfunction(ref) {
getReport(ref, "queue", "hour", "2018-09-03", "2018-10-04", "pageviews", "page").done(function(r1) {
getReport(r1.reportID, "get").done(r2=>reportHandler(r1.reportID, r2, 0))
});
}
function reportHandler(id, r2, retries){
if(retries >= 3){
console.log("Retried 3 times - stopping")
return
}
if (r2.error == "report_not_ready") {
console.log("Not ready");
setTimeout(function() {
getReport(id, "get").done(r2=>reportHandler(id, r2, retries + 1))
}, 2000);
}
console.log(r2);
}
function getReport(ref, type, granularity, from, to, metric, element) {
return $.getJSON("report.php", {
ref: ref,
type: type,
granularity: granularity,
from: from,
to: to,
metric: metric,
element: element,
});
}
What I haven't been able to figure out is how to process the data, which I want to be able to do in myfunction.
At the moment the only way I can do is return the data in my report handler function.
I want to be able to return the data from the API in my myfunction function where I will then process it further, and then keep my reporthander and getreport functions generic.
theninstead ofdoneto pipe outputs.