public Route GetRoute(Location source, Location destination) { var json = _jsonDownloader.DownloadRouteJson(source, destination); var route = new Route() { Source = source, Destination = destination }; return PopulateRoute(route, json); }
private Route PopulateRoute(Route route, dynamic json) { if (json["status"] == "NOT_FOUND") throw new Exception(string.Format( "Either the source address ({0}) or the destination address ({1}) does not exist", route.Source.Address, route.Destination.Address)); var path = json["routes"][0]["legs"][0]; route.Distance = path["distance"]["text"]; route.Duration = path["duration"]["text"]; route.DurationValue = path["duration"]["value"]; return route; }
private IEnumerable<string> GetColumns(Route route) { return new[] { route.Source.Name, route.Destination.Name, route.Duration, route.Distance }; }
private string FormatRoute(Route route) { return GetColumns(route).Zip(_columnWidths, (str, len) => str.PadRight(len + 4, ' ')) .Aggregate(new StringBuilder(), (running, current) => running.Append(current)) .ToString(); }