Created
September 3, 2015 16:54
-
-
Save FranckErnewein/d43c81e33a281d5ad136 to your computer and use it in GitHub Desktop.
send data to lightstream API in PHP
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
<?php | |
$server = 'test.lightstream.io'; | |
$type = 'ads'; | |
$key = 'b72d053a3722415fab181af70e89a8f2'; | |
$query_string = '?api_key='.$key; | |
$url = 'http://'.$server.'/api/items/'.$type; | |
$generated_id = 'test_' . time(); | |
$data = array( | |
'item' => array( | |
'data' => array( | |
'name' => 'Campagne Name', | |
'sex' => 'M' | |
/* | |
here you can reference all kind of data | |
those data could be use to filter data on the map | |
*/ | |
), | |
/* | |
ID is not required, | |
if the id field is not defined, API will generate one | |
but we recomande to define an ID for each item by yourself | |
*/ | |
'id' => $generated_id, | |
/* | |
geojson is a required field | |
it should respect the geojson specification structure | |
for more information see http://geojson.org/ | |
*/ | |
'geojson' => array( | |
'type' => 'Point', | |
'coordinates' => array( | |
33.377661, //set longitude here | |
-6.447516 //set latitude here | |
) | |
) | |
) | |
); | |
echo json_encode($data); | |
$options = array( | |
'http' => array( | |
'method' => 'POST', | |
'content' => json_encode( $data ), | |
'header'=> "Content-Type: application/json\r\n" . | |
"Accept: application/json\r\n" | |
) | |
); | |
$context = stream_context_create( $options ); | |
$result = file_get_contents( $url . $query_string, false, $context ); | |
echo "to check insert, consult the following address with your browser:\r\n"; | |
echo $url .'/'. $generated_id . $query_string; | |
echo "\r\n"; | |
// display the buffer in terminal | |
// remove this function when script run in apache | |
ob_flush(); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment