Skip to content

Commit dd1d42b

Browse files
committed
README updated according to the updated SDK
1 parent ddf195b commit dd1d42b

File tree

1 file changed

+41
-35
lines changed

1 file changed

+41
-35
lines changed

README.md

Lines changed: 41 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Developers can use this JQuery SDK for software and web projects related to, but
1818

1919
You need a valid 'IPGeolocation API key' to use this SDK. [Sign up](https://ipgeolocation.io/signup) here and get your free API key if you don't have one.
2020

21-
**Note:** Complete documentation to use this SDK is also available at [IP Geolocation API JQuery SDK Documentation](https://ipgeolocation.io/documentation/ip-geolocation-api-jquery-sdk-201809051507).
21+
**Note:** Complete documentation to use this SDK is also available at [IP Geolocation API JQuery SDK Documentation](https://ipgeolocation.io/documentation/ip-geolocation-api-jquery-sdk.html).
2222

2323
## System Requirements
2424

@@ -30,7 +30,7 @@ Internet connection is required to run this component.
3030
Add the following script in your HTML page:
3131

3232
```html
33-
<script src="https://cdn.jsdelivr.net/npm/ip-geolocation-api-jquery-sdk@1.0.6/ipgeolocation.min.js"></script>
33+
<script src="https://cdn.jsdelivr.net/npm/ip-geolocation-api-jquery-sdk@1.0.8/ipgeolocation.min.js"></script>
3434
```
3535

3636
## Geolocation Lookup
@@ -46,32 +46,35 @@ function handleResponse(response) {
4646
}
4747

4848
// Get geolocation for the calling machine's IP address with an API key (optional, if you're using "Request Origin" feature at IP Geolocation API)
49-
getGeolocation(handleResponse, "YOUR_API_KEY");
49+
_ipgeolocation.getGeolocation(handleResponse, "YOUR_API_KEY");
5050

5151
// Don't pass the API key if you're using the "Request Origin" feature at IP Geolocation API
52-
getGeolocation(handleResponse);
52+
_ipgeolocation.getGeolocation(handleResponse);
53+
54+
// Toggle sessionStorage usage to store API response on client-side. (This is very handy as it will help users to avoid making duplicate API calls for a single visitor.)
55+
_ipgeolocation.enableSessionStorage(true);
5356

5457
// Toggle API calls' async behavior. By default, async is true.
55-
setAsync(false)
58+
_ipgeolocation.makeAsyncCallsToAPI(false);
5659

5760
// Get geolocation for an IP address "1.1.1.1"
58-
setIPAddressParameter("1.1.1.1");
59-
getGeolocation(handleResponse, "YOUR_API_KEY");
61+
_ipgeolocation.setIPAddress("1.1.1.1");
62+
_ipgeolocation.getGeolocation(handleResponse, "YOUR_API_KEY");
6063

6164
// Get geolocation for an IP address "1.1.1.1" in Russian language **
62-
setLanguageParameter("ru");
63-
setIPAddressParameter("1.1.1.1");
64-
getGeolocation(handleResponse, "YOUR_API_KEY");
65+
_ipgeolocation.setLanguage("ru");
66+
_ipgeolocation.setIPAddress("1.1.1.1");
67+
_ipgeolocation.getGeolocation(handleResponse, "YOUR_API_KEY");
6568

6669
// Get the specific geolocation fields "country_code2,time_zone,currency" for the calling machine's IP address
67-
setFieldsParameter("geo,time_zone,currency");
68-
getGeolocation(handleResponse, "YOUR_API_KEY");
70+
_ipgeolocation.setFields("geo,time_zone,currency");
71+
_ipgeolocation.getGeolocation(handleResponse, "YOUR_API_KEY");
6972

7073
// Get the specified geolocaiton fields like "country_code2,time_zone,currency" for an IP address "1.1.1.1" and skip the "ip" field in the response
71-
setFieldsParameter("geo,time_zone,currency");
72-
setIPAddressParameter("1.1.1.1");
73-
setExcludesParameter("ip");
74-
getGeolocation(handleResponse, "YOUR_API_KEY");
74+
_ipgeolocation.setFields("geo,time_zone,currency");
75+
_ipgeolocation.setIPAddress("1.1.1.1");
76+
_ipgeolocation.setExcludes("ip");
77+
_ipgeolocation.getGeolocation(handleResponse, "YOUR_API_KEY");
7578
```
7679
## Time Zone API
7780

@@ -85,26 +88,29 @@ function handleResponse(response) {
8588
}
8689

8790
// Get time zone information for the calling machine's IP address with an API key (optional, if you're using "Request Origin" feature at IP Geolocation API)
88-
getTimezone(handleResponse, "YOUR_API_KEY");
91+
_ipgeolocation.getTimezone(handleResponse, "YOUR_API_KEY");
8992

9093
// Don't pass the API key if you're using the "Request Origin" feature at IP Geolocation API
91-
getTimezone(handleResponse);
94+
_ipgeolocation.getTimezone(handleResponse);
95+
96+
// Toggle sessionStorage usage to store API response on client-side. (This is very handy as it will help users to avoid making duplicate API calls for a single visitor.)
97+
_ipgeolocation.enableSessionStorage(true);
9298

9399
// Toggle API calls' async behavior. By default, async is true.
94-
setAsync(false)
100+
_ipgeolocation.makeAsyncCallsToAPI(false);
95101

96102
// Get time zone information for an IP address "1.1.1.1" and geolocation information in Italian language **
97-
setIPAddressParameter("1.1.1.1");
98-
setLanguageParameter("it");
99-
getTimezone(handleResponse, "YOUR_API_KEY");
103+
_ipgeolocation.setIPAddress("1.1.1.1");
104+
_ipgeolocation.setLanguage("it");
105+
_ipgeolocation.getTimezone(handleResponse, "YOUR_API_KEY");
100106

101107
// Get time zone infomration for a time zone "America/New_York"
102-
setTimezoneParameter("America/Los_Angeles");
103-
getTimezone(handleResponse, "YOUR_API_KEY");
108+
_ipgeolocation.setTimeZone("America/Los_Angeles");
109+
_ipgeolocation.getTimezone(handleResponse, "YOUR_API_KEY");
104110

105111
// Get time zone information by coordinates of the location
106-
setCoordinatesParameter("31.4816", "74.3551");
107-
getTimezone(handleResponse, "YOUR_API_KEY");
112+
_ipgeolocation.setCoordinates("31.4816", "74.3551");
113+
_ipgeolocation.getTimezone(handleResponse, "YOUR_API_KEY");
108114
```
109115

110116
## Example
@@ -113,27 +119,27 @@ Here is a sample code to use IP Geolocation API using JQuery SDK:
113119

114120
```javascript
115121
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
116-
<script src="https://cdn.jsdelivr.net/npm/ip-geolocation-api-jquery-sdk@1.0.5/ipgeolocation.min.js"></script>
122+
<script src="https://cdn.jsdelivr.net/npm/ip-geolocation-api-jquery-sdk@1.0.8/ipgeolocation.min.js"></script>
117123

118124
<script>
125+
// On call to IPGeolocation API on each page during a user's visit, API response will be served from sessionStorage after the first page.
126+
127+
_ipgeolocation.enableSessionStorage(true);
128+
119129
var ip = sessionStorage.getItem("ip");
120130
var country_name = sessionStorage.getItem("country_name");
121131
var country_code2 = sessionStorage.getItem("country_code2");
122132

123133
if (!ip || !country_name || !country_code2) {
124-
setAsync(false);
125-
setFieldsParameter("country_name,country_code2");
126-
getGeolocation(handleGeolocationResponse, "YOUR_API_KEY");
134+
_ipgeolocation.makeAsyncCallsToAPI(false);
135+
_ipgeolocation.setFields("country_name,country_code2");
136+
_ipgeolocation.getGeolocation(handleResponse, "YOUR_API_KEY");
127137
}
128138

129-
function handleGeolocationResponse(json) {
139+
function handleResponse(json) {
130140
ip = json.ip;
131141
country_name = json.country_name;
132142
country_code2 = json.country_code2;
133-
134-
sessionStorage.setItem("ip", ip);
135-
sessionStorage.setItem("country_name", country_name);
136-
sessionStorage.setItem("country_code2", country_code2);
137143
}
138144

139145
$(document).ready(function() {

0 commit comments

Comments
 (0)