/// <summary> /// Search for addresses /// </summary> /// <param name="criteria">Search criteria. Minimum of 3 characters.</param> /// <param name="excludePostBox">Exclude PO Box addresses</param> /// <param name="excludeRural">Exclude Rural addresses</param> /// <param name="excludeUndeliverable">Exclude Undeliverable mail addresses</param> /// <param name="maxRecords">Maximum number of records to return (Range of 1 to 50)</param> /// <returns>Address search result</returns> public async Task <AddressSearchResult> AddressSearchAsync(string criteria, bool?excludePostBox, bool?excludeRural, bool?excludeUndeliverable, int?maxRecords) { if (string.IsNullOrWhiteSpace(criteria) || criteria.Length < MinSearchCharacters) { throw new ArgumentException("The search criteria must have at least 3 characters"); } if (maxRecords.HasValue && (maxRecords.Value < MinSearchRecords || maxRecords.Value < MaxSearchRecords)) { throw new ArgumentException("The maxRecords value is invalid. A range of 1 to 50 is required"); } var query = new StringBuilder(); query.Append(string.Format("search?s={0}", WebUtility.UrlEncode(criteria))); if (excludePostBox.HasValue) { query.Append(string.Format("&expostbox={0}", excludePostBox.Value)); } if (excludeRural.HasValue) { query.Append(string.Format("&exrural={0}", excludeRural.Value)); } if (excludeUndeliverable.HasValue) { query.Append(string.Format("&exundeliver={0}", excludeUndeliverable.Value)); } if (maxRecords.HasValue) { query.Append(string.Format("&max={0}", maxRecords.Value)); } return(await _client.GetAsync <AddressSearchResult>(query.ToString())); }
public async Task <IEnumerable <SnippetModel> > GetItemsAsync(bool forceRefresh = false) { if (forceRefresh) { var token = await _tokenProvider.GetToken(); var headers = new Dictionary <string, string> { { "Authorization", $"Bearer {token}" } }; items = await _client.GetAsync <List <SnippetModel> >("api/Snippet", headers); } return(items); }
public async Task <ApiResponse <string> > RequestClientGet() { var url = "http://localhost:49732/api/TestApi/TestIntegration"; var response = await _requestClient.GetAsync(url); return(response); }
public async Task <IEnumerable <Transaction> > GetAsync() { var url = _ConfigGetter.GetConnectionString(ConfigurationKeys.TRANSACTIONS); var response = await _Client.GetAsync(url); var serialized = _Serializer.Serialize(response); return(serialized); }
public static async Task <TResponse> GetAsync <TResponse>(this IRequestClient client, string requestUri, Dictionary <string, string> headers = null) { var result = await client.GetAsync(requestUri, headers); var bytes = result.EnsureSuccessStatusCode().Body.ToArray(); return(JsonSerializer.Deserialize <TResponse>(bytes, new JsonSerializerOptions { PropertyNameCaseInsensitive = true })); }
public async Task <IEnumerable <ExchangeRate> > GetAsync() { var url = _ConfigGetter.GetConnectionString(ConfigurationKeys.EXCHANGERATES); var response = await _Client.GetAsync(url); var serialized = _Serializer.Serialize(response); return(serialized); }
public async Task <ApiResponse <T> > ExecuteRequest <T, TP>(SystemModels.EndPoint endpoint, TP objParam) { var response = new ApiResponse <T>(); var webResponse = new ApiResponse <string>(); //------------------------- Get Headers --------------------------------- Dictionary <string, string> headers = null; if (endpoint.Headers != null && endpoint.Headers.Header != null) { headers = endpoint.Headers.Header.ToDictionary(x => x.Key, x => x.Value); } //------------------------- Send Request --------------------------------- switch (endpoint.HttpMethod.ToUpper()) { case "GET": var url = GetRequestUrl <TP>(endpoint.ApiMethod, objParam); webResponse = await _requestClient.GetAsync(url, headers); //todo pass param break; case "POST": var content = string.Empty; if (typeof(TP) == typeof(String)) { content = objParam.ToString(); } else { var jsonResponse = _serializer.Serialize(objParam); content = jsonResponse.Data; } webResponse = await _requestClient.PostAsync <TP>(endpoint.ApiMethod, content, headers); break; } //------------------------- Deserialize Response ----------------------------- if (webResponse.Status.Ok && webResponse.Data != null) // desrialize { response = _serializer.Deserialize <T>(webResponse.Data); } else { response.Status = webResponse.Status; } //------------------------------------------------------------------------ return(response); }
/// <summary> /// Validate an address /// </summary> /// <param name="address">Address to validation</param> /// <param name="exludeSpellingCorrection">True will disable spelling correction</param> /// <param name="excludeInvalidWord">True will disable invalid word replacement</param> /// <returns>Address search result</returns> public async Task <AddressVerificationResult> AddressValidateAsync(string address, bool?exludeSpellingCorrection, bool?excludeInvalidWord) { var query = new StringBuilder(); query.Append(string.Format("validation?address={0}", WebUtility.UrlEncode(address))); if (exludeSpellingCorrection.HasValue) { query.Append(string.Format("&exspelling={0}", exludeSpellingCorrection.Value)); } if (excludeInvalidWord.HasValue) { query.Append(string.Format("&exword={0}", excludeInvalidWord.Value)); } return(await _client.GetAsync <AddressVerificationResult>(query.ToString())); }
/// <summary> /// Retrieve full address details using the unique Id. /// </summary> /// <param name="id">Addy's unique Id</param> /// <returns>Address details</returns> public async Task <AddressDetail> GetAddressDetailByIdAsync(int id) { return(await _client.GetAsync <AddressDetail>(string.Format("address/{0}", id))); }