Skip to content

Commit 10f4f83

Browse files
committed
Rename IPInfo to IPLookupResult for clarity
IPLookupResult better describes what the model represents (the result of an IP lookup) rather than the generic "IPInfo". https://claude.ai/code/session_01GqyDyB2zrpxr1ZVw8vFVg3
1 parent ec4f5a3 commit 10f4f83

9 files changed

Lines changed: 40 additions & 40 deletions

File tree

.github/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ All usage examples you can find on `samples` folder.
4848
var client = new IPDataClient("API_KEY");
4949

5050
// Get IP data from my IP
51-
var myIPInfo = await client.Lookup();
52-
Console.WriteLine($"Country name for {myIPInfo.Ip} is {myIPInfo.CountryName}");
51+
var myIp = await client.Lookup();
52+
Console.WriteLine($"Country name for {myIp.Ip} is {myIp.CountryName}");
5353

5454
// Get IP data from IP
5555
var ipInfo = await client.Lookup("8.8.8.8");
@@ -153,7 +153,7 @@ v3.0.0 renames all public types to follow [.NET naming conventions](https://lear
153153
|---|---|
154154
| `IpDataClient` | `IPDataClient` |
155155
| `IIpDataClient` | `IIPDataClient` |
156-
| `IpInfo` | `IPInfo` |
156+
| `IpInfo` | `IPLookupResult` |
157157

158158
### Namespace change
159159

samples/IPData.Lookup/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ public static async Task Main()
1111
var client = new IPDataClient("API_KEY");
1212

1313
// Get IP data from my IP
14-
var myIPInfo = await client.Lookup();
15-
Console.WriteLine($"Country name for {myIPInfo.Ip} is {myIPInfo.CountryName}");
14+
var myIPLookupResult = await client.Lookup();
15+
Console.WriteLine($"Country name for {myIPLookupResult.Ip} is {myIPLookupResult.CountryName}");
1616

1717
// Get IP data from IP
1818
var ipInfo = await client.Lookup("8.8.8.8");

src/IPData/Helpers/ApiUrls.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ public Uri Get(string apiKey, string ip, CultureInfo culture)
2727
return ApplyApiKey(new Uri(_base, relative), apiKey);
2828
}
2929

30-
public Uri Get(string apiKey, string ip, Expression<Func<IPInfo, object>> expression)
30+
public Uri Get(string apiKey, string ip, Expression<Func<IPLookupResult, object>> expression)
3131
{
32-
var field = IPInfo.FieldName(expression);
32+
var field = IPLookupResult.FieldName(expression);
3333
return ApplyApiKey(new Uri(_base, $"{ip}/{field}"), apiKey);
3434
}
3535

36-
public Uri Get(string apiKey, string ip, params Expression<Func<IPInfo, object>>[] expressions)
36+
public Uri Get(string apiKey, string ip, params Expression<Func<IPLookupResult, object>>[] expressions)
3737
{
38-
var fields = string.Join(",", expressions.Select(IPInfo.FieldName));
38+
var fields = string.Join(",", expressions.Select(IPLookupResult.FieldName));
3939
return ApplyApiKey(new Uri(_base, $"{ip}").AddParameter(nameof(fields), fields), apiKey);
4040
}
4141

