private function getNationalData($stop) { $stopData = Stop::where('id', '=', $stop)->get(); if (!$stopData->isEmpty()) { $url = 'http://nextbus.mxdata.co.uk/nextbuses/beta'; $date = date("Y-m-d\\TH:i:s\\Z"); $id = rand(100000, 999999); $request = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <Siri version="1.0" xmlns="http://www.siri.org.uk/"> <ServiceRequest> <RequestTimestamp>' . $date . '</RequestTimestamp> <RequestorRef>' . Config::get('traveline.username') . '</RequestorRef> <StopMonitoringRequest version="1.0"> <RequestTimestamp>' . $date . '</RequestTimestamp> <MessageIdentifier>' . $id . '</MessageIdentifier> <MonitoringRef>' . $stop . '</MonitoringRef> </StopMonitoringRequest> </ServiceRequest> </Siri>'; $response = Httpful::post($url)->body($request)->authenticateWith(Config::get('traveline.username'), Config::get('traveline.password'))->sendsXml()->expectsXml()->send(); $timetable = $response->body->ServiceDelivery->StopMonitoringDelivery; $standardTimetable = array(); foreach ($timetable->MonitoredStopVisit as $trip) { if (isset($trip->MonitoredVehicleJourney->MonitoredCall->ExpectedDepartureTime)) { $standardTimetable[] = ['BusName' => (string) $trip->MonitoredVehicleJourney->PublishedLineName, 'BusHeading' => (string) $trip->MonitoredVehicleJourney->DirectionName, 'ArrivalTime' => strtotime((string) $trip->MonitoredVehicleJourney->MonitoredCall->ExpectedDepartureTime)]; } else { $standardTimetable[] = ['BusName' => (string) $trip->MonitoredVehicleJourney->PublishedLineName, 'BusHeading' => (string) $trip->MonitoredVehicleJourney->DirectionName, 'ArrivalTime' => strtotime((string) $trip->MonitoredVehicleJourney->MonitoredCall->AimedDepartureTime)]; } } if (isset($standardTimetable[0]['ArrivalTime'])) { if ($standardTimetable[0]['ArrivalTime'] - time() > 0) { //cover for errors in data or redis gets angry at a negative expiry Redis::setex($stop, $standardTimetable[0]['ArrivalTime'] - time(), json_encode($standardTimetable)); } return $standardTimetable; } else { return FALSE; } } else { return FALSE; } }