Skip to content

Commit b9d056b

Browse files
Merge pull request #5 from zeeshan-tfw/master
Added User-Agent API and location parameter
2 parents 2151f5c + 49b49d7 commit b9d056b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1184
-1222
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
# Directories
22
.vscode/
3-
IPGeolocation/obj/
3+
IPGeolocation/obj/
4+
.fake
5+
.ionide

.idea/.gitignore

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/ip-geolocation-api-dotnet-sdk.iml

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

IPGeolocation/Geolocation.cs

Lines changed: 122 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
namespace IPGeolocation
55
{
66
public class Geolocation
7-
{
8-
private int status;
9-
private String message;
7+
{
8+
private String domain;
109
private String ipAddress;
10+
private String hostname;
1111
private String continentCode;
1212
private String continentName;
1313
private String countryCode2;
@@ -20,125 +20,162 @@ public class Geolocation
2020
private String zipCode;
2121
private String latitude;
2222
private String longitude;
23-
private Boolean isEU;
23+
private Boolean isEU;
2424
private String callingCode;
2525
private String countryTLD;
2626
private String languages;
2727
private String countryFlag;
2828
private String isp;
2929
private String connectionType;
3030
private String organization;
31-
private String geonameID;
3231
private String asn;
32+
private String geonameID;
3333
private GeolocationCurrency currency;
3434
private GeolocationTimezone timezone;
35+
private GeolocationSecurity security;
36+
private UserAgent userAgentDetail;
3537

3638
public Geolocation(JObject json)
3739
{
38-
this.status = json.GetValue("status").ToObject<int>();
40+
JToken token = json.GetValue("domain");
41+
this.domain = token != null ? token.ToObject<String>() : null;
3942

40-
JToken token = json.GetValue("message");
41-
String message = token != null ? token.ToObject<String>() : null;
43+
token = json.GetValue("ip");
44+
this.ipAddress = token != null ? token.ToObject<String>() : null;
4245

43-
if (this.status != 200 || message != null)
44-
{
45-
this.message = message;
46-
}
47-
else
48-
{
49-
token = json.GetValue("ip");
50-
this.ipAddress = token != null ? token.ToObject<String>() : null;
46+
token = json.GetValue("hostname");
47+
this.hostname = token != null ? token.ToObject<String>() : null;
5148

52-
token = json.GetValue("continent_code");
53-
this.continentCode = token != null ? token.ToObject<String>() : null;
49+
token = json.GetValue("continent_code");
50+
this.continentCode = token != null ? token.ToObject<String>() : null;
5451

55-
token = json.GetValue("continent_name");
56-
this.continentName = token != null ? token.ToObject<String>() : null;
52+
token = json.GetValue("continent_name");
53+
this.continentName = token != null ? token.ToObject<String>() : null;
5754

58-
token = json.GetValue("country_code2");
59-
this.countryCode2 = token != null ? token.ToObject<String>() : null;
55+
token = json.GetValue("country_code2");
56+
this.countryCode2 = token != null ? token.ToObject<String>() : null;
6057

61-
token = json.GetValue("country_code3");
62-
this.countryCode3 = token != null ? token.ToObject<String>() : null;
58+
token = json.GetValue("country_code3");
59+
this.countryCode3 = token != null ? token.ToObject<String>() : null;
6360

64-
token = json.GetValue("country_name");
65-
this.countryName = token != null ? token.ToObject<String>() : null;
61+
token = json.GetValue("country_name");
62+
this.countryName = token != null ? token.ToObject<String>() : null;
6663

67-
token = json.GetValue("country_capital");
68-
this.countryCapital = token != null ? token.ToObject<String>() : null;
64+
token = json.GetValue("country_capital");
65+
this.countryCapital = token != null ? token.ToObject<String>() : null;
6966

70-
token = json.GetValue("state_prov");
71-
this.stateProvince = token != null ? token.ToObject<String>() : null;
67+
token = json.GetValue("state_prov");
68+
this.stateProvince = token != null ? token.ToObject<String>() : null;
7269

73-
token = json.GetValue("district");
74-
this.district = token != null ? token.ToObject<String>() : null;
70+
token = json.GetValue("district");
71+
this.district = token != null ? token.ToObject<String>() : null;
7572

76-
token = json.GetValue("city");
77-
this.city = token != null ? token.ToObject<String>() : null;
73+
token = json.GetValue("city");
74+
this.city = token != null ? token.ToObject<String>() : null;
7875

79-
token = json.GetValue("zipcode");
80-
this.zipCode = token != null ? token.ToObject<String>() : null;
76+
token = json.GetValue("zipcode");
77+
this.zipCode = token != null ? token.ToObject<String>() : null;
8178

82-
token = json.GetValue("latitude");
83-
this.latitude = token != null ? token.ToObject<String>() : null;
79+
token = json.GetValue("latitude");
80+
this.latitude = token != null ? token.ToObject<String>() : null;
8481

85-
token = json.GetValue("longitude");
86-
this.longitude = token != null ? token.ToObject<String>() : null;
82+
token = json.GetValue("longitude");
83+
this.longitude = token != null ? token.ToObject<String>() : null;
8784

88-
token = json.GetValue("is_eu");
89-
this.isEU = token != null ? token.ToObject<Boolean>() : false;
85+
token = json.GetValue("is_eu");
86+
this.isEU = token != null ? token.ToObject<Boolean>() : false;
9087

91-
token = json.GetValue("calling_code");
92-
this.callingCode = token != null ? token.ToObject<String>() : null;
88+
token = json.GetValue("calling_code");
89+
this.callingCode = token != null ? token.ToObject<String>() : null;
9390

94-
token = json.GetValue("country_tld");
95-
this.countryTLD = token != null ? token.ToObject<String>() : null;
91+
token = json.GetValue("country_tld");
92+
this.countryTLD = token != null ? token.ToObject<String>() : null;
9693

97-
token = json.GetValue("languages");
98-
this.languages = token != null ? token.ToObject<String>() : null;
94+
token = json.GetValue("languages");
95+
this.languages = token != null ? token.ToObject<String>() : null;
9996

100-
token = json.GetValue("country_flag");
101-
this.countryFlag = token != null ? token.ToObject<String>() : null;
97+
token = json.GetValue("country_flag");
98+
this.countryFlag = token != null ? token.ToObject<String>() : null;
10299

103-
token = json.GetValue("isp");
104-
this.isp = token != null ? token.ToObject<String>() : null;
100+
token = json.GetValue("isp");
101+
this.isp = token != null ? token.ToObject<String>() : null;
105102

106-
token = json.GetValue("connection_type");
107-
this.connectionType = token != null ? token.ToObject<String>() : null;
103+
token = json.GetValue("connection_type");
104+
this.connectionType = token != null ? token.ToObject<String>() : null;
108105

109-
token = json.GetValue("organization");
110-
this.organization = token != null ? token.ToObject<String>() : null;
106+
token = json.GetValue("organization");
107+
this.organization = token != null ? token.ToObject<String>() : null;
111108

112-
token = json.GetValue("geoname_id");
113-
this.geonameID = token != null ? token.ToObject<String>() : null;
109+
token = json.GetValue("geoname_id");
110+
this.geonameID = token != null ? token.ToObject<String>() : null;
114111

115-
token = json.GetValue("asn");
116-
this.asn = token != null ? token.ToObject<String>() : null;
117-
118-
token = json.GetValue("currency");
119-
JObject currencyJson = token != null ? token.ToObject<JObject>() : null;
112+
token = json.GetValue("asn");
113+
this.asn = token != null ? token.ToObject<String>() : null;
114+
115+
token = json.GetValue("currency");
116+
JObject currencyJson = token != null ? token.ToObject<JObject>() : null;
117+
118+
if (currencyJson == null)
119+
{
120+
this.currency = new GeolocationCurrency();
121+
}
122+
else
123+
{
120124
this.currency = new GeolocationCurrency(currencyJson);
125+
}
126+
127+
token = json.GetValue("time_zone");
121128

122-
token = json.GetValue("time_zone");
123-
JObject timezoneJson = token != null ? token.ToObject<JObject>() : null;
129+
JObject timezoneJson = token != null ? token.ToObject<JObject>() : null;
130+
131+
if (timezoneJson == null)
132+
{
133+
this.timezone = new GeolocationTimezone();
134+
}
135+
else
136+
{
124137
this.timezone = new GeolocationTimezone(timezoneJson);
125138
}
126-
}
127139

128-
public int GetStatus()
129-
{
130-
return status;
140+
token = json.GetValue("security");
141+
142+
JObject securityJson = token != null ? token.ToObject<JObject>() : null;
143+
144+
if (securityJson == null)
145+
{
146+
this.security = new GeolocationSecurity();
147+
}
148+
else
149+
{
150+
this.security = new GeolocationSecurity(securityJson);
151+
}
152+
153+
token = json.GetValue("user_agent");
154+
155+
JObject userAgentJson = token != null ? token.ToObject<JObject>() : null;
156+
157+
if (userAgentJson == null)
158+
{
159+
this.userAgentDetail = new UserAgent();
160+
}
161+
else
162+
{
163+
this.userAgentDetail = new UserAgent(userAgentJson);
164+
}
131165
}
132166

133-
public String GetMessage()
167+
public String GetDomain()
134168
{
135-
return message;
169+
return domain;
136170
}
137-
138171
public String GetIPAddress()
139172
{
140173
return ipAddress;
141174
}
175+
public String GetHostname()
176+
{
177+
return hostname;
178+
}
142179

143180
public String GetContinentCode()
144181
{
@@ -198,8 +235,8 @@ public String GetLongitude()
198235
{
199236
return longitude;
200237
}
201-
202-
public Boolean GetIsEU()
238+
239+
public Boolean IsEU()
203240
{
204241
return isEU;
205242
}
@@ -252,10 +289,20 @@ public String GetASN()
252289
{
253290
return asn;
254291
}
255-
292+
256293
public GeolocationCurrency GetCurrency()
257294
{
258295
return currency;
259296
}
297+
298+
public GeolocationSecurity GetSecurity()
299+
{
300+
return security;
301+
}
302+
303+
public UserAgent GetUserAgent()
304+
{
305+
return userAgentDetail;
306+
}
260307
}
261308
}

IPGeolocation/GeolocationCurrency.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,14 @@
44
namespace IPGeolocation
55
{
66
public class GeolocationCurrency
7-
{
7+
{
88
private String name;
99
private String code;
10+
private String symbol;
11+
12+
public GeolocationCurrency()
13+
{
14+
}
1015

1116
public GeolocationCurrency(JObject json)
1217
{
@@ -15,6 +20,9 @@ public GeolocationCurrency(JObject json)
1520

1621
token = json.GetValue("code");
1722
this.code = token != null ? token.ToObject<String>() : null;
23+
24+
token = json.GetValue("symbol");
25+
this.symbol = token != null ? token.ToObject<String>() : null;
1826
}
1927

2028
public String GetName()
@@ -26,5 +34,11 @@ public String GetCode()
2634
{
2735
return code;
2836
}
37+
38+
public String GetSymbol()
39+
{
40+
return symbol;
41+
}
42+
2943
}
3044
}

0 commit comments

Comments
 (0)