Beispiel #1
0
 private TimetableClient GetTimetableClient()
 {
     var timetableClient = new TimetableClient(
         TestConstants.TimetableDeveloperID,
         TestConstants.TimetableSecurityKey,
         (input, key) =>
         {
             var provider = new HMACSHA1(key);
             var hash = provider.ComputeHash(input);
             return hash;
         });
     return timetableClient;
 }
Beispiel #2
0
        private TimetableClient GetTimetableClient()
        {
            var timetableClient = new TimetableClient(
                TestConstants.TimetableDeveloperID,
                TestConstants.TimetableSecurityKey,
                (input, key) =>
            {
                var provider = new HMACSHA1(key);
                var hash     = provider.ComputeHash(input);
                return(hash);
            });

            return(timetableClient);
        }
        private static PtvJsonObject _GetPtvObject()
        {
            var departureList = new PtvJsonObject();

            //     try
            //     {
            var client = new TimetableClient(
                Settings.PtvDeveloperID,
                Settings.PtvSecurityKey,
                (input, key) =>
            {
                var provider = new HMACSHA1(key);
                var hash     = provider.ComputeHash(input);
                return(hash);
            });

            var searchResults = client.SearchAsync(Settings.PtvStationName).Result;
            var stopResults   = (Stop)searchResults[0];

            var lineResults   = client.SearchLineByModeAsync(Settings.PtvLineName, TransportType.Train).Result;
            var departResults = client.GetBroadNextDeparturesAsync(TransportType.Train, stopResults.StopID, 3).Result;

            departureList.Departures = new List <Departures>();

            // Use for loop here to limit the result amount to 3.
            // In fact alothough I've set the amount limit, PTV API always returns more than 3.
            for (int i = 0; i <= 2; i++)
            {
                var departItem = departResults[i];


                departureList.Departures.Add(new Departures()
                {
                    Direction    = departItem.Platform.Direction.DirectionName,
                    EstTime      = departItem.EstimatedTime.Value.ToLocalTime().ToString("HH:mm"),
                    ScheduleTime = departItem.ScheduledTime.Value.ToLocalTime().ToString("HH:mm"),
                    TimeLeft     = ((int)((departItem.EstimatedTime.Value.ToLocalTime() - DateTime.Now).TotalMinutes)).ToString()
                });
            }
            //      }
            //      catch(Exception error)
            //      {
            //          departureList.HasError = true;
            //          departureList.ErrorMessage = error.Message;
            //      }

            return(departureList);
        }