src/IPData/Helpers/Extensions/ExpressionExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace IPData.Helpers.Extensions
66
{
77
internal static class ExpressionExtensions
88
{
9-
public static string PropertyName(this Expression<Func<IPInfo, object>> expression)
9+
public static string PropertyName(this Expression<Func<IPLookupResult, object>> expression)
1010
{
1111
switch (expression.Body)
1212
{

src/IPData/IIPDataClient.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public interface IIPDataClient
116116
Task<Threat> Threat(string ip);
117117

118118
/// <summary>Fetch IP info for your IP.</summary>
119-
/// <returns>The IP info <see cref="Models.IPInfo">.</returns>
119+
/// <returns>The IP info <see cref="Models.IPLookupResult">.</returns>
120120
/// <exception cref="Exceptions.BadRequestException">
121121
/// Thrown when IP address is private or invalid.
122122
/// </exception>
@@ -129,11 +129,11 @@ public interface IIPDataClient
129129
/// <exception cref="Exceptions.ApiException">
130130
/// Thrown when unexpected case occurred.
131131
/// </exception>
132-
Task<IPInfo> Lookup();
132+
Task<IPLookupResult> Lookup();
133133

134134
/// <summary>Fetch localized IP info for your IP.</summary>
135135
/// <param name="culture">The culture info.</param>
136-
/// <returns>Localized IP info <see cref="IPInfo"/></returns>
136+
/// <returns>Localized IP info <see cref="IPLookupResult"/></returns>
137137
/// <exception cref="Exceptions.BadRequestException">
138138
/// Thrown when IP address is private or invalid.
139139
/// </exception>
@@ -151,11 +151,11 @@ public interface IIPDataClient
151151
/// Lookup(CultureInfo.GetCultureInfo("zh-CN"));
152152
/// </code>
153153
/// </example>
154-
Task<IPInfo> Lookup(CultureInfo culture);
154+
Task<IPLookupResult> Lookup(CultureInfo culture);
155155

156156
/// <summary>Fetch IP info for few IPs.</summary>
157157
/// <param name="ips">The list of IPv4 addresses.</param>
158-
/// <returns>The list of IP info <see cref="IPInfo"/>.</returns>
158+
/// <returns>The list of IP info <see cref="IPLookupResult"/>.</returns>
159159
/// <exception cref="Exceptions.BadRequestException">
160160
/// Thrown when IP address is private or invalid.
161161
/// </exception>
@@ -168,7 +168,7 @@ public interface IIPDataClient
168168
/// <exception cref="Exceptions.ApiException">
169169
/// Thrown when unexpected case occurred.
170170
/// </exception>
171-
Task<IEnumerable<IPInfo>> Lookup(IReadOnlyCollection<string> ips);
171+
Task<IEnumerable<IPLookupResult>> Lookup(IReadOnlyCollection<string> ips);
172172

173173
/// <summary>Fetch IP info for IPv4 address.</summary>
174174
/// <param name="ip">The IPv4 Address.</param>
@@ -185,12 +185,12 @@ public interface IIPDataClient
185185
/// <exception cref="Exceptions.ApiException">
186186
/// Thrown when unexpected case occurred.
187187
/// </exception>
188-
Task<IPInfo> Lookup(string ip);
188+
Task<IPLookupResult> Lookup(string ip);
189189

190190
/// <summary>Fetch localized IP info for IPv4 address.</summary>
191191
/// <param name="ip">The IPv4 address.</param>
192192
/// <param name="culture">The culture info.</param>
193-
/// <returns>Localized IP info <see cref="IPInfo"/>.</returns>
193+
/// <returns>Localized IP info <see cref="IPLookupResult"/>.</returns>
194194
/// <exception cref="Exceptions.BadRequestException">
195195
/// Thrown when IP address is private or invalid.
196196
/// </exception>
@@ -208,7 +208,7 @@ public interface IIPDataClient
208208
/// Lookup("8.8.8.8", CultureInfo.GetCultureInfo("zh-CN"));
209209
/// </code>
210210
/// </example>
211-
Task<IPInfo> Lookup(string ip, CultureInfo culture);
211+
Task<IPLookupResult> Lookup(string ip, CultureInfo culture);
212212

213213
/// <summary>Fetch single IP info fields from IPv4 address.</summary>
214214
/// <param name="ip">The IPv4 address.</param>
@@ -231,7 +231,7 @@ public interface IIPDataClient
231231
/// Lookup("8.8.8.8", x => x.CountryName);
232232
/// </code>
233233
/// </example>
234-
Task<string> Lookup(string ip, Expression<Func<IPInfo, object>> fieldSelector);
234+
Task<string> Lookup(string ip, Expression<Func<IPLookupResult, object>> fieldSelector);
235235

236236
/// <summary>Fetch multiple IP info fields from IPv4 address.</summary>
237237
/// <param name="ip">The IPv4 address.</param>
@@ -254,6 +254,6 @@ public interface IIPDataClient
254254
/// Lookup("8.8.8.8", x => x.CountryName, x => x.City);
255255
/// </code>
256256
/// </example>
257-
Task<IPInfo> Lookup(string ip, params Expression<Func<IPInfo, object>>[] fieldSelectors);
257+
Task<IPLookupResult> Lookup(string ip, params Expression<Func<IPLookupResult, object>>[] fieldSelectors);
258258
}
259259
}

src/IPData/IPDataClient.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -87,50 +87,50 @@ public IPDataClient(string apiKey, IHttpClient httpClient, Uri baseUrl)
8787
}
8888

8989
/// <inheritdoc />
90-
public Task<IPInfo> Lookup() =>
90+
public Task<IPLookupResult> Lookup() =>
9191
Lookup(CultureInfo.InvariantCulture);
9292

9393
/// <inheritdoc />
94-
public async Task<IPInfo> Lookup(CultureInfo culture)
94+
public async Task<IPLookupResult> Lookup(CultureInfo culture)
9595
{
9696
var url = _apiUrls.Get(ApiKey, culture);
9797
var request = new HttpRequestMessage(HttpMethod.Get, url);
9898
var json = await SendRequestAsync(_httpClient, request).ConfigureAwait(false);
99-
return _serializer.Deserialize<IPInfo>(json);
99+
return _serializer.Deserialize<IPLookupResult>(json);
100100
}
101101

102102
/// <inheritdoc />
103-
public Task<IPInfo> Lookup(string ip) =>
103+
public Task<IPLookupResult> Lookup(string ip) =>
104104
Lookup(ip, CultureInfo.InvariantCulture);
105105

106106
/// <inheritdoc />
107-
public async Task<IPInfo> Lookup(string ip, CultureInfo culture)
107+
public async Task<IPLookupResult> Lookup(string ip, CultureInfo culture)
108108
{
109109
var url = _apiUrls.Get(ApiKey, ip, culture);
110110
var request = new HttpRequestMessage(HttpMethod.Get, url);
111111
var json = await SendRequestAsync(_httpClient, request).ConfigureAwait(false);
112-
return _serializer.Deserialize<IPInfo>(json);
112+
return _serializer.Deserialize<IPLookupResult>(json);
113113
}
114114

115115
/// <inheritdoc />
116-
public Task<string> Lookup(string ip, Expression<Func<IPInfo, object>> fieldSelector)
116+
public Task<string> Lookup(string ip, Expression<Func<IPLookupResult, object>> fieldSelector)
117117
{
118118
var url = _apiUrls.Get(ApiKey, ip, fieldSelector);
119119
var request = new HttpRequestMessage(HttpMethod.Get, url);
120120
return SendRequestAsync(_httpClient, request);
121121
}
122122

123123
/// <inheritdoc />
124-
public async Task<IPInfo> Lookup(string ip, params Expression<Func<IPInfo, object>>[] fieldSelectors)
124+
public async Task<IPLookupResult> Lookup(string ip, params Expression<Func<IPLookupResult, object>>[] fieldSelectors)
125125
{
126126
var url = _apiUrls.Get(ApiKey, ip, fieldSelectors);
127127
var request = new HttpRequestMessage(HttpMethod.Get, url);
128128
var json = await SendRequestAsync(_httpClient, request).ConfigureAwait(false);
129-
return _serializer.Deserialize<IPInfo>(json);
129+
return _serializer.Deserialize<IPLookupResult>(json);
130130
}
131131

132132
/// <inheritdoc />
133-
public async Task<IEnumerable<IPInfo>> Lookup(IReadOnlyCollection<string> ips)
133+
public async Task<IEnumerable<IPLookupResult>> Lookup(IReadOnlyCollection<string> ips)
134134
{
135135
var url = _apiUrls.Bulk(ApiKey);
136136
var request = new HttpRequestMessage(HttpMethod.Post, url)
@@ -139,7 +139,7 @@ public async Task<IEnumerable<IPInfo>> Lookup(IReadOnlyCollection<string> ips)
139139
};
140140

141141
var json = await SendRequestAsync(_httpClient, request).ConfigureAwait(false);
142-
return _serializer.Deserialize<IEnumerable<IPInfo>>(json);
142+
return _serializer.Deserialize<IEnumerable<IPLookupResult>>(json);
143143
}
144144

