Skip to content

Commit d672e15

Browse files
committed
added 1 example code for timezone and 3 examples for useragent
Added one example for timezone API for 'timezone with location' and three examples for 'useragent with ua string', 'useragent with ua strings' and 'useragent of IP'
1 parent fe3caeb commit d672e15

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

README.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,77 @@ try {
279279
System.err.println("HTTP status: " + e.getStatus() + " Error: " + e.getMessage());
280280
}
281281
```
282+
```java
283+
// Get time zone information by location (city, country, etc.)
284+
TimezoneParams timezoneParams =
285+
TimezoneParams.builder().withLocation("Syria, Damascus").build();
286+
287+
try {
288+
Timezone tz = ipGeolocationAPI.getTimezone(timezoneParams);
289+
290+
System.out.println("Format 'EEEE, MMMM dd, yyyy HH:mm:ss': " + tz.getDateTimeTxt());
291+
System.out.println("Country: " + tz.getGeo().getCountryName());
292+
} catch (IPGeolocationError e) {
293+
// on unsuccessful lookup or invalid input IPGeolocationError is thrown
294+
System.err.println("HTTP status: " + e.getStatus() + " Error: " + e.getMessage());
295+
}
296+
```
297+
298+
### UserAgent API
299+
```java
300+
// Query/Parse user agent information for Provided the provided string
301+
try {
302+
String uaString = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_2) AppleWebKit/601.3.9 (KHTML, like Gecko) Version/9.0.2 Safari/601.3.9";
303+
UserAgent ua = ipGeolocationAPI.getUserAgent(uaString);
304+
305+
System.out.println("Device name: " + ua.getDevice().getName());
306+
System.out.println("OS name: " + ua.getOperatingSystem().getName());
307+
System.out.println("OS version: " + ua.getOperatingSystem().getVersion());
308+
System.out.println("CPU: " + ua.getDevice().getCpu());
309+
} catch (IPGeolocationError e) {
310+
// on unsuccessful lookup or invalid input IPGeolocationError is thrown
311+
System.err.println("HTTP status: " + e.getStatus() + " Error: " + e.getMessage());
312+
}
313+
```
314+
```java
315+
// Query/Parse user agent information for the provided strings
316+
String[] uaStrings = new String[]
317+
{"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_2) AppleWebKit/601.3.9 (KHTML, like Gecko) Version/9.0.2 Safari/601.3.9",
318+
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.111 Safari/537.36",
319+
"Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.1"};
320+
321+
try {
322+
List<UserAgent> uas = ipGeolocationAPI.getBulkUserAgent(uaStrings);
323+
324+
System.out.println("No. of Requests: " + uas.size());
325+
System.out.println("1st UA's Device name: " + uas.get(0).getDevice().getName());
326+
System.out.println("2nd UA's OS name: " + uas.get(1).getOperatingSystem().getName());
327+
System.out.println("3rd UA's Browser: " + uas.get(2).getName());
328+
} catch (IPGeolocationError e) {
329+
System.err.println("HTTP status: " + e.getStatus() + " Error: " + e.getMessage());
330+
}
331+
```
332+
```java
333+
// Query useragent of the machine IP Address along with Geolocation
334+
GeolocationParams geolocationParams =
335+
GeolocationParams.builder()
336+
.includeUserAgentDetail()
337+
.build();
338+
try {
339+
Geolocation geolocation = ipGeolocationAPI.getGeolocation(geolocationParams);
340+
341+
System.out.println("IP: " + geolocation.getIP());
342+
System.out.println("City: " + geolocation.getCity());
343+
System.out.println("UserAgent OS: " + geolocation.getUserAgent().getOperatingSystem().getName());
344+
System.out.println("UserAgent Browser:" + geolocation.getUserAgent().getName());
345+
System.out.println("UserAgent Device: " + geolocation.getUserAgent().getDevice().getName());
346+
347+
} catch (IPGeolocationError e) {
348+
// on unsuccessful lookup or invalid input IPGeolocationError is thrown
349+
System.err.println("HTTP status: " + e.getStatus() + " Error: " + e.getMessage());
350+
}
351+
```
352+
282353

283354
** IPGeolocation provides geolocation information in the following languages:
284355

0 commit comments

Comments
 (0)