Function Reference: gdfi_yelp_get

Summary

This function has not been documented yet.

Source Code

function gdfi_yelp_get($page_id)
{
// For example, request business with id 'the-waterboy-sacramento'
    $aip_url = "http://api.yelp.com/v2/business/";
    $unsigned_url = $aip_url . $page_id;


    global $wpdb;
    $gdfi_config_yelp = get_option('gdfi_config_yelp');
// Set your keys here
    $consumer_key = $gdfi_config_yelp['key'];
    $consumer_secret = $gdfi_config_yelp['key_secret'];
    $token = $gdfi_config_yelp['token'];
    $token_secret = $gdfi_config_yelp['token_secret'];

// Token object built using the OAuth library
    $token = new GeodirYelpAuthToken($token, $token_secret);

// Consumer object built using the OAuth library
    $consumer = new GeodirYelpAuthConsumer($consumer_key, $consumer_secret);

// Yelp uses HMAC SHA1 encoding
    $signature_method = new GeodirYelpAuthSignatureMethod_HMAC_SHA1();

// Build OAuth Request using the OAuth PHP library. Uses the consumer and token object created above.
    $oauthrequest = GeodirYelpAuthRequest::from_consumer_and_token($consumer, $token, 'GET', $unsigned_url);

// Sign the request
    $oauthrequest->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); // Yelp response
    curl_close($ch);

// Handle Yelp response data
    $response = json_decode($data);//print_r($response);
    if ($response && !isset($response->error)) {
        $response->is_yelp = true;
        $country_name = $wpdb->get_var($wpdb->prepare("SELECT Country FROM " . GEODIR_COUNTRIES_TABLE . " WHERE ISO2=%s", array($response->location->country_code)));
        $response->location->country = $country_name;
        $response->image_url = str_replace("ms.jpg", "l.jpg", $response->image_url);
    } elseif (is_object($response)) {
        $response->is_yelp = true;
    }
// Print it for debugging
    return json_encode($response);
}