public async Task Test() { var api = new Api(); var startElysee = new GeoLocation { Longitude = 2.316749, Latitude = 48.870663 }; var endTourEiffel = new GeoLocation { Longitude = 2.294555, Latitude = 48.858465 }; var arrivalTime = DateTimeOffset.Now.AddDays(3); var networks = new List<Network> {Network.Bus}; var s = await api.GetItinerary(startElysee, endTourEiffel, null, arrivalTime, networks, JourneyPreference.MinWait, false, false, false); Assert.False(string.IsNullOrWhiteSpace(s)); }
public async Task<string> GetItinerary(GeoLocation start, GeoLocation end, DateTimeOffset? leaveTime, DateTimeOffset? arrivalTime, List<Network> prefNetworks, JourneyPreference? preference, bool withTrafficEvents, bool withText, bool withDetails) { var queryStringParametters = new List<KeyValuePair<string, string>> { new KeyValuePair<string, string>("startPointLon", start.Longitude.ToString()), new KeyValuePair<string, string>("startPointLat", start.Latitude.ToString()), new KeyValuePair<string, string>("keyapp", "FvChCBnSetVgTKk324rO"), new KeyValuePair<string, string>("engine", "ratp"), new KeyValuePair<string, string>("endPointLon", end.Longitude.ToString()), new KeyValuePair<string, string>("endPointLat", end.Latitude.ToString()), new KeyValuePair<string, string>("cmd", "getItinerary") }; if (withTrafficEvents) { queryStringParametters.Add(new KeyValuePair<string, string>("withTrafficEvents", "true")); } if (withText) { queryStringParametters.Add(new KeyValuePair<string, string>("withText", "true")); } if (withDetails) { queryStringParametters.Add(new KeyValuePair<string, string>("withDetails", "true")); } if (leaveTime == null && arrivalTime == null) { queryStringParametters.Add(new KeyValuePair<string, string>("leaveTime", ToApix(DateTimeOffset.Now))); } else if (leaveTime != null && arrivalTime != null) { throw new ArgumentException("Can't set both leaveTime and arrivalTime"); } else if (leaveTime != null) { queryStringParametters.Add(new KeyValuePair<string, string>("leaveTime", ToApix(leaveTime.Value))); } else { queryStringParametters.Add(new KeyValuePair<string, string>("arrivalTime", ToApix(arrivalTime.Value))); } if (preference != null) { queryStringParametters.Add(new KeyValuePair<string, string>("prefJourney", preference.ToString().PascalCaseToCamelCase())); } if (prefNetworks != null && prefNetworks.Any()) { var prefNetworksStr = string.Join(",", prefNetworks.Select(s => s.ToString().ToLower())); queryStringParametters.Add(new KeyValuePair<string, string>("prefNetworks", prefNetworksStr)); } HttpContent queryString = new FormUrlEncodedContent(queryStringParametters); var response = await _httpClient.GetAsync(new Uri("/APIX?" + await queryString.ReadAsStringAsync(), UriKind.Relative)); return await response.Content.ReadAsStringAsync(); }