145145
/// <inheritdoc />
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
namespace IPData.Models
99
{
10-
public class IPInfo
10+
public class IPLookupResult
1111
{
1212
[JsonProperty("ip", NullValueHandling = NullValueHandling.Ignore)]
1313
public string Ip { get; set; }
@@ -90,10 +90,10 @@ public class IPInfo
9090
[JsonProperty("count")]
9191
public int Count { get; set; }
9292

93-
internal static string FieldName(Expression<Func<IPInfo, object>> expression)
93+
internal static string FieldName(Expression<Func<IPLookupResult, object>> expression)
9494
{
9595
var propName = expression.PropertyName();
96-
var attribute = typeof(IPInfo)
96+
var attribute = typeof(IPLookupResult)
9797
.GetProperty(propName)
9898
?.GetCustomAttributes(typeof(JsonPropertyAttribute), false)
9999
.Single() as JsonPropertyAttribute;

test/Unit/IPData.Tests/DataSources/TestDataSource.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public static IEnumerable<object[]> EmptyOrWhitespaceString()
1111
yield return new object[] { null };
1212
}
1313

14-
public static IEnumerable<object[]> IPInfoData()
14+
public static IEnumerable<object[]> IPLookupResultData()
1515
{
1616
yield return new object[] { "{\"ip\":\"91.225.201.108\",\"is_eu\":false,\"city\":\"Lviv\",\"region\":\"L'vivs'ka Oblast'\",\"region_code\":\"46\",\"region_type\":\"oblast\",\"country_name\":\"Ukraine\",\"country_code\":\"UA\",\"continent_name\":\"Europe\",\"continent_code\":\"EU\",\"latitude\":49.8486,\"longitude\":24.0323,\"postal\":\"79000\",\"calling_code\":\"380\",\"flag\":\"https:\\/\\/ipdata.co\\/flags\\/ua.png\",\"emoji_flag\":\"\uD83C\uDDFA\uD83C\uDDE6\",\"emoji_unicode\":\"U+1F1FA U+1F1E6\",\"asn\":{\"asn\":\"AS49824\",\"name\":\"PC \\\"Astra-net\\\"\",\"domain\":\"astra.in.ua\",\"route\":\"91.225.200.0\\/22\",\"type\":\"isp\"},\"company\":{\"name\":\"Astra-net\",\"domain\":\"astra.in.ua\",\"network\":\"91.225.200.0\\/22\",\"type\":\"isp\"},\"carrier\":{\"name\":\"Kyivstar\",\"mcc\":\"255\",\"mnc\":\"03\"},\"languages\":[{\"name\":\"Ukrainian\",\"native\":\"\u0423\u043A\u0440\u0430\u0457\u043D\u0441\u044C\u043A\u0430\",\"code\":\"uk\"}],\"currency\":{\"name\":\"Ukrainian Hryvnia\",\"code\":\"UAH\",\"symbol\":\"\u20B4\",\"native\":\"\u20B4\",\"plural\":\"Ukrainian hryvnias\"},\"time_zone\":{\"name\":\"Europe\\/Kiev\",\"abbr\":\"EET\",\"offset\":\"+0200\",\"is_dst\":false,\"current_time\":\"2020-01-30T23:16:19.129316+02:00\"},\"threat\":{\"is_tor\":false,\"is_icloud_relay\":false,\"is_proxy\":false,\"is_datacenter\":false,\"is_anonymous\":false,\"is_known_attacker\":false,\"is_known_abuser\":false,\"is_threat\":false,\"is_bogon\":false,\"blocklists\":[]},\"status\":200}" };
1717
}

test/Unit/IPData.Tests/Http/Serializer/JsonSerializerTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,18 @@ public class JsonSerializerTests
1111
private readonly JsonSerializer _sut = new JsonSerializer();
1212

1313
[Theory]
14-
[MemberData(nameof(TestDataSource.IPInfoData), MemberType = typeof(TestDataSource))]
15-
public void Deserialize_WhenCalled_ReturnedIPInfo(string json)
14+
[MemberData(nameof(TestDataSource.IPLookupResultData), MemberType = typeof(TestDataSource))]
15+
public void Deserialize_WhenCalled_ReturnedIPLookupResult(string json)
1616
{
1717
// Act
18-
var actual = _sut.Deserialize<IPInfo>(json);
18+
var actual = _sut.Deserialize<IPLookupResult>(json);
1919

2020
// Assert
2121
actual.Should().NotBeNull();
2222
}
2323

2424
[Theory, AutoMoqData]
25-
public void SerializeIPInfo_WhenCalled_ReturnedString(IPInfo ipInfo)
25+
public void SerializeIPLookupResult_WhenCalled_ReturnedString(IPLookupResult ipInfo)
2626
{
2727
// Act
2828
var actual = _sut.Serialize(ipInfo);

0 commit comments

Comments
 (0)