ip-geolocation-api-jquery-sdk
Advanced tools
Comparing version 1.0.4 to 1.0.5
@@ -1,115 +0,110 @@ | ||
function geolocation(callback) { | ||
request("ipgeo", "", "", "", "", "", "", callback) | ||
} | ||
var asyncParameter = true; | ||
var ipAddressParameter = ""; | ||
var excludesParameter = ""; | ||
var fieldsParameter = ""; | ||
var langParameter = ""; | ||
var tzParameter = ""; | ||
var latitudeParameter = ""; | ||
var longitudeParameter = ""; | ||
function geolocationByAPIkey(apikey="",callback) { | ||
request("ipgeo", apikey, "", "", "", "", "", callback) | ||
} | ||
function geolocationByIP(ip="",callback) { | ||
request("ipgeo", "", "", ip, "", "", "", callback) | ||
} | ||
function setAsync(async = true) { | ||
asyncParameter = async; | ||
} | ||
function geolocationByAPIkeyAndIP(apikey="", ip="", callback) { | ||
request("ipgeo", apikey, "", ip, "", "", "", callback) | ||
} | ||
function setIPAddressParameter (ip = "") { | ||
ipAddressParameter = ip; | ||
} | ||
function geolocationByFieldsAndIP(fields="", ip="", callback) { | ||
request("ipgeo", "", fields, ip, "", "", "", callback) | ||
} | ||
function setExcludesParameter (excludes = "") { | ||
excludesParameter = excludes; | ||
} | ||
function geolocationByAPIkeyFieldsAndIp(apikey="", fields="", ip="", callback) { | ||
request("ipgeo", apikey, fields, ip, "", "", "", callback) | ||
} | ||
function setFieldsParameter (fields = "") { | ||
fieldsParameter = fields; | ||
} | ||
function geolocationByFields(fields="", callback) { | ||
request("ipgeo", "", fields, "", "", "", "", callback) | ||
} | ||
function setLanguageParameter (lang = "") { | ||
langParameter = lang; | ||
} | ||
function geolocationByAPIkeyAndFields(apikey="", fields="", callback) { | ||
request("ipgeo", apikey, fields, "", "", "", "", callback) | ||
} | ||
function setTimezoneParameter (tz = "") { | ||
tzParameter = tz; | ||
} | ||
function timezoneByIP(ip="", callback) { | ||
request("timezone", "", "", ip, "", "", "", callback) | ||
} | ||
function setCoordinatesParameter (latitude = "", longitude = "") { | ||
latitudeParameter = latitude; | ||
longitudeParameter = longitude; | ||
} | ||
function timezoneByAPIKeyAndIP(apikey="", ip="", callback) { | ||
request("timezone", apikey, "", ip, "", "", "", callback) | ||
} | ||
function getGeolocation (callback, apiKey = "") { | ||
request("ipgeo", callback, apiKey); | ||
} | ||
function timezoneByTz(tz="", callback) { | ||
request("timezone", "", "", "", tz, "", "", callback) | ||
} | ||
function getTimezone (callback, apikey = "") { | ||
request("timezone", callback, apikey); | ||
} | ||
function timezoneByAPIKeyAndTz(apikey="", tz="", callback) { | ||
request("timezone", apikey, "", "", tz, "", "", callback) | ||
} | ||
function timezone(callback) { | ||
request("timezone", "", "", "", "", "", "", callback) | ||
} | ||
function addUrlParameter(parameters, parameterName, parameterValue) { | ||
if (parameters) { | ||
parameters = parameters.concat("&", parameterName, "=", parameterValue); | ||
} else { | ||
parameters = "?".concat(parameterName, "=", parameterValue); | ||
} | ||
return parameters; | ||
} | ||
function timezoneByAPIKey(apikey="", callback) { | ||
request("timezone", apikey, "", "", "", "", "", callback) | ||
} | ||
function request (subUrl, callback, apiKey = "") { | ||
var urlParameters = ""; | ||
function timezoneByLatitudeAndLongitude(latitude="", longitude="", callback){ | ||
request("timezone", "", "", "", "", latitude, logitude, callback) | ||
} | ||
if(!subUrl) { | ||
callback({"status": 401, "message": "Given path to IP Geolocation API is not valid"}); | ||
return; | ||
} | ||
if (apiKey) { | ||
urlParameters = addUrlParameter(urlParameters, "apiKey", apiKey); | ||
} | ||
function timezoneByAPIKeyLatitudeAndLongitude(apikey="", latitude="", longitude="", callback){ | ||
request("timezone", apikey, "", "", "", latitude, logitude, callback) | ||
} | ||
if (excludesParameter) { | ||
urlParameters = addUrlParameter(urlParameters, "excludes", excludesParameter); | ||
} | ||
if (fieldsParameter) { | ||
urlParameters = addUrlParameter(urlParameters, "fields", fieldsParameter); | ||
} | ||
if (ipAddressParameter) { | ||
urlParameters = addUrlParameter(urlParameters, "ip", ipAddressParameter); | ||
} | ||
if (langParameter) { | ||
urlParameters = addUrlParameter(urlParameters, "lang", langParameter); | ||
} | ||
if (tzParameter) { | ||
urlParameters = addUrlParameter(urlParameters, "tz", tzParameter); | ||
} | ||
if (latitudeParameter && longitudeParameter) { | ||
urlParameters = addUrlParameter(urlParameters, "lat", latitudeParameter); | ||
urlParameters = addUrlParameter(urlParameters, "long", longitudeParameter); | ||
} | ||
function request(subUrl=null, apiKey="",fields="",ip="", tz="", latitude="", longitude="", callback){ | ||
var URL = ""; | ||
if(apiKey){ | ||
URL = subUrl; | ||
URL = URL + ("?apiKey=" + apiKey); | ||
if(fields){ | ||
URL = URL + "&fields="; | ||
URL = URL + fields; | ||
} | ||
if(ip){ | ||
URL = URL + "&ip="; | ||
URL = URL + ip; | ||
} | ||
if(tz){ | ||
URL = URL + "&tz="; | ||
URL = URL + tz; | ||
} | ||
if(latitude){ | ||
URL = URL + "&lat="; | ||
URL = URL + latitude; | ||
$.ajax ({ | ||
async: asyncParameter, | ||
method: "GET", | ||
url: "https://api.ipgeolocation.io/".concat(subUrl, urlParameters, ""), | ||
contentType: "application/json", | ||
dataType: "json", | ||
success: function (data, status, jqXHR) { | ||
if (callback) { | ||
callback(data); | ||
} | ||
}, | ||
error: function (data, jqXHR, status) { | ||
if (callback) { | ||
callback(data.responseText); | ||
} | ||
} | ||
if(longitude){ | ||
URL = URL + "&long="; | ||
URL = URL + longitude; | ||
} | ||
} | ||
$.ajax( | ||
{ | ||
async: true, | ||
method: "GET", | ||
url: "https://api.ipgeolocation.io/"+URL+"", | ||
contentType: "application/json; charset=utf-8", | ||
dataType: "json", | ||
success: function (data, status, jqXHR) { | ||
if(callback) { | ||
callback(data); | ||
} | ||
}, | ||
error: function (data, jqXHR, status) { | ||
if(callback) { | ||
callback(data.responseText); | ||
} | ||
} | ||
} ); | ||
} | ||
}); | ||
} |
{ | ||
"_from": "ip-geolocation-api-jquery-sdk", | ||
"_id": "ip-geolocation-api-jquery-sdk@1.0.4", | ||
"_inBundle": false, | ||
@@ -22,12 +21,10 @@ "_integrity": "sha512-mmwTYe04ioiUcnOaMiPYD5SFIBoqvnRgeC/YkrYe5B9VGxRd1gdXVmDAaXRoHacDvgnqhW+CDMXnyEvvgXtj0g==", | ||
], | ||
"_resolved": "https://registry.npmjs.org/ip-geolocation-api-jquery-sdk/-/ip-geolocation-api-jquery-sdk-1.0.4.tgz", | ||
"_resolved": "https://registry.npmjs.org/ip-geolocation-api-jquery-sdk/-/ip-geolocation-api-jquery-sdk-1.0.5.tgz", | ||
"_shasum": "7afe1f670ee1309eb9effb25818c481c5d855593", | ||
"_spec": "ip-geolocation-api-jquery-sdk", | ||
"_where": "/home/developer/jQry/npm", | ||
"author": { | ||
"name": "ipgeolocation" | ||
}, | ||
"author": "ipgeolocation", | ||
"bundleDependencies": false, | ||
"deprecated": false, | ||
"description": "## Basic Usage Add the following script in your page: ```html <script src=\"https://cdn.jsdelivr.net/npm/ip-geolocation-api-jquery-sdk@1.0.0/ipgeolocation.min.js\"></script> ``` ## Geolocation Lookup ```html ipgeoByApikey('YOUR_API_KEY') ipgeoByApikeyAndIp('YOUR_API_KEY', '1.1.1.1') ipgeoByApikeyAndFields('YOUR_API_KEY', 'geo,time_zone,currency') ipgeoByApikeyFieldsAndIp('YOUR_API_KEY', 'geo,time_zone,currency', '1.1.1.1') ``` ## Bulk Geolocations Lookup ```html ipgeoByApikeyAndIps('YOUR_API_KEY', ['1.1.1.1','2.2.22.2','34.1.1.3']) ``` ## Time Zone API ```html timezoneByApikey('YOUR_API_KEY') timezoneByApikeyAndIp('YOUR_API_KEY', '1.1.1.1') timezoneByApikeyAndTimezone('YOUR_API_KEY', 'America/Los_Angeles')", | ||
"description": "JQuery SDK for [IP Geolocation API](https://ipgeolocation.io/). You can use this SDK to Geolocate an IP address and get time zone information based on geolocation coordinates, or an IP address.", | ||
"keywords": [ | ||
@@ -43,3 +40,5 @@ "ip", | ||
"geoip api", | ||
"ip location api" | ||
"ip location api", | ||
"ip location", | ||
"ip lookup" | ||
], | ||
@@ -52,3 +51,11 @@ "license": "ISC", | ||
}, | ||
"version": "1.0.4" | ||
"version": "1.0.5", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/IPGeolocation/ip-geolocation-api-jQuery-sdk.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/IPGeolocation/ip-geolocation-api-jQuery-sdk/issues" | ||
}, | ||
"homepage": "https://github.com/IPGeolocation/ip-geolocation-api-jQuery-sdk#readme" | ||
} |
150
README.md
@@ -1,47 +0,137 @@ | ||
# IPGeolocation API JQuery SDK | ||
# IP Geolocation API JQuery SDK | ||
## Basic Usage | ||
Add the following script in your page: | ||
## Introduction | ||
[IPGeolocation API](https://ipgeolocation.io) is the solution to identify country code (ISO2 and ISO3 standard), country name, continent code, continent name, country capital, state/province, district, city, zip code, latitude and longitude of city, is country belongs to Europian Union, calling code, top level domain (TLD), languages, country flag, internet service provider (ISP), connection type, organization, geoname ID, currency code, currency name, time zone ID, time zone offset, current time in the time zone, is time zone in daylight saving time, and total daylight savings. This document provides important information to help you get up to speed with IPGeolocation API using IP Geolocation API JQuery SDK. | ||
Developers can use this JQuery SDK for software and web projects related to, but not limited to: | ||
1. Display native language and currency | ||
2. Redirect based on the country | ||
3. Digital rights management | ||
4. Web log stats and analysis | ||
5. Auto-selection of country, state/province and city on forms | ||
6. Filter access from countries you do not do business with | ||
7. Geo-targeting for increased sales and click-through | ||
## Quick Start Guide | ||
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. | ||
**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). | ||
## System Requirements | ||
Internet connection is required to run this component. | ||
## Installation | ||
### CDN Link | ||
Add the following script in your HTML page: | ||
```html | ||
<script src="https://cdn.jsdelivr.net/npm/ip-geolocation-api-jquery-sdk@1.0.4/ipgeolocation.min.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/ip-geolocation-api-jquery-sdk@1.0.5/ipgeolocation.min.js"></script> | ||
``` | ||
## Geolocation Lookup | ||
```html | ||
<script> | ||
function geoResponse(data){ | ||
console.log(data); | ||
You can use this SDK without an API key if you're using the _Request Origin_ feaure on IP Geolocation API. | ||
Here are a few different ways of querying Geolocation for an IP address from IP Geolocation API. | ||
```javascript | ||
// Function to handle the response from IP Geolocation API. | ||
// "response" is a JSON object returned from IP Geolocation API. | ||
function handleResponse(response) { | ||
console.log(response); | ||
} | ||
</script> | ||
geolocation(geoResponse) | ||
geolocationByAPIkey('YOUR_API_KEY', geoResponse) | ||
geolocationByIP('1.1.1.1', geoResponse) | ||
geolocationByAPIkeyAndIP('YOUR_API_KEY', '1.1.1.1', geoResponse) | ||
// 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) | ||
getGeolocation(handleResponse, "YOUR_API_KEY"); | ||
geolocationByFields('geo,time_zone,currency', geoResponse) | ||
geolocationByAPIkeyAndFields('YOUR_API_KEY', 'geo,time_zone,currency', geoResponse) | ||
// To use the "Request Origin" feature at IP Geolocation API, you skip the API key parameter. | ||
getGeolocation(handleResponse); | ||
geolocationByFieldsAndIP('geo,time_zone,currency', '1.1.1.1', geoResponse) | ||
geolocationByAPIkeyFieldsAndIp('YOUR_API_KEY', 'geo,time_zone,currency', '1.1.1.1', geoResponse) | ||
// Toggle API calls' async behavior. By default, async is true. | ||
setAsync(false) | ||
// Query geolocation for an IP address e.g., "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 | ||
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 | ||
setFieldsParameter("geo,time_zone,currency"); | ||
setIPAddressParameter("1.1.1.1"); | ||
setExcludesParameter("ip"); | ||
getGeolocation(handleResponse, "YOUR_API_KEY"); | ||
``` | ||
## Time Zone API | ||
```html | ||
<script> | ||
function geoResponse(data){ | ||
console.log(data); | ||
Here are a few different ways of querying Time Zone information from IP Geolocation API. | ||
```javascript | ||
// Function to handle the response from IP Geolocation API. | ||
// "response" is a JSON object returned from IP Geolocation API. | ||
function handleResponse(response) { | ||
console.log(response); | ||
} | ||
</script> | ||
timezone(geoResponse) | ||
timezoneByAPIKey('YOUR_API_KEY', geoResponse) | ||
timezoneByIP('1.1.1.1', geoResponse) | ||
timezoneByAPIKeyAndIP('YOUR_API_KEY', '1.1.1.1', geoResponse) | ||
// 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) | ||
getTimezone(handleResponse, "YOUR_API_KEY"); | ||
timezoneByTz('America/Los_Angeles', geoResponse) | ||
timezoneByAPIKeyAndTz('YOUR_API_KEY', 'America/Los_Angeles', geoResponse) | ||
// To use the "Request Origin" feature at IP Geolocation API, you skip the API key parameter. | ||
getTimezone(handleResponse); | ||
// Toggle API calls' async behavior. By default, async is true. | ||
setAsync(false) | ||
// Query time zone information for an IP address e.g., "1.1.1.1" | ||
setIPAddressParameter("1.1.1.1"); | ||
getTimezone(handleResponse, "YOUR_API_KEY"); | ||
// Query time zone infomration for a time zone ID like "America/New_York" | ||
setTimezoneParameter("America/Los_Angeles"); | ||
getTimezone(handleResponse, "YOUR_API_KEY"); | ||
// Query time zone information by latitude and longitude of the location | ||
timezoneByLatitudeAndLongitude( '31.4816', '74.3551', geoResponse) | ||
timezoneByAPIKeyLatitudeAndLongitude('YOUR_API_KEY', '31.4816', '74.3551', geoResponse) | ||
setCoordinatesParameter("31.4816", "74.3551"); | ||
getTimezone(handleResponse, "YOUR_API_KEY"); | ||
``` | ||
## Example | ||
Here is a sample code to use IP Geolocation API using JQuery SDK: | ||
```javascript | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/ip-geolocation-api-jquery-sdk@1.0.5/ipgeolocation.min.js"></script> | ||
<script> | ||
var ip = sessionStorage.getItem("ip"); | ||
var country_name = sessionStorage.getItem("country_name"); | ||
var country_code2 = sessionStorage.getItem("country_code2"); | ||
if (!ip || !country_name || !country_code2) { | ||
setAsync(false); | ||
setFieldsParameter("country_name,country_code2"); | ||
getGeolocation(handleGeolocationResponse, "YOUR_API_KEY"); | ||
} | ||
function handleGeolocationResponse(json) { | ||
ip = json.ip; | ||
country_name = json.country_name; | ||
country_code2 = json.country_code2; | ||
sessionStorage.setItem("ip", ip); | ||
sessionStorage.setItem("country_name", country_name); | ||
sessionStorage.setItem("country_code2", country_code2); | ||
} | ||
$(document).ready(function() { | ||
alert("Hello " + country_name + "!"); | ||
}); | ||
</script> | ||
``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
10486
0
1
138
0
89