Created
August 1, 2018 04:23
-
-
Save farishkash/097ffc2d3f3c1ab8e0286036265f9712 to your computer and use it in GitHub Desktop.
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 apiKey = | |
"CYEw8PzXruGqaduiHtA8V1DXfojHcpkoJzK7wg7e1BzkGsFxOb2A55NHoTPf0I3lrsbrDQLSlp3NGWqgkwyGZLpp74hv9VCQ5rNb0wCodAxTPFAxCkVkoMuksH5eW3Yx"; | |
const Yelp = { | |
search(term, location, sortBy) { | |
console.log(term, location, sortBy); | |
console.log( | |
`https://cors-anywhere.herokuapp.com/https://api.yelp.com/v3/businesses/search?term=${term}&location=${location}&sort_by=${sortBy}` | |
); | |
return fetch( | |
`https://cors-anywhere.herokuapp.com/https://api.yelp.com/v3/businesses/search?term=${term}&location=${location}&sort_by=${sortBy}`, | |
{ | |
headers: { | |
Authorization: `Bearer ${apiKey}` | |
} | |
} | |
) | |
.then(response => { | |
return response.json(); | |
}) | |
.then(jsonResponse => { | |
if (jsonResponse.businesses) { | |
return jsonResponse.businesses.map(business => { | |
return { | |
id: business.id, | |
imageSrc: business.image_url, | |
name: business.name, | |
address: business.location.address1, | |
city: business.location.city, | |
state: business.location.state, | |
zipCode: business.location.zip_code, | |
category: business.categories[0].title, | |
rating: business.rating, | |
reviewCount: business.review_count | |
}; | |
}); | |
} | |
}); | |
} | |
}; | |
export default Yelp; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment