private static StopAndBus OutputBus(StopPoint stop) { var downloadedJson = DownloadFile(stop.id); var busList = Bus.FromJson(downloadedJson); var firstFiveBus = busList.OrderBy(x => x.expectedArrival).Take(5); return(new StopAndBus(stop.commonName, firstFiveBus.ToList())); }
public static List <Bus> GetBuses(StopPoint stopPoint) { var response = ApiRequest("https://api.tfl.gov.uk", "StopPoint/" + stopPoint.naptanId + "/Arrivals?app_id=d55bb861&app_key=a5c391d03e8a461105ee02f229bdb8c7"); var arrivals = JsonConvert.DeserializeObject <List <Bus> >(response).OrderBy(x => x.timeToStation).Take(5).ToList(); return(arrivals); }
public static ApiReturn MakeApiCalls(string input) { try { ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; var postCodeInfo = DownloadPostcode(input); var longLat = LongLat.FromJson(postCodeInfo); var busStopJson = DownloadBusStops(longLat); var stopPoints = StopPoint.FromJson(busStopJson); var firstTwoStopPoints = stopPoints.OrderBy(x => x.distance).Take(2).ToList(); return(new ApiReturn(OutputAllBus(firstTwoStopPoints))); } catch (InvalidPostcodeException) { return(new ApiReturn()); } catch (Exception e) { return(new ApiReturn(e)); } }
public StopInfo(StopPoint stopPoint) { Station = stopPoint.commonName; Arrivals = ApiHelper.GetArrivalsList(stopPoint); }
public static IEnumerable <BusEntry> GetArrivalsList(StopPoint stopPoint) { return(ApiGet <BusEntry>("https://api.tfl.gov.uk/", $"StopPoint/{stopPoint.id}/Arrivals") .OrderBy(busEntry => busEntry.expectedArrival) .Take(5)); }
public static string GetArrivalsString(StopPoint stopPoint) { return(string.Join("\n", GetArrivalsList(stopPoint))); }