public async Task <StateVectorResponse> GetOwnStateVectorsAsync(int?time = null, string icao24 = null, int[] serials = null, Credentials credentials = null, BoundingBox boundingBox = null, CancellationToken cancellationToken = default) { var url = $"{apiUrl}/states/own"; var httpRequestMessageBuilder = new HttpRequestMessageBuilder(url, HttpMethod.Get); if (time.HasValue) { httpRequestMessageBuilder.AddQueryString("time", time.Value.ToString(CultureInfo.InvariantCulture)); } if (icao24 != null) { httpRequestMessageBuilder.AddQueryString("icao24", icao24); } if (serials != null) { foreach (var serial in serials) { httpRequestMessageBuilder.AddQueryString("serials", serial.ToString(CultureInfo.InvariantCulture)); } } if (boundingBox != null) { httpRequestMessageBuilder.AddQueryString("lamin", boundingBox.LaMin.ToString(CultureInfo.InvariantCulture)); httpRequestMessageBuilder.AddQueryString("lomin", boundingBox.LoMin.ToString(CultureInfo.InvariantCulture)); httpRequestMessageBuilder.AddQueryString("lamax", boundingBox.LaMax.ToString(CultureInfo.InvariantCulture)); httpRequestMessageBuilder.AddQueryString("lomax", boundingBox.LoMax.ToString(CultureInfo.InvariantCulture)); } var httpRequestMessage = httpRequestMessageBuilder.Build(); if (credentials != null) { SetBasicAuthHeader(httpRequestMessage, credentials); } using (var httpResponse = await httpClient .SendAsync(httpRequestMessage, HttpCompletionOption.ResponseHeadersRead, cancellationToken) .ConfigureAwait(false)) { httpResponse.EnsureSuccessStatusCode(); using (var stream = await httpResponse.Content .ReadAsStreamAsync(cancellationToken) .ConfigureAwait(false)) { return(await StateVectorResponseParser.ParseAsync(stream)); } } }
public async Task <string> Search(string q, string lang = default, int?limit = default, float?lat = default, float?lon = default, int?location_bias_scale = default, string bbox = default, string[] osm_tags = default, CancellationToken cancellationToken = default) { var url = $"{applicationOptions.Photon?.ApiUrl}"; var httpRequestMessageBuilder = new HttpRequestMessageBuilder(url, HttpMethod.Get); httpRequestMessageBuilder.AddQueryString("q", q); if (!string.IsNullOrWhiteSpace(lang)) { httpRequestMessageBuilder.AddQueryString("lang", lang); } if (limit.HasValue) { httpRequestMessageBuilder.AddQueryString("limit", limit.Value.ToString(CultureInfo.InvariantCulture)); } if (lat.HasValue) { httpRequestMessageBuilder.AddQueryString("lat", lat.Value.ToString(CultureInfo.InvariantCulture)); } if (lon.HasValue) { httpRequestMessageBuilder.AddQueryString("lon", lon.Value.ToString(CultureInfo.InvariantCulture)); } if (location_bias_scale.HasValue) { httpRequestMessageBuilder.AddQueryString("location_bias_scale", location_bias_scale.Value.ToString(CultureInfo.InvariantCulture)); } if (!string.IsNullOrWhiteSpace(bbox)) { httpRequestMessageBuilder.AddQueryString("bbox", bbox); } if (osm_tags != null) { foreach (var osm_tag in osm_tags) { httpRequestMessageBuilder.AddQueryString("osm_tag", osm_tag); } } var httpRequestMessage = httpRequestMessageBuilder.Build(); var httpResponse = await httpClient .SendAsync(httpRequestMessage) .ConfigureAwait(false); if (!httpResponse.IsSuccessStatusCode) { var statusCode = httpResponse.StatusCode; var reason = httpResponse.ReasonPhrase; throw new Exception($"API Request failed with Status Code {statusCode} and Reason {reason}. For additional information, see the HttpResponseMessage in this Exception."); } return(await httpResponse.Content .ReadAsStringAsync() .ConfigureAwait(false)); }