less hacking way of pulling poe data

This commit is contained in:
2018-08-27 23:54:27 -05:00
parent 5423b81c95
commit 97acc0d4fa
34 changed files with 651 additions and 221 deletions

View File

@@ -1,20 +1,44 @@
import PQueue from 'p-queue';
import { POE_HOME, POE_LEAGUE_LIST_URL, POE_STASH_ITEMS_URL } from '../constants';
import { http } from '../http';
export class PoeService {
public static async getStash(): Promise<any> {
const res = await http.get(
'https://pathofexile.com/character-window/get-stash-items?' +
'league=Incursion&tabs=1&tabIndex=6&accountName=DoctorCoctor',
);
return res.data;
}
const queue = new PQueue({ concurrency: 1 });
public static async priceCheck(item: any) {
const res = await http.get(`https://poeprices.info/api?l=Incursion&i=${encodeURI(btoa(item))}`, {
headers: {
'Cache-Control': 'max-age=600',
},
const getStash = async (username: string, league: string, tabIndex: number | string): Promise<any> => {
const res = await http.get(
`${POE_STASH_ITEMS_URL}?league=${league}&tabs=1&tabIndex=${tabIndex}&accountName=${username}`,
);
return res.data;
};
const priceCheck = async (item: any): Promise<any> => {
return new Promise(resolve => {
queue.add(() => {
return http
.get(`https://poeprices.info/api?l=Incursion&i=${encodeURI(btoa(item))}`, {
headers: {
'Cache-Control': 'max-age=600',
},
})
.then(resolve);
});
return res.data;
}
}
});
};
const getUsername = async (): Promise<any> => {
const res = await http.get(POE_HOME);
const username = res.data.match(/\/account\/view-profile\/(.*?)\"/);
return username[1];
};
const getLeagues = async (): Promise<any> => {
const res = await http.get(POE_LEAGUE_LIST_URL);
return res.data;
};
export const PoeService = {
getLeagues,
getStash,
getUsername,
priceCheck,
};