Skip to content

Instantly share code, notes, and snippets.

@BaReinhard
Last active May 25, 2020 13:34
Show Gist options
  • Save BaReinhard/0832af2438ac428de57ab191f5316a68 to your computer and use it in GitHub Desktop.
Save BaReinhard/0832af2438ac428de57ab191f5316a68 to your computer and use it in GitHub Desktop.
Update trades Path of Diablo
function postData(url = ``, data = {}) {
// Default options are marked with *
return fetch(url, {
method: "POST", // *GET, POST, PUT, DELETE, etc.
headers: {
Cookie:
"COOKIE_GOES_HERE",
"Content-Type": "application/json",
"X-XSRF-TOKEN":
"TOKEN_GOES_HERE"
},
body: JSON.stringify(data) // body data type must match "Content-Type" header
}).then(response => {
return response.json();
}); // parses response to JSON
}
// refreshOffer takes a tradeID aka oID from the account_details information and a trade type, whether the trade was offer or need
function refreshOffer(tradeID, tradeType) {
postData("https://pathofdiablo.com/portal/api/account/refresh_trade", {
tradeID,
tradeType
});
}
postData("https://pathofdiablo.com/portal/api/account-details", {
user: "USERNAME_GOES_HERE"
})
.then(res => {
return res;
})
.then(accountDetails => {
// capture current time
let date = new Date();
let now = new Date(date.valueOf() + date.getTimezoneOffset() * 60000);
// loop through offers and check whether they are expired or not
accountDetails.trades.offer.map(offer => {
let offerDate = new Date(offer.time);
// if expired refreshOffer/need
if ((now - offerDate) / 3600000 > 10) {
refreshOffer(offer.oID, "offer");
}
});
// loop through needs and check whether they are expired or not
// I don't have any needs so I wasn't able to test this one just yet
accountDetails.trades.need.map(need => {
let needDate = new Date(need.time);
// if expired refreshOffer/need
if ((now - needDate) / 3600000 > 10) {
refreshOffer(need.oID, "need");
}
});
});
@BaReinhard
Copy link
Author

screenshot 2019-01-24 10 08 25
screenshot 2019-01-24 10 11 23

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment