Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(asus): realtime api #675

Merged
merged 1 commit into from
Nov 3, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 30 additions & 1 deletion src/store/model/asus.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {Store} from './store';
import fetch from 'node-fetch';

export const Asus: Store = {
labels: {
Expand All @@ -10,41 +11,69 @@ export const Asus: Store = {
links: [
{
brand: 'test:brand',
itemNumber: '202007AM020000005',
model: 'test:model',
series: 'test:series',
url: 'https://store.asus.com/us/item/202003AM280000002'
url: 'https://store.asus.com/us/item/202007AM020000005'
},
{
brand: 'asus',
itemNumber: '202009AM160000001',
model: 'tuf oc',
series: '3080',
url: 'https://store.asus.com/us/item/202009AM160000001'
},
{
brand: 'asus',
itemNumber: '202009AM150000004',
model: 'tuf',
series: '3080',
url: 'https://store.asus.com/us/item/202009AM150000004'
},
{
brand: 'asus',
itemNumber: '202009AM150000003',
model: 'tuf',
series: '3090',
url: 'https://store.asus.com/us/item/202009AM150000003'
},
{
brand: 'asus',
itemNumber: '202009AM150000001',
model: 'tuf oc',
series: '3090',
url: 'https://store.asus.com/us/item/202009AM150000001'
},
{
brand: 'asus',
itemNumber: '202009AM290000002',
model: 'rog strix oc',
series: '3080',
url: 'https://store.asus.com/us/item/202009AM290000002'
}
],
name: 'asus',
realTimeInventoryLookup: async (itemNumber: string) => {
const request_url = 'https://store.asus.com/us/category/get_real_time_data';
const response = await fetch(request_url, {
body: 'sm_seq_list%5B%5D=' + itemNumber,
headers: {
'accept-language': 'en-US,en;q=0.9',
'cache-control': 'no-cache',
'content-type': 'application/x-www-form-urlencoded; charset=UTF-8'
},
method: 'POST'
});
const response_json = await response.json();

if (response_json.data[itemNumber] !== undefined) {
const item_info = response_json.data[itemNumber].market_info;
if (item_info.buy === true || item_info.quantity > 0) {
return true;
}
}

return false;
},
successStatusCodes: [[0, 399], 404]
};