Created
September 27, 2017 13:10
-
-
Save bcuz/a14a916773b6de9f3fc607d45808f83a to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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