Skip to content
master
Switch branches/tags
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 

README.md

NationalRail

.NET Core wrapper to query the National Rail APIs for historical and live information.

Installation

To use NationalRail in your C# project, you can either download the NationalRail C# .NET libraries directly from the Github repository or, if you have the NuGet package manager installed, you can grab them automatically.

PM> Install-Package NationalRail

Once you have the NationalRail libraries properly referenced in your project, you can include calls to them in your code.

Add the following namespaces to use the library:

using NationalRail;
using NationalRail.Models.LiveDepartureBoard;
using NationalRail.Models.HistoricalServicePerformance;

Dependencies

Seperate accounts are need to access the live data and historical data. An overview of the National Rail data sources can be found here.

Usage

The below code can be used in a .NET Core project, a test project is also included in the GitHub solution.

    public class Program
    {
        public static void Main(string[] args)
        {
            // Historical Data
            HistoricalServicePerformanceClient historicalClient = new HistoricalServicePerformanceClient("{EMAILADDRESS}", "{PASSWORD}");

            ServiceMetric metric = new ServiceMetric();

            metric.FromLocation = "BTN";
            metric.ToLocation = "VIC";
            metric.FromTime = "0700";
            metric.ToTime = "0800";
            metric.FromDate = "2016-07-01";
            metric.ToDate = "2016-07-01";
            metric.Days = "WEEKDAY";

            ServiceMetricResponse historicalResponse = historicalClient.GetServiceMetrics(metric).Result;

            foreach (NationalRail.Models.HistoricalServicePerformance.Service service in historicalResponse.Services)
            {
                foreach(string rid in service.ServiceAttributesMetrics.RIDs)
                {
                    NationalRail.Models.HistoricalServicePerformance.ServiceDetailsResponse details = historicalClient.GetServiceDetails(new ServiceDetailsRID(rid)).Result;
                }
            }

            // Live Data
            string token = "{TOKEN}";

            LiveDepartureBoardClient liveClient = new LiveDepartureBoardClient(token);

            NextDepartureRequest.Body liveBody = new NextDepartureRequest.Body();

            liveBody.GetNextDeparturesRequest.Crs = "LDS";
            liveBody.GetNextDeparturesRequest.FilterList.Crs.Add("DON");
            liveBody.GetNextDeparturesRequest.TimeOffset = 0;
            liveBody.GetNextDeparturesRequest.TimeWindow = 120;

            NextDepartureResponse.Envelope liveResponse = liveClient.GetNextDeparture(liveBody).Result;
        }
    }

References

A description of the historical service API can be found here and a description of the live API here.

About

A .NET Core class library for accessing the various National Rail APIs

Resources

License

Releases

No releases published

Packages

No packages published

Languages