Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor startupgenome_get.php to consume Startup Genome API using CURL. #29

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 21 additions & 32 deletions represent-map/startupgenome_get.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,29 @@
$interval_info = mysql_fetch_assoc($interval_query);
if((time()-$interval_info[sg_lastupdate]) > $sg_frequency || $_GET['override'] == "true") {

// connect to startup genome API
if(strpos($_SERVER['SERVER_NAME'],'.local') !== false) {
$config = array('api_url' => 'startupgenome.com.local/api/');
} else {
$config = array('api_url' => 'www.startupgenome.com/api');
}
//grab the location configuration. We can probably remove this and just use $sg_location directly.
$config['search_location'] = $sg_location;
$http = Http::connect($config['api_url'],false,'http');
try {
$r = $http->doGet("login/{$sg_auth_code}");
$j = json_decode($r,1);
$http->setHeaders(array("AUTH_CODE: {$sg_auth_code}"));
$user = $j['response'];
} catch(Exception $e) {
$error = "<div class='error'>".print_r($e)."</div>";
exit();
}

// set the header required by the API.
$headers = array("AUTH-CODE: {$sg_auth_code}");

// connect to startup genome API using cURL
$curl = curl_init();

// get organizations
try {
$r = $http->doGet("/organizations{$config['search_location']}");
$places_arr = json_decode($r, 1);
// Set some options
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLINFO_HEADER_OUT, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_URL, "http://startupgenome.com/api/organizations{$config['search_location']}");

// Send the request & save response to $resp
$resp = curl_exec($curl);

// Close request to clear up some resources
curl_close($curl);

$places_arr = json_decode($resp, 1);

// update organizations in local db
$org_array = Array();
foreach ($places_arr['response'] as $key => $place) {
Expand Down Expand Up @@ -111,22 +111,11 @@

// update settings table with the timestamp for this sync
mysql_query("UPDATE settings SET sg_lastupdate='".time()."'");

// show errors if there were any issues
} catch (Exception $e) {
echo "<div class='error'>";
print_r($e);
echo "</div>";
exit();
}



}
}





?>
?>