Skip to content

Instantly share code, notes, and snippets.

@ptz0n

ptz0n/gist:1246066

Last active Feb 9, 2017
Embed
What would you like to do?
Trafikverket exponerar API
<!DOCTYPE html>
<html><head><meta charset="UTF-8" /><title>Trafikverket exponerar API</title></head><body><pre><?php
/**
* @author Erik Eng <erik@eng.se>
*
* @url http://tagtider.net/blogg/tjanster/trafikverket-exponerar-api/
*
*/
$headers = array(
'Content-type:text/xml; charset=UTF-8',
'User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/534.50 (KHTML, like Gecko) Version/5.1 Safari/534.50',
);
$trafiklagen = '<ORIONML version="1.0">
<REQUEST plugin="WOW" version="" locale="SE_sv">
<PLUGINML
table="LpvTrafiklagen"
filter="TrafikplatsNamn = \'Stockholm C\' AND (AnnonseradTidpunktAvgang > datetime(\'now\',\'localtime\',\'-15 minute\') AND (datetime(\'now\',\'+14 hour\') > AnnonseradTidpunktAvgang))"
orderby=""
selectcolumns="" />
</REQUEST>
</ORIONML>';
$messages = '<ORIONML version="1.0">
<REQUEST plugin="KartDB" locale="SE_sv">
<PLUGINML table="Messages" />
</REQUEST>
</ORIONML>';
$group = '<ORIONML version="1.0">
<REQUEST plugin="WOW" version="" locale="SE_sv">
<PLUGINML
table="LpvTrafiklagen"
filter="TagGrupp = \'2e20211f-8ccf-490b-9bb5-e3b112591d25\'" orderby="TagGrupp,TagGruppOrdning"
selectcolumns="" />
</REQUEST>
</ORIONML>';
$stations = '<ORIONML version=\'1.0\'>
<REQUEST plugin=\'KartDB\'>
<PLUGINML table=\'Stations\'></PLUGINML>
</REQUEST>
</ORIONML>';
$train = '<ORIONML version="1.0">
<REQUEST plugin="WOW" version="" locale="SE_sv">
<PLUGINML
table="LpvTrafiklagen"
filter="AnnonseratTagId=\'584\'" orderby="Utgangsdatum DESC, TagGrupp"
selectcolumns="DISTINCT TagGrupp" />
</REQUEST>
</ORIONML>';
$ch = curl_init();
// set URL and other appropriate options
$options = array(
CURLOPT_URL => 'http://trafikinfo.trafikverket.se/litcore/orion/orionproxy.ashx',
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_HTTPHEADER => $headers,
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => $trafiklagen
);
curl_setopt_array($ch, $options);
echo $data = curl_exec($ch);
print_r(json_decode($data));
print_r(curl_getinfo($ch));
curl_close($ch);
?></body></html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment