Skip to content

Commit 26eccbb

Browse files
committed
Add Priority field to providers to allow more clear ordering.
1 parent 53654a4 commit 26eccbb

File tree

5 files changed

+20
-14
lines changed

5 files changed

+20
-14
lines changed

Kapok.IpToGeolocation.Tests/Kapok.IpToGeolocation.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
<PackageLicenseExpression>AGPL-3.0-only</PackageLicenseExpression>
1111

12-
<Version>0.0.4-alpha</Version>
12+
<Version>0.0.5-alpha</Version>
1313

1414
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
1515

Kapok.IpToGeolocation.Tests/appsettings.json

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,40 @@
11
{
22
"IpToGeolocation": {
33
"Providers": {
4-
"IpRegistry": {
5-
"Name": "IpRegistry",
6-
"UrlPattern": "https://api.ipregistry.co/{IpAddress}?key={Key}",
7-
"PrivateKey": "",
8-
"Disabled": true
9-
},
104
"AbstractApi": {
115
"Name": "AbstractApi",
126
"UrlPattern": "https://ipgeolocation.abstractapi.com/v1/?api_key={Key}&ip_address={IpAddress}",
137
"PrivateKey": "",
14-
"Disabled": false
8+
"Disabled": false,
9+
"Priority": 10
10+
},
11+
"IpRegistry": {
12+
"Name": "IpRegistry",
13+
"UrlPattern": "https://api.ipregistry.co/{IpAddress}?key={Key}",
14+
"PrivateKey": "",
15+
"Disabled": true,
16+
"Priority": 20
1517
},
1618
"IpStack": {
1719
"Name": "IpStack",
1820
"UrlPattern": "http://api.ipstack.com/{IpAddress}?access_key={Key}",
1921
"PrivateKey": "",
20-
"Disabled": true
22+
"Disabled": true,
23+
"Priority": 30
2124
},
2225
"IpGeolocationIo": {
2326
"Name": "IpGeolocationIo",
2427
"UrlPattern": "https://api.ipgeolocation.io/ipgeo?apiKey={Key}&ip={IpAddress}",
2528
"PrivateKey": "",
26-
"Disabled": true
29+
"Disabled": true,
30+
"Priority": 40
2731
},
2832
"IpGeolocationApi": {
2933
"Name": "IpGeolocationApi",
3034
"UrlPattern": "https://api.ipgeolocationapi.com/geolocate/{IpAddress}",
3135
"PrivateKey": null,
32-
"Disabled": false
36+
"Disabled": false,
37+
"Priority": 50
3338
}
3439
}
3540
}

Kapok.IpToGeolocation/GeolocationProviderConfiguration.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public class GeolocationProviderConfiguration
1010

1111
public Provider Name { get; set; }
1212
public bool Disabled { get; set; }
13+
public int Priority { get; set; }
1314
public string? UrlPattern { get; set; }
1415
public string? PrivateKey { get; set; }
1516
public string? UrlPatternWithPrivateKey

Kapok.IpToGeolocation/GeolocationService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ public GeolocationService(IConfiguration configuration, HttpClient httpClient, I
4242
}
4343

4444
private GeolocationProviderConfiguration[] GetProviders()
45-
=> _configuration.Providers.Values.Where(p => !p.Disabled).ToArray();
45+
=> _configuration.Providers.Values.Where(p => !p.Disabled).OrderBy(p => p.Priority).ToArray();
4646

4747
private GeolocationProviderConfiguration[] GetProviders(IEnumerable<Provider> providers)
48-
=> _configuration.Providers.Values.Where(p => !p.Disabled && providers.Contains(p.Name)).ToArray();
48+
=> _configuration.Providers.Values.Where(p => !p.Disabled && providers.Contains(p.Name)).OrderBy(p => p.Priority).ToArray();
4949

5050
/// <summary>
5151
/// Create the <see cref="HttpRequestMessage"/> for the first valid and available provider.

Kapok.IpToGeolocation/Kapok.IpToGeolocation.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
88
<Copyright>Ⓒ Kapok Marketing, Inc. All Rights Reserved.</Copyright>
99
<PackageLicenseExpression>AGPL-3.0-only</PackageLicenseExpression>
10-
<Version>0.0.4-alpha</Version>
10+
<Version>0.0.5-alpha</Version>
1111
<PackageProjectUrl>https://github.com/kapokmarketing/IpToGeolocation</PackageProjectUrl>
1212
<RepositoryUrl>https://github.com/kapokmarketing/IpToGeolocation</RepositoryUrl>
1313
<Authors>Kapok Marketing, Inc., Jake Braun</Authors>

0 commit comments

Comments
 (0)