|
|
@ -0,0 +1,40 @@ |
|
|
|
<?php |
|
|
|
|
|
|
|
class Gtfs { |
|
|
|
private $endpoint; |
|
|
|
private $secret; |
|
|
|
|
|
|
|
public function __construct($endpoint, $secret) { |
|
|
|
$this->endpoint = $endpoint; |
|
|
|
$this->secret = $secret; |
|
|
|
} |
|
|
|
|
|
|
|
public function getStopSchedule($stopId) { |
|
|
|
// TODO: Error handling
|
|
|
|
|
|
|
|
$ch = curl_init(); |
|
|
|
curl_setopt($ch, CURLOPT_URL, |
|
|
|
$this->endpoint . '?stop=' . $stopId . '&agency=1'); |
|
|
|
|
|
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, array( |
|
|
|
'secret: ' . $this->secret |
|
|
|
)); |
|
|
|
|
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
|
|
|
$response = curl_exec($ch); |
|
|
|
curl_close($ch); |
|
|
|
|
|
|
|
// TODO: Error handling
|
|
|
|
$json = json_decode($response); |
|
|
|
|
|
|
|
$tmp_dateTimes = $json; |
|
|
|
|
|
|
|
$dateTime = array(); |
|
|
|
foreach($tmp_dateTimes as $tmp_dateTime) { |
|
|
|
$dateTime[] = strtotime($tmp_dateTime); |
|
|
|
} |
|
|
|
|
|
|
|
return json_encode($dateTime); |
|
|
|
} |
|
|
|
} |
|
|
|
|