sign_request($signature_method, $consumer, $token); // Get the signed URL $signed_url = $oauthrequest->to_url(); // Send Yelp API Call $ch = curl_init($signed_url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HEADER, 0); $data = curl_exec($ch); curl_close($ch); return $data; } /** * Query the Search API by a search term and location * * @param $term The search term passed to the API * @param $location The search location passed to the API * @return The JSON response from the request */ function search($term, $location) { $url_params = array(); $url_params['term'] = $term ?: $GLOBALS['DEFAULT_TERM']; $url_params['location'] = $location?: $GLOBALS['DEFAULT_LOCATION']; $url_params['limit'] = $GLOBALS['SEARCH_LIMIT']; $search_path = $GLOBALS['SEARCH_PATH'] . "?" . http_build_query($url_params); return request($GLOBALS['API_HOST'], $search_path); } /** * Query the Business API by business_id * * @param $business_id The ID of the business to query * @return The JSON response from the request */ function get_business($business_id) { $business_path = $GLOBALS['BUSINESS_PATH'] . $business_id; return request($GLOBALS['API_HOST'], $business_path); } /** * Queries the API by the input values from the user * * @param $term The search term to query * @param $location The location of the business to query */ function query_api($term, $location) { $response = json_decode(search($term, $location)); $business_id = $response->businesses[0]->id; print sprintf( "%d businesses found, querying business info for the top result \"%s\"\n\n", count($response->businesses), $business_id ); $response = get_business($business_id); print sprintf("Result for business \"%s\" found:\n", $business_id); print "$response\n"; } /** * User input is handled here */ $longopts = array( "term::", "location::", ); $options = getopt("", $longopts); $term = $options['term'] ?: ''; $location = $options['location'] ?: ''; query_api($term, $location); ?>

Neighbourhood Data

Powered by Yelp!