4
4
namespace IPGeolocation
5
5
{
6
6
public class Geolocation
7
- {
8
- private int status ;
9
- private String message ;
7
+ {
8
+ private String domain ;
10
9
private String ipAddress ;
10
+ private String hostname ;
11
11
private String continentCode ;
12
12
private String continentName ;
13
13
private String countryCode2 ;
@@ -20,125 +20,162 @@ public class Geolocation
20
20
private String zipCode ;
21
21
private String latitude ;
22
22
private String longitude ;
23
- private Boolean isEU ;
23
+ private Boolean isEU ;
24
24
private String callingCode ;
25
25
private String countryTLD ;
26
26
private String languages ;
27
27
private String countryFlag ;
28
28
private String isp ;
29
29
private String connectionType ;
30
30
private String organization ;
31
- private String geonameID ;
32
31
private String asn ;
32
+ private String geonameID ;
33
33
private GeolocationCurrency currency ;
34
34
private GeolocationTimezone timezone ;
35
+ private GeolocationSecurity security ;
36
+ private UserAgent userAgentDetail ;
35
37
36
38
public Geolocation ( JObject json )
37
39
{
38
- this . status = json . GetValue ( "status" ) . ToObject < int > ( ) ;
40
+ JToken token = json . GetValue ( "domain" ) ;
41
+ this . domain = token != null ? token . ToObject < String > ( ) : null ;
39
42
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 ;
42
45
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 ;
51
48
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 ;
54
51
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 ;
57
54
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 ;
60
57
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 ;
63
60
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 ;
66
63
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 ;
69
66
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 ;
72
69
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 ;
75
72
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 ;
78
75
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 ;
81
78
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 ;
84
81
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 ;
87
84
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 ;
90
87
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 ;
93
90
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 ;
96
93
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 ;
99
96
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 ;
102
99
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 ;
105
102
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 ;
108
105
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 ;
111
108
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 ;
114
111
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
+ {
120
124
this . currency = new GeolocationCurrency ( currencyJson ) ;
125
+ }
126
+
127
+ token = json . GetValue ( "time_zone" ) ;
121
128
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
+ {
124
137
this . timezone = new GeolocationTimezone ( timezoneJson ) ;
125
138
}
126
- }
127
139
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
+ }
131
165
}
132
166
133
- public String GetMessage ( )
167
+ public String GetDomain ( )
134
168
{
135
- return message ;
169
+ return domain ;
136
170
}
137
-
138
171
public String GetIPAddress ( )
139
172
{
140
173
return ipAddress ;
141
174
}
175
+ public String GetHostname ( )
176
+ {
177
+ return hostname ;
178
+ }
142
179
143
180
public String GetContinentCode ( )
144
181
{
@@ -198,8 +235,8 @@ public String GetLongitude()
198
235
{
199
236
return longitude ;
200
237
}
201
-
202
- public Boolean GetIsEU ( )
238
+
239
+ public Boolean IsEU ( )
203
240
{
204
241
return isEU ;
205
242
}
@@ -252,10 +289,20 @@ public String GetASN()
252
289
{
253
290
return asn ;
254
291
}
255
-
292
+
256
293
public GeolocationCurrency GetCurrency ( )
257
294
{
258
295
return currency ;
259
296
}
297
+
298
+ public GeolocationSecurity GetSecurity ( )
299
+ {
300
+ return security ;
301
+ }
302
+
303
+ public UserAgent GetUserAgent ( )
304
+ {
305
+ return userAgentDetail ;
306
+ }
260
307
}
261
308
}
0 commit comments