Exemple #1
0
        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()));
        }
Exemple #2
0
        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);
        }
Exemple #3
0
 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));
     }
 }
Exemple #4
0
 public StopInfo(StopPoint stopPoint)
 {
     Station  = stopPoint.commonName;
     Arrivals = ApiHelper.GetArrivalsList(stopPoint);
 }
Exemple #5
0
 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));
 }
Exemple #6
0
 public static string GetArrivalsString(StopPoint stopPoint)
 {
     return(string.Join("\n", GetArrivalsList(stopPoint)));
 }