Created
May 22, 2014 12:36
-
-
Save Rudis1261/dfd8efada4c327bdc614 to your computer and use it in GitHub Desktop.
GeckoBoard List Example
This file contains 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
<?php | |
# DATA | |
$data_url = "http://rudi.strydom.photography/Portfolio/json/rand"; | |
$get_data = file_get_contents($data_url); | |
# Geckoboard specifics | |
$gb_url = "https://push.geckoboard.com/v1/send/"; | |
$gb_token = ""; | |
$gb_api_key = ""; | |
# Start the data packet | |
$data = array(); | |
# Ensure we have something to work with | |
if (!empty($get_data)) | |
{ | |
# Decode the json stream | |
$json = json_decode($get_data, true); | |
# Ensure that it's value | |
if (!empty($json)) | |
{ | |
# Added a counter | |
$counter = 0; | |
foreach($json as $item) | |
{ | |
# Title | |
$data["data"]["item"][$counter]["title"]["text"] = $item["name"] . " - " . $item["image"]; | |
# Labels | |
//$data["data"]["item"][$counter]["label"]["color"] = "black"; | |
//$data["data"]["item"][$counter]["label"]["name"] = "Awesome"; | |
# Description | |
$data['data']['item'][$counter]['description'] = "ISO: " . $item["iso"] . ", Aperture: " . $item['aperture'] . ", Exposure: " . $item['exposure']; | |
# Count up son | |
$counter++; | |
} | |
} | |
} | |
# Append the api_key | |
$data["api_key"] = $gb_api_key; | |
# Push it to Gecko | |
pushToGecko(json_encode($data), $gb_token); | |
function pushToGecko($data, $token) | |
{ | |
global $gb_url; | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, $gb_url . $token); | |
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); | |
curl_setopt($ch,CURLOPT_POST, 1); | |
curl_setopt($ch,CURLOPT_POSTFIELDS, $data); | |
$result = curl_exec($ch); | |
//echo($result); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment