Exemplo n.º 1
0
        public async Task <RTPIData> GetRTPIForStop(string stopId)
        {
            RTPIData data = new RTPIData {
                Error = "Found no arrivals for stop"
            };

            var encodedStopId = WebUtility.UrlEncode(stopId);
            // TODO: pull this out of code
            string address = $"https://data.dublinked.ie/cgi-bin/rtpi/realtimebusinformation?stopid={encodedStopId}&format=json";

            var response = await _http.GetData(address);

            var rawJson = await response.Content.ReadAsStringAsync();

            try
            {
                var jsonResults = JObject.Parse(rawJson);
                data = TransformServiceData(jsonResults);
            }
            catch (JsonException)
            {
                // Failed to parse the JSON, give the user an error.
            }

            return(data);
        }
Exemplo n.º 2
0
        public async Task <RTPIData> GetRTPIForStop(string stopId)
        {
            RTPIData data = new RTPIData {
                Error = "Found no arrivals for stop"
            };

            var encodedStopId = WebUtility.UrlEncode(stopId);
            // TODO: pull this out of code
            string address = $"http://luasforecasts.rpa.ie/xml/get.ashx?action=forecast&encrypt=false&stop={encodedStopId}";

            var response = await _http.GetData(address);

            using (Stream rawResponse = await response.Content.ReadAsStreamAsync())
            {
                var xml = new XmlSerializer(typeof(LUASStopInfo));
                try
                {
                    var LUASData = xml.Deserialize(rawResponse) as LUASStopInfo;
                    if (LUASData != null)
                    {
                        data = TransformServiceData(LUASData);
                    }
                }
                catch (InvalidOperationException)
                {
                    // The LUAS API returns a plain string error message if it can not find the stop
                    // this will break the deserialization, just fall trough with error set above.
                }
            }

            return(data);
        }