diff --git a/src/Spoleto.AddressResolver.Dadata/DadataAddressResolver.cs b/src/Spoleto.AddressResolver.Dadata/DadataAddressResolver.cs
index 7ef4d45..4e4e546 100644
--- a/src/Spoleto.AddressResolver.Dadata/DadataAddressResolver.cs
+++ b/src/Spoleto.AddressResolver.Dadata/DadataAddressResolver.cs
@@ -7,7 +7,8 @@ namespace Spoleto.AddressResolver.Dadata
public class DadataAddressResolver : IAddressResolver
{
private readonly DadataOptions _options;
- private readonly SuggestClientAsync _dadataClient;
+ private readonly CleanClientAsync _cleanDadataClient;
+ private readonly SuggestClientAsync _suggestDadataClient;
public DadataAddressResolver(DadataOptions options)
{
@@ -19,7 +20,8 @@ public DadataAddressResolver(DadataOptions options)
_options = options;
- _dadataClient = new SuggestClientAsync(_options.Token);
+ _cleanDadataClient = new CleanClientAsync(options.Token, options.Secret);
+ _suggestDadataClient = new SuggestClientAsync(_options.Token);
}
///
@@ -32,8 +34,9 @@ public async Task ResolveLocationAsync(string originalLocationA
if (String.IsNullOrEmpty(originalLocationAddress))
throw new ArgumentNullException(nameof(originalLocationAddress));
- var fullAddress = await GetFullAddressAsync(originalLocationAddress, countryIsoCode).ConfigureAwait(false);
- if (fullAddress?.data is not Address dadataAddress)
+ var fullAddress = await _cleanDadataClient.Clean(originalLocationAddress).ConfigureAwait(false);
+
+ if (fullAddress is not Address dadataAddress)
throw new ArgumentException($"Could not find the full address for <{originalLocationAddress}>.", nameof(fullAddress));
var location = ConvertToAddressLocation(originalLocationAddress, dadataAddress);
@@ -86,7 +89,7 @@ private async Task>> GetAddressAsync(string searchText
}
- var response = await _dadataClient.SuggestAddress(request).ConfigureAwait(false);
+ var response = await _suggestDadataClient.SuggestAddress(request).ConfigureAwait(false);
return response?.suggestions;
}
diff --git a/src/Spoleto.AddressResolver.Dadata/Options/DadataOptions.cs b/src/Spoleto.AddressResolver.Dadata/Options/DadataOptions.cs
index bad3fbf..8afd2e9 100644
--- a/src/Spoleto.AddressResolver.Dadata/Options/DadataOptions.cs
+++ b/src/Spoleto.AddressResolver.Dadata/Options/DadataOptions.cs
@@ -10,14 +10,22 @@ public record DadataOptions
///
public string Token { get; set; }
+ ///
+ /// Gets or sets the Dadata secret key.
+ ///
+ public string Secret { get; set; }
+
///
/// Checks that all the settings within the options are configured properly.
///
- /// Thrown when is null.
+ /// Thrown when or are null.
public void Validate()
{
if (String.IsNullOrEmpty(Token))
throw new ArgumentNullException(nameof(Token));
+
+ if (String.IsNullOrEmpty(Secret))
+ throw new ArgumentNullException(nameof(Secret));
}
}
}