The API I'm using is owapi.net/api/v3/u/Calvin-1337/stats
(the name will change). Let's say I wanted the tier
, that'd be JSON.us.stats.competitive.overall_stats.tier
and I can parse that and get it okay. But now I want to create a promise. Let's make it for the overall_stats
so... us.stats.competitive.overall_stats
and I only want values from there for the moment. I wan't to be able to do something like:
const core = require("myNodePackage");
core.getCompOverallStats("Calvin-1337").then(data > {
console.log(data.tier) // grandmaster
// etc through to
console.log(data.prestige) // 5
});
This is totally wrong but what I had thought about:
const fetch = require("node-fetch"); // used to get json data
getCompOverallStats = (playerName) => {
return new Promise((resolve, reject) => {
// only want this for us.stats.competitive.overall_stats
fetch("https://owapi.net/api/v3/u/Calvin-1337/stats")
.then(function(res) => {
return res.json();
}).then(function(json) {
//console.log(json.us.stats.competitive.overall_stats.tier) => grandmaster
});