Skip to content

Instantly share code, notes, and snippets.

@FranckErnewein
Created September 3, 2015 16:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FranckErnewein/d43c81e33a281d5ad136 to your computer and use it in GitHub Desktop.
Save FranckErnewein/d43c81e33a281d5ad136 to your computer and use it in GitHub Desktop.
send data to lightstream API in PHP
<?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