Skip to content

Commit 2fd2695

Browse files
committed
Hostname lookup support added
1 parent e26b6db commit 2fd2695

File tree

12 files changed

+32
-6
lines changed

12 files changed

+32
-6
lines changed

.gitignore

100644100755
File mode changed.

README.md

100644100755
File mode changed.

pom.xml

100644100755
File mode changed.

src/main/java/io/ipgeolocation/api/Geolocation.java

100644100755
Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
public class Geolocation {
88
private Integer status;
99
private String message;
10+
private String domain;
1011
private String ip;
12+
private String hostname;
1113
private String continentCode;
1214
private String continentName;
1315
private String countryCode2;
@@ -39,7 +41,9 @@ public class Geolocation {
3941
if(this.status != 200 || message != null) {
4042
this.message = message;
4143
} else {
44+
this.domain = (String) json.get("domain");
4245
this.ip = (String) json.get("ip");
46+
this.hostname = (String) json.get("hostname");
4347
this.continentCode = (String) json.get("continent_code");
4448
this.continentName = (String) json.get("continent_name");
4549
this.countryCode2 = (String) json.get("country_code2");
@@ -81,10 +85,18 @@ public String getMessage() {
8185
return message;
8286
}
8387

88+
public String getDomain() {
89+
return domain;
90+
}
91+
8492
public String getIPAddress() {
8593
return ip;
8694
}
8795

96+
public String getHostname() {
97+
return hostname;
98+
}
99+
88100
public String getContinentCode() {
89101
return continentCode;
90102
}
@@ -190,6 +202,6 @@ public String toString() {
190202
timezoneString = timezone.toString();
191203
}
192204

193-
return String.format("ip: '%s' \ncontinent_code: '%s' \ncontinent_name: '%s' \ncountry_code2: '%s' \ncountry_code3: '%s' \ncountry_name: '%s' \ncountry_capital: '%s \nstate_prov: '%s' \ndistrict: '%s' \ncity: '%s' \nzipcode: '%s' \nlatitude: '%s' \nlongitude: '%s' \nis_eu: '%s' \ncalling_code: '%s' \ncountry_tld: '%s' \nlanguages: '%s' \ncountry_flag: '%s' \nisp: '%s' \nconnection_type: '%s' \norganization: '%s' \ngeoname_id: '%s' \ncurrency: {\n%s\n} \ntime_zone: {\n%s\n}\n", ip, continentCode, continentName, countryCode2, countryCode3, countryName, countryCapital, stateProvince, district, city, zipCode, latitude, longitude, isEU, callingCode, countryTLD, languages, countryFlag, isp, connectionType, organization, geonameID, currencyString, timezoneString);
205+
return String.format("domain: '%s' \nip: '%s' \nhostname: '%s' \ncontinent_code: '%s' \ncontinent_name: '%s' \ncountry_code2: '%s' \ncountry_code3: '%s' \ncountry_name: '%s' \ncountry_capital: '%s \nstate_prov: '%s' \ndistrict: '%s' \ncity: '%s' \nzipcode: '%s' \nlatitude: '%s' \nlongitude: '%s' \nis_eu: '%s' \ncalling_code: '%s' \ncountry_tld: '%s' \nlanguages: '%s' \ncountry_flag: '%s' \nisp: '%s' \nconnection_type: '%s' \norganization: '%s' \ngeoname_id: '%s' \ncurrency: {\n%s\n} \ntime_zone: {\n%s\n}\n", domain, ip, hostname, continentCode, continentName, countryCode2, countryCode3, countryName, countryCapital, stateProvince, district, city, zipCode, latitude, longitude, isEU, callingCode, countryTLD, languages, countryFlag, isp, connectionType, organization, geonameID, currencyString, timezoneString);
194206
}
195-
}
207+
}

src/main/java/io/ipgeolocation/api/GeolocationCurrency.java

100644100755
File mode changed.

src/main/java/io/ipgeolocation/api/GeolocationParams.java

100644100755
Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ public class GeolocationParams {
66
private String ip;
77
private String fields;
88
private String lang;
9+
private boolean includeHostname;
910
private String[] ips;
1011

1112
public GeolocationParams() {
1213
this.ip = "";
1314
this.fields = "";
1415
this.lang = "en";
16+
this.includeHostname = false;
1517
this.ips = new String[0];
1618
}
1719

@@ -20,23 +22,31 @@ public void setIPAddress(String ip) {
2022
}
2123

2224
public String getIPAddress() {
23-
return this.ip;
25+
return ip;
2426
}
2527

2628
public void setFields(String fields) {
2729
this.fields = Strings.nullToEmpty(fields);
2830
}
2931

3032
public String getFields() {
31-
return this.fields;
33+
return fields;
3234
}
3335

3436
public void setLang(String lang) {
3537
this.lang = lang;
3638
}
3739

3840
public String getLang() {
39-
return this.lang;
41+
return lang;
42+
}
43+
44+
public void setIncludeHostname(boolean includeHostname) {
45+
this.includeHostname = includeHostname;
46+
}
47+
48+
public boolean isIncludeHostname() {
49+
return includeHostname;
4050
}
4151

4252
public void setIPAddresses(String[] ips) throws IllegalArgumentException {
@@ -48,7 +58,7 @@ public void setIPAddresses(String[] ips) throws IllegalArgumentException {
4858
}
4959

5060
public String[] getIPAddresses() {
51-
return this.ips;
61+
return ips;
5262
}
5363

5464
@Override

src/main/java/io/ipgeolocation/api/GeolocationTimezone.java

100644100755
File mode changed.

src/main/java/io/ipgeolocation/api/IPGeolocationAPI.java

100644100755
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ private String buildGeolocationUrlParams(GeolocationParams params) {
5555
urlParams.append(params.getFields());
5656
}
5757

58+
if(params.isIncludeHostname()) {
59+
urlParams.append("&include=hostname");
60+
}
61+
5862
if(!isNullOrEmpty(params.getLang())) {
5963
urlParams.append("&lang=");
6064
urlParams.append(params.getLang());

src/main/java/io/ipgeolocation/api/Strings.java

100644100755
File mode changed.

src/main/java/io/ipgeolocation/api/Timezone.java

100644100755
File mode changed.

0 commit comments

Comments
 (0)