// GET /{board}/CRS?accessToken=[your token] public async Task <StationBoard> Get([FromUri] StationBoardRequest request) { // Process CRS codes request.Crs = LdbHelper.GetCrsCode(request.Crs, _crsRecords); request.FilterCrs = LdbHelper.GetCrsCode(request.FilterCrs, _crsRecords); var token = LdbHelper.GetDarwinAccessToken(request.AccessToken, _huxleySettings); switch (request.Board) { case Board.Departures: var departures = await _client.GetDepartureBoardAsync(token, request.NumRows, request.Crs, request.FilterCrs, request.FilterType, 0, 0); return(departures.GetStationBoardResult); case Board.Arrivals: var arrivals = await _client.GetArrivalBoardAsync(token, request.NumRows, request.Crs, request.FilterCrs, request.FilterType, 0, 0); return(arrivals.GetStationBoardResult); default: var board = await _client.GetArrivalDepartureBoardAsync(token, request.NumRows, request.Crs, request.FilterCrs, request.FilterType, 0, 0); return(board.GetStationBoardResult); } }
// GET /delays/{crs}/{filtertype}/{filtercrs}/{numrows}/{stds}?accessToken=[your token] public async Task <DelaysResponse> Get([FromUri] StationBoardRequest request) { if (request.AccessToken == null) { throw new HttpResponseException(HttpStatusCode.BadRequest); } if (request.FilterCrs == null) { throw new HttpResponseException(HttpStatusCode.BadRequest); } // Process CRS codes request.Crs = LdbHelper.GetCrsCode(request.Crs, _crsRecords); request.FilterCrs = LdbHelper.GetCrsCode(request.FilterCrs, _crsRecords); List <string> stds; // Parse the list of comma separated STDs if provided (e.g. /btn/to/lon/50/0729,0744,0748) if (!ParseStds(request.Std, out stds)) { return(new DelaysResponse()); } var filterCrs = request.FilterCrs; StationBoard board; ServiceItem[] trainServices; string filterLocationName; var token = LdbHelper.GetDarwinAccessToken(request.AccessToken, _huxleySettings); if (request.FilterCrs.Equals("LON", StringComparison.InvariantCultureIgnoreCase) || request.FilterCrs.Equals("London", StringComparison.InvariantCultureIgnoreCase)) { var response = await _client.GetDepartureBoardAsync(token, request.NumRows, request.Crs, null, request.FilterType, 0, 0).ConfigureAwait(false); board = response.GetStationBoardResult; var londonDepartures = FilterLondonDepartures(board.trainServices, request.FilterType); trainServices = londonDepartures as ServiceItem[] ?? londonDepartures.ToArray(); filterCrs = "LON"; filterLocationName = "London"; } else { var response = await _client.GetDepartureBoardAsync(token, request.NumRows, request.Crs, filterCrs, request.FilterType, 0, 0).ConfigureAwait(false); board = response.GetStationBoardResult; trainServices = board.trainServices ?? new ServiceItem[0]; filterLocationName = board.filterLocationName; } var railReplacement = board.busServices != null && !trainServices.Any() && board.busServices.Any(); var messagesPresent = board.nrccMessages != null && board.nrccMessages.Any(); // If STDs are provided then select only the train(s) matching them if (stds.Count > 0) { trainServices = trainServices.Where(ts => stds.Contains(ts.ScheduledTimeOfDeparture.Replace(":", ""))).ToArray(); } int totalDelayMinutes; // TODO: make delay threshold part of request var delayedTrains = GetDelayedTrains(trainServices, _huxleySettings.DelayMinutesThreshold, out totalDelayMinutes); return(new DelaysResponse { GeneratedAt = board.generatedAt, Crs = board.crs, LocationName = board.locationName, Filtercrs = filterCrs, FilterLocationName = filterLocationName, Delays = delayedTrains.Count > 0 || railReplacement || messagesPresent, TotalTrainsDelayed = delayedTrains.Count, TotalDelayMinutes = totalDelayMinutes, TotalTrains = trainServices.Length, DelayedTrains = delayedTrains, }); }