Socket
Socket
Sign inDemoInstall

ip-geolocation-api-jquery-sdk

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ip-geolocation-api-jquery-sdk - npm Package Compare versions

Comparing version 1.0.6 to 1.0.7

217

ipgeolocation.js

@@ -1,110 +0,127 @@

var asyncParameter = true;
var ipAddressParameter = "";
var excludesParameter = "";
var fieldsParameter = "";
var langParameter = "";
var tzParameter = "";
var latitudeParameter = "";
var longitudeParameter = "";
var _ipgeolocation = function() {
var useSessionStorage = false;
var asyncCall = true;
var ipAddress = "";
var excludes = "";
var fields = "";
var lang = "en";
var tz = "";
var latitude = "";
var longitude = "";
function setAsync(async = true) {
asyncParameter = async;
}
function setIPAddressParameter (ip = "") {
ipAddressParameter = ip;
}
function setExcludesParameter (excludes = "") {
excludesParameter = excludes;
}
function setFieldsParameter (fields = "") {
fieldsParameter = fields;
}
function setLanguageParameter (lang = "") {
langParameter = lang;
}
function setTimezoneParameter (tz = "") {
tzParameter = tz;
}
function setCoordinatesParameter (latitude = "", longitude = "") {
latitudeParameter = latitude;
longitudeParameter = longitude;
}
function getGeolocation (callback, apiKey = "") {
request("ipgeo", callback, apiKey);
}
function getTimezone (callback, apikey = "") {
request("timezone", callback, apikey);
}
function addUrlParameter(parameters, parameterName, parameterValue) {
if (parameters) {
parameters = parameters.concat("&", parameterName, "=", parameterValue);
} else {
parameters = "?".concat(parameterName, "=", parameterValue);
}
return parameters;
}
function request (subUrl, callback, apiKey = "") {
var urlParameters = "";
if(!subUrl) {
callback(JSON.parse("{'status': 401, message: 'Given path to IP Geolocation API is not valid'}"));
return;
}
function request(subUrl, callback, apiKey = "") {
if (useSessionStorage) {
if (subUrl == "ipgeo" && sessionStorage.getItem("_ipGeolocation") && callback) {
callback(JSON.parse(sessionStorage.getItem("_ipGeolocation")));
} else if (subUrl == "timezone" && sessionStorage.getItem("_ipTimeZone") && callback) {
callback(JSON.parse(sessionStorage.getItem("_ipTimeZone")));
}
}
if (apiKey) {
urlParameters = addUrlParameter(urlParameters, "apiKey", apiKey);
}
if (excludesParameter) {
urlParameters = addUrlParameter(urlParameters, "excludes", excludesParameter);
}
var urlParameters = "";
if (!subUrl) {
callback(JSON.parse("{'status': 401, message: 'Given path to IP Geolocation API is not valid'}"));
return;
}
if (fieldsParameter) {
urlParameters = addUrlParameter(urlParameters, "fields", fieldsParameter);
if (apiKey) {
urlParameters = addUrlParameter(urlParameters, "apiKey", apiKey);
}
if (ipAddress) {
urlParameters = addUrlParameter(urlParameters, "ip", ipAddress);
}
if (fields) {
urlParameters = addUrlParameter(urlParameters, "fields", fields);
}
if (excludes) {
urlParameters = addUrlParameter(urlParameters, "excludes", excludes);
}
if (lang) {
urlParameters = addUrlParameter(urlParameters, "lang", lang);
}
if (tz) {
urlParameters = addUrlParameter(urlParameters, "tz", tz);
}
if (latitude && longitude) {
urlParameters = addUrlParameter(urlParameters, "lat", latitude);
urlParameters = addUrlParameter(urlParameters, "long", longitude);
}
$.ajax ({
async: asyncCall,
method: "GET",
url: "https://api.ipgeolocation.io/".concat(subUrl, urlParameters, ""),
contentType: "application/json",
dataType: "json",
success: function (result, status, xhr) {
if (useSessionStorage) {
if (subUrl == "ipgeo") {
sessionStorage.setItem("_ipGeolocation", JSON.stringify(result));
} else if (subUrl == "timezone") {
sessionStorage.setItem("_ipTimeZone", JSON.stringify(result));
}
}
if (callback) {
callback(result);
}
},
error: function (xhr, status, error) {
if (callback) {
callback(JSON.parse(xhr.responseText));
}
}
});
}
if (ipAddressParameter) {
urlParameters = addUrlParameter(urlParameters, "ip", ipAddressParameter);
}
if (langParameter) {
urlParameters = addUrlParameter(urlParameters, "lang", langParameter);
}
function addUrlParameter(parameters, parameterName, parameterValue) {
if (parameters) {
parameters = parameters.concat("&", parameterName, "=", parameterValue);
} else {
parameters = "?".concat(parameterName, "=", parameterValue);
}
if (tzParameter) {
urlParameters = addUrlParameter(urlParameters, "tz", tzParameter);
return parameters;
}
if (latitudeParameter && longitudeParameter) {
urlParameters = addUrlParameter(urlParameters, "lat", latitudeParameter);
urlParameters = addUrlParameter(urlParameters, "long", longitudeParameter);
}
$.ajax ({
async: asyncParameter,
method: "GET",
url: "https://api.ipgeolocation.io/".concat(subUrl, urlParameters, ""),
contentType: "application/json",
dataType: "json",
success: function (result, status, xhr) {
if (callback) {
callback(result);
}
return {
enableSessionStorage: function(e = false) {
useSessionStorage = e;
},
error: function (xhr, status, error) {
if (callback) {
callback(JSON.parse(xhr.responseText));
}
makeAsyncCallsToAPI: function(a = true) {
asyncCall = a;
},
setIPAddress: function(ip = "") {
ipAddress = ip;
},
setFields: function(f = "") {
fields = f;
},
setExcludes: function(e = "") {
excludes = e;
},
setLanguage: function(l = "en") {
lang = l;
},
setTimeZone: function(t = "") {
tz = t;
},
setCoordinates: function(latitude = "", longitude = "") {
latitudeParameter = latitude;
longitudeParameter = longitude;
},
getGeolocation: function(callback, apiKey = "") {
request("ipgeo", callback, apiKey);
},
getTimezone: function(callback, apikey = "") {
request("timezone", callback, apikey);
}
});
}
}
}();

@@ -21,3 +21,3 @@ {

],
"_resolved": "https://registry.npmjs.org/ip-geolocation-api-jquery-sdk/-/ip-geolocation-api-jquery-sdk-1.0.6.tgz",
"_resolved": "https://registry.npmjs.org/ip-geolocation-api-jquery-sdk/-/ip-geolocation-api-jquery-sdk-1.0.7.tgz",
"_shasum": "7afe1f670ee1309eb9effb25818c481c5d855593",

@@ -27,5 +27,4 @@ "_spec": "ip-geolocation-api-jquery-sdk",

"author": "ipgeolocation",
"bundleDependencies": false,
"deprecated": false,
"description": "[JQuery SDK for IP Geolocation API](https://ipgeolocation.io/documentation/ip-geolocation-api-jquery-sdk-201809051507). You can use this SDK to Geolocate an IP address and get time zone information based on geolocation coordinates, or an IP address.",
"description": "[JQuery SDK for IP Geolocation API](https://ipgeolocation.io/documentation/ip-geolocation-api-jquery-sdk.html). You can use this SDK to Geolocate an IP address and get time zone information based on geolocation coordinates, or an IP address.",
"keywords": [

@@ -51,3 +50,3 @@ "ip",

},
"version": "1.0.6",
"version": "1.0.7",
"repository": {

@@ -54,0 +53,0 @@ "type": "git",

@@ -33,3 +33,3 @@ # IP Geolocation API JQuery SDK

```html
<script src="https://cdn.jsdelivr.net/npm/ip-geolocation-api-jquery-sdk@1.0.5/ipgeolocation.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/ip-geolocation-api-jquery-sdk@1.0.6/ipgeolocation.min.js"></script>
```

@@ -49,6 +49,6 @@

// Query geolocation for the calling machine's IP address with an API key (optional, if you're using "Request Origin" feature at IP Geolocation API)
// 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)
getGeolocation(handleResponse, "YOUR_API_KEY");
// To use the "Request Origin" feature at IP Geolocation API, you skip the API key parameter.
// Don't pass the API key if you're using the "Request Origin" feature at IP Geolocation API
getGeolocation(handleResponse);

@@ -59,11 +59,16 @@

// Query geolocation for an IP address e.g., "1.1.1.1"
// Get geolocation for an IP address "1.1.1.1"
setIPAddressParameter("1.1.1.1");
getGeolocation(handleResponse, "YOUR_API_KEY");
// Query only specific geolocation fields e.g., "country_code2,time_zone,currency" for the calling machine's IP address
// Get geolocation for an IP address "1.1.1.1" in Russian language **
setLanguageParameter("ru");
setIPAddressParameter("1.1.1.1");
getGeolocation(handleResponse, "YOUR_API_KEY");
// Get the specific geolocation fields "country_code2,time_zone,currency" for the calling machine's IP address
setFieldsParameter("geo,time_zone,currency");
getGeolocation(handleResponse, "YOUR_API_KEY");
// Query only specific fields like "country_code2,time_zone,currency" for an IP address like "1.1.1.1" and skip the "ip" field in the response
// 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
setFieldsParameter("geo,time_zone,currency");

@@ -76,3 +81,3 @@ setIPAddressParameter("1.1.1.1");

Here are a few different ways of querying Time Zone information from IP Geolocation API.
Here are a few examples to query Time Zone information from Timezone API.

@@ -86,6 +91,6 @@ ```javascript

// Query 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)
// 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)
getTimezone(handleResponse, "YOUR_API_KEY");
// To use the "Request Origin" feature at IP Geolocation API, you skip the API key parameter.
// Don't pass the API key if you're using the "Request Origin" feature at IP Geolocation API
getTimezone(handleResponse);

@@ -96,11 +101,12 @@

// Query time zone information for an IP address e.g., "1.1.1.1"
// Get time zone information for an IP address "1.1.1.1" and geolocation information in Italian language **
setIPAddressParameter("1.1.1.1");
setLanguageParameter("it");
getTimezone(handleResponse, "YOUR_API_KEY");
// Query time zone infomration for a time zone ID like "America/New_York"
// Get time zone infomration for a time zone "America/New_York"
setTimezoneParameter("America/Los_Angeles");
getTimezone(handleResponse, "YOUR_API_KEY");
// Query time zone information by latitude and longitude of the location
// Get time zone information by coordinates of the location
setCoordinatesParameter("31.4816", "74.3551");

@@ -144,1 +150,14 @@ getTimezone(handleResponse, "YOUR_API_KEY");

```
** IPGeolocation provides geolocation information in the following languages:
* English (en)
* German (de)
* Russian (ru)
* Japanese (ja)
* French (fr)
* Chinese Simplified (cn)
* Spanish (es)
* Czech (cs)
* Italian (it)
By default, geolocation information is returned in English. Response in a language other than English is available to paid users only.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc