Created
September 16, 2020 22:14
-
-
Save mojowen/5a1c56808c07a82a48af311f1f3054ad to your computer and use it in GitHub Desktop.
Figure out if pizza hut serves a given address
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fetch = require('node-fetch') | |
const PIZZA_HUT_ENDPOINT = 'https://www.pizzahut.com/api.php/site/api_ajax/search/delivery' | |
const getCookies = async() => { | |
const resp = await fetch(PIZZA_HUT_ENDPOINT, { method: 'post' }) | |
return resp.headers.get('set-cookie').split(',').map((el) => (`${el.split(';')[0]}`)).join(';') | |
} | |
const pizzaSearch = async (address, address2, zip, city, state, lat, lng) => { | |
const body = { | |
customer_address1: address, | |
customer_address2: address2, | |
customer_postal_code: zip, | |
customer_city: city, | |
customer_state: state, | |
latitude: lat, | |
longitude: lng, | |
limit: 5 | |
} | |
try { | |
const resp = await fetch( | |
PIZZA_HUT_ENDPOINT, | |
{ | |
method: 'post', | |
headers: { | |
cookie: await getCookies() | |
}, | |
body: JSON.stringify(body) | |
} | |
) | |
return await resp.json() | |
} catch(e) { | |
console.log(e) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment