Skip to content

Instantly share code, notes, and snippets.

@bcuz
Created September 27, 2017 13:10
Show Gist options
  • Select an option

  • Save bcuz/d251cfacf17d44a46d446da1b015ce2e to your computer and use it in GitHub Desktop.

Select an option

Save bcuz/d251cfacf17d44a46d446da1b015ce2e to your computer and use it in GitHub Desktop.
const Yelp = {
getAccessToken() {
if (accessToken) {
return new Promise(function(resolve) {
resolve(accessToken)
})
}
return fetch('https://cors-anywhere.herokuapp.com/' + 'https://api.yelp.com/oauth2/token?grant_type=client_credentials&client_id=' + clientId + '&client_secret=' + secret, { method: 'POST'}).then(response => response.json()).then(jsonResponse => accessToken = jsonResponse.access_token)
},
search(term, location, sortBy) {
// doesnt seem to work all the time for w/e reason
return Yelp.getAccessToken().then(() => fetch('https://cors-anywhere.herokuapp.com/' + 'https://api.yelp.com/v3/businesses/search?term=' + term + '&location=' + location + '&sort_by=' + sortBy, {headers: { Authorization: `Bearer ${accessToken}` }})).then(response => response.json()).then(jsonResponse => jsonResponse.businesses.map(function(business) { return { name: business.name } } ))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment