34 lines
1022 B
C#
34 lines
1022 B
C#
using System.Net.Http;
|
|
using System.Net.Http.Json;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace TIAM.Services.Server
|
|
{
|
|
public class SmartyStreetsService
|
|
{
|
|
private readonly HttpClient _httpClient;
|
|
private readonly string _authId = "YourAuthID";
|
|
private readonly string _authToken = "YourAuthToken";
|
|
|
|
public SmartyStreetsService(HttpClient httpClient)
|
|
{
|
|
_httpClient = httpClient;
|
|
}
|
|
|
|
public async Task<string> ValidateAddressAsync(string address)
|
|
{
|
|
var requestUri = $"https://us-street.api.smartystreets.com/street-address?auth-id={_authId}&auth-token={_authToken}&street={address}";
|
|
|
|
var response = await _httpClient.GetFromJsonAsync<SmartyStreetsResponse[]>(requestUri);
|
|
|
|
return response?.Length > 0 ? "Valid address" : "Invalid address";
|
|
}
|
|
}
|
|
|
|
public class SmartyStreetsResponse
|
|
{
|
|
public string DeliveryLine1 { get; set; }
|
|
public string LastLine { get; set; }
|
|
}
|
|
}
|