ip-geolocation-api-javascript-sdk
Advanced tools
Comparing version 1.0.7 to 1.0.8
@@ -1,9 +0,14 @@ | ||
module.exports = class GeolocationParams { | ||
module.exports = class GeolocationParams { | ||
constructor() { | ||
var ipAdress = ''; | ||
var ipAdresses = []; | ||
var fields = '*'; | ||
var excludes = ''; | ||
var lang = 'en'; | ||
var ipAdresses = []; | ||
var includeHostname = false; | ||
var includeLiveHostname = false; | ||
var includeHostnameFallbackLive = false; | ||
var includeSecurity = false; | ||
var includeUserAgent = false; | ||
} | ||
@@ -44,3 +49,3 @@ | ||
setIPAddresses(ipAdresses = []) { | ||
if(ipAdresses.length > 50) { | ||
if (ipAdresses.length > 50) { | ||
console.log("Max. number of IP addresses cannot be more than 50."); | ||
@@ -55,3 +60,43 @@ } else { | ||
} | ||
setIncludeHostname(b = false) { | ||
this.includeHostname = b; | ||
} | ||
setIncludeHostnameFallbackLive(b = false) { | ||
this.includeHostnameFallbackLive = b; | ||
} | ||
setIncludeLiveHostname(b = false) { | ||
this.includeLiveHostname = b; | ||
} | ||
setIncludeSecurity(b = false) { | ||
this.includeSecurity = b; | ||
} | ||
setIncludeUserAgent(b = false) { | ||
this.includeUserAgent = b; | ||
} | ||
isIncludeHostname() { | ||
return this.includeHostname; | ||
} | ||
isIncludeHostnameFallbackLive() { | ||
return this.includeHostnameFallbackLive; | ||
} | ||
isIncludeLiveHostname() { | ||
return this.includeLiveHostname; | ||
} | ||
isIncludeSecurity() { | ||
return this.includeSecurity; | ||
} | ||
isIncludeUserAgent() { | ||
return this.includeUserAgent; | ||
} | ||
} | ||
@@ -12,3 +12,3 @@ var GeolocationParams = require('./GeolocationParams.js'); | ||
getGeolocation(callback, geolocationParams = null) { | ||
if(geolocationParams && geolocationParams.getIPAddresses()) { | ||
if (geolocationParams && geolocationParams.getIPAddresses()) { | ||
var jsonData = JSON.stringify({ | ||
@@ -23,3 +23,3 @@ 'ips': geolocationParams.getIPAddresses() | ||
} | ||
getTimezone(callback, timezoneParams = null) { | ||
@@ -29,2 +29,22 @@ return getRequest('timezone', buildTimezoneUrlParams(this.apiKey, timezoneParams), callback); | ||
getUserAgent(callback, uaString ="") { | ||
var jsonData = "{\"uaString\":\"" + uaString + "\"}"; | ||
postRequest('user-agent', "apiKey=" + this.apiKey, jsonData, callback); | ||
} | ||
getBulkUserAgent(callback, uaStrings = []) { | ||
var jsonData = "{\"uaStrings\":["; | ||
for(let i = 0; i < uaStrings.length; i++){ | ||
if(i === 0){ | ||
jsonData = jsonData.concat("\"" + uaStrings[i] + "\""); | ||
} else{ | ||
jsonData = jsonData.concat(","); | ||
jsonData = jsonData.concat("\"" + uaStrings[i] + "\""); | ||
} | ||
} | ||
jsonData = jsonData.concat("]}"); | ||
postRequest('user-agent-bulk', "apiKey=" + this.apiKey, jsonData, callback); | ||
} | ||
getApiKey() { | ||
@@ -42,9 +62,9 @@ return this.apiKey; | ||
if(apiKey) { | ||
if (apiKey) { | ||
urlParams = urlParams.concat('apiKey=', apiKey); | ||
} | ||
if(geolocationParams) { | ||
if(geolocationParams.getIPAddress()) { | ||
if(urlParams) { | ||
if (geolocationParams) { | ||
if (geolocationParams.getIPAddress()) { | ||
if (urlParams) { | ||
urlParams = urlParams.concat('&'); | ||
@@ -55,5 +75,5 @@ } | ||
} | ||
if(geolocationParams.getFields()) { | ||
if(urlParams) { | ||
if (geolocationParams.getFields()) { | ||
if (urlParams) { | ||
urlParams = urlParams.concat('&'); | ||
@@ -64,5 +84,5 @@ } | ||
} | ||
if(geolocationParams.getExcludes()) { | ||
if(urlParams) { | ||
if (geolocationParams.getExcludes()) { | ||
if (urlParams) { | ||
urlParams = urlParams.concat('&'); | ||
@@ -73,5 +93,5 @@ } | ||
} | ||
if(geolocationParams.getLang()) { | ||
if(urlParams) { | ||
if (geolocationParams.getLang()) { | ||
if (urlParams) { | ||
urlParams = urlParams.concat('&'); | ||
@@ -82,2 +102,37 @@ } | ||
} | ||
if (geolocationParams.isIncludeHostname() || geolocationParams.isIncludeHostnameFallbackLive() || geolocationParams.isIncludeLiveHostname() || geolocationParams.isIncludeSecurity() || geolocationParams.isIncludeUserAgent()) { | ||
var val = ""; | ||
var includeHost = false; | ||
if (geolocationParams.isIncludeHostname()) { | ||
val = "hostname"; | ||
includeHost = true; | ||
} else if (geolocationParams.isIncludeHostnameFallbackLive()) { | ||
val = "hostnameFallbackLive"; | ||
includeHost = true; | ||
} else if (geolocationParams.isIncludeLiveHostname()) { | ||
val = "liveHostname"; | ||
includeHost = true; | ||
} | ||
if (geolocationParams.isIncludeSecurity()) { | ||
if (includeHost) { | ||
val = val + ",security"; | ||
} else { | ||
val = "security"; | ||
} | ||
} | ||
if (geolocationParams.isIncludeUserAgent()) { | ||
if (includeHost || geolocationParams.isIncludeSecurity()) { | ||
val = val + ",useragent"; | ||
} else { | ||
val = "useragent"; | ||
} | ||
} | ||
if (urlParams) { | ||
urlParams = urlParams.concat('&'); | ||
} | ||
urlParams = urlParams.concat('include=', val); | ||
} | ||
} | ||
@@ -90,9 +145,9 @@ return urlParams; | ||
if(apiKey) { | ||
if (apiKey) { | ||
urlParams = urlParams.concat('apiKey=', apiKey); | ||
} | ||
if(timezoneParams) { | ||
if(timezoneParams.getIPAddress()) { | ||
if(urlParams) { | ||
if (timezoneParams) { | ||
if (timezoneParams.getIPAddress()) { | ||
if (urlParams) { | ||
urlParams = urlParams.concat('&'); | ||
@@ -104,4 +159,4 @@ } | ||
if(timezoneParams.getTimezone()) { | ||
if(urlParams) { | ||
if (timezoneParams.getTimezone()) { | ||
if (urlParams) { | ||
urlParams = urlParams.concat('&'); | ||
@@ -113,12 +168,19 @@ } | ||
if(timezoneParams.getLatitude() !== '1000.0' && timezoneParams.getLongitude() !== '1000.0') { | ||
if(urlParams) { | ||
if (timezoneParams.getLocation()) { | ||
if (urlParams) { | ||
urlParams = urlParams.concat('&'); | ||
} | ||
urlParams = urlParams.concat('location=', timezoneParams.getLocation()); | ||
} | ||
if ((timezoneParams.getLatitude() >= -90 && timezoneParams.getLatitude() <= 90) && (timezoneParams.getLongitude() >= -180 && timezoneParams.getLongitude() <= 180)) { | ||
if (urlParams) { | ||
urlParams = urlParams.concat('&'); | ||
} | ||
urlParams = urlParams.concat('lat=', timezoneParams.getLatitude(), '&long=', timezoneParams.getLongitude()); | ||
} | ||
if(timezoneParams.getLang()) { | ||
if(urlParams) { | ||
if (timezoneParams.getLang()) { | ||
if (urlParams) { | ||
urlParams = urlParams.concat('&'); | ||
@@ -138,5 +200,5 @@ } | ||
xhr.onreadystatechange = function() { | ||
xhr.onreadystatechange = function () { | ||
if (this.readyState === 4) { | ||
if (this.status == 0){ | ||
if (this.status == 0) { | ||
jsonData = { | ||
@@ -149,3 +211,3 @@ 'message': 'Internet is not connected!' | ||
if (callback && typeof(callback) === typeof(Function)) { | ||
if (callback && typeof (callback) === typeof (Function)) { | ||
callback(jsonData); | ||
@@ -164,7 +226,7 @@ } else { | ||
function postRequest(subUrl, urlParams = '', requestData = {}, callback) { | ||
var jsonData = {}; | ||
var jsonData = {}; | ||
var XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest; | ||
var xhr = new XMLHttpRequest(); | ||
xhr.onreadystatechange = function() { | ||
xhr.onreadystatechange = function () { | ||
if (this.readyState === 4) { | ||
@@ -176,6 +238,6 @@ if (this.status == 0) { | ||
} else { | ||
jsonData = JSON.parse(this.responseText); | ||
jsonData = JSON.parse(this.responseText); | ||
} | ||
if (callback && typeof(callback) === typeof(Function)) { | ||
if (callback && typeof (callback) === typeof (Function)) { | ||
callback(jsonData); | ||
@@ -182,0 +244,0 @@ } else { |
{ | ||
"_from": "ip-geolocation-api-javascript-sdk", | ||
"_inBundle": false, | ||
"_integrity": "sha512-hzaB5USO7B3XltJTckXK9FtC+OpSiGx4h8/nV3eskFhmmTBC1YVTd9WnlJTUQm3sb9e+V3pzu8coNbXC3ZrRPg==", | ||
"_location": "/ip-geolocation-api-javascript-sdk", | ||
"_phantomChildren": {}, | ||
"_requested": { | ||
"type": "tag", | ||
"registry": true, | ||
"raw": "ip-geolocation-api-javascript-sdk", | ||
"name": "ip-geolocation-api-javascript-sdk", | ||
"escapedName": "ip-geolocation-api-javascript-sdk", | ||
"rawSpec": "", | ||
"saveSpec": null, | ||
"fetchSpec": "latest" | ||
}, | ||
"_requiredBy": [ | ||
"#USER", | ||
"/" | ||
], | ||
"_resolved": "https://registry.npmjs.org/ip-geolocation-api-javascript-sdk/-/ip-geolocation-api-javascript-sdk-1.0.6.tgz", | ||
"_shasum": "0273f7c043749ce91a586388edf35319d2c52818", | ||
"_spec": "ip-geolocation-api-javascript-sdk", | ||
"_where": "/home/developer/jvs/new-npm", | ||
"author": "ipgeolocation", | ||
"bundleDependencies": false, | ||
"dependencies": { | ||
@@ -50,3 +26,3 @@ "xmlhttprequest": "^1.8.0" | ||
}, | ||
"version": "1.0.7", | ||
"version": "1.0.8", | ||
"devDependencies": {}, | ||
@@ -53,0 +29,0 @@ "repository": { |
@@ -33,2 +33,5 @@ # IP Geolocation API Javascript SDK | ||
``` | ||
## Documentation | ||
Use the following URL to visit documentation | ||
[https://ipgeolocation.io/documentation.html](https://ipgeolocation.io/documentation.html) | ||
@@ -40,15 +43,8 @@ ## Basic Usage | ||
```javascript | ||
var IPGeolocationAPI = require('ip-geolocation-api-javascript-sdk/IPGeolocationAPI'); | ||
var IPGeolocationAPI = require('ip-geolocation-api-javascript-sdk'); | ||
// Create IPGeolocationAPI object, passing your valid API key (optional) and async requests mode (optional, default: true) | ||
var ipgeolocationApi = new IPGeolocationAPI("YOUR_API_KEY"); | ||
// Turn off async mode | ||
var ipgeolocationApi = new IPGeolocationAPI("YOUR_API_KEY", false); | ||
// If you want to authorize your requests by your "Request Origin", you can create IPGeolocationAPI object without an API key | ||
var ipgeolocationApi = new IPGeolocationAPI(); | ||
// Turn off async mode | ||
var ipgeolocationApi = new IPGeolocationAPI(false); | ||
// Create IPGeolocationAPI object. Constructor takes two parameters. | ||
// 1) API key (Optional: To authenticate your requests through "Request Origin", you can skip it.) | ||
// 2) Async (Optional: It is used to toggle "async" mode in the requests. By default, it is true.) | ||
var ipgeolocationApi = new IPGeolocationAPI("YOUR_API_KEY", false); | ||
``` | ||
@@ -66,15 +62,23 @@ | ||
// Query geolocation for an IP address "1.1.1.1" and all fields | ||
// Get complete geolocation for the calling machine's IP address | ||
ipgeolocationApi.getGeolocation(handleResponse); | ||
// Get complete geolocation in Russian** for IP address (1.1.1.1) | ||
var geolocationParams = new GeolocationParams(); | ||
geolocationParams.setIPAddress("1.1.1.1"); | ||
geolocationParams.setIPAddress('1.1.1.1'); | ||
geolocationParams.setLang('ru'); | ||
ipgeolocationApi.getGeolocation(handleResponse, geolocationParams); | ||
// Query geolocation for the calling machine's IP address for all fields | ||
ipgeolocationApi.getGeolocation(handleResponse); | ||
// Get custom geolocation (only "geo, time_zone and currency" fields/objects) for an IP address (1.1.1.1) | ||
var geolocationParams = new GeolocationParams(); | ||
geolocationParams.setIPAddress('1.1.1.1'); | ||
geolocationParams.setFields('geo,time_zone,currency'); | ||
// Query geolocation for an IP address "1.1.1.1" and fields "geo, time_zone, currency" | ||
ipgeolocationApi.getGeolocation(handleResponse, geolocationParams); | ||
// Exclude fields/obejects from complete geolocation in Italian language | ||
var geolocationParams = new GeolocationParams(); | ||
geolocationParams.setIPAddress("1.1.1.1"); | ||
geolocationParams.setFields("geo,time_zone,currency"); | ||
geolocationParams.setExcludes('continent_name,country_code3,time_zone'); | ||
geolocationParams.setLang('it'); | ||
@@ -87,17 +91,18 @@ ipgeolocationApi.getGeolocation(handleResponse, geolocationParams); | ||
```ts | ||
// Query geolocations for multiple IP addresses and all fields | ||
// Query geolocation in German** for multiple IP addresses and all fields | ||
var geolocationParams = new GeolocationParams(); | ||
geolocationParams.setIPAddresses(["1.1.1.1", "2.2.2.2", "3.3.3.3"]); | ||
geolocationParams.setLang('de'); | ||
geolocationParams.setIPAddresses(['1.1.1.1', '2.2.2.2', '3.3.3.3']); | ||
ipgeolocationApi.getGeolocation(handleResponse, geolocationParams); | ||
// Query geolocations for multiple IP addresses but only 'geo' field | ||
// Specify the required fields/objects for multiple IP addresses | ||
var geolocationParams = new GeolocationParams(); | ||
geolocationParams.setIPAddresses(["1.1.1.1", "2.2.2.2", "3.3.3.3"]); | ||
geolocationParams.setFields("geo"); | ||
geolocationParams.setIPAddresses(['1.1.1.1', '2.2.2.2', '3.3.3.3']); | ||
geolocationParams.setFields('geo'); | ||
ipgeolocationApi.getGeolocation(handleResponse, geolocationParams); | ||
ipgeolocationApi.getGeolocation(geolocationParams, geoResponse); | ||
``` | ||
### Time Zone API | ||
### Timezone API | ||
@@ -107,22 +112,47 @@ ```ts | ||
// Query time zone information by time zone ID | ||
// Get time zone information by time zone ID | ||
var timezoneParams = new TimezoneParams(); | ||
timezoneParams.setTimezone("America/New_York"); | ||
timezoneParams.setTimezone('America/Los_Angeles'); | ||
ipgeolocationApi.getTimezone(handleResponse, timezoneParams); | ||
// Query time zone information by latitude and longitude of the location | ||
// Get time zone information by latitude and longitude of the location | ||
var timezoneParams = new TimezoneParams(); | ||
timezoneParams.setCoordinates(37.1838139, -123.8105225); | ||
timezoneParams.setCoordinates('37.1838139', '-123.8105225'); | ||
ipgeolocationApi.getTimezone(handleResponse, timezoneParams); | ||
// Query time zone information for IP address "1.1.1.1" | ||
// Get time zone information for IP address (1.1.1.1) and geolocation information Japanese** | ||
var timezoneParams = new TimezoneParams(); | ||
timezoneParams.setIPAddress("1.1.1.1"); | ||
timezoneParams.setIPAddress('1.1.1.1'); | ||
ipgeolocationApi.getTimezone(handleResponse, timezoneParams); | ||
// Query time zone information for calling machine’s IP address | ||
// Query time zone information for calling machine's IP address | ||
ipgeolocationApi.getTimezone(handleResponse); | ||
``` | ||
### UserAgent API | ||
```ts | ||
// Get user agent information for single user agent string | ||
ipgeolocationApi.getUserAgent(handleResponse, "AppleTV6,2/11.1"); | ||
// Get user agents information in bulk by providing array of user agent strings | ||
const uaStrings = ["AppleTV6,2/11.1", "Roku4640X/DVP-7.70 (297.70E04154A)", "Mozilla/5.0 (Nintendo 3DS; U; ; en) Version/1.7412.EU"]; | ||
ipgeolocationApi.getBulkUserAgent(handleResponse, uaStrings); | ||
``` | ||
** 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. |
@@ -9,2 +9,3 @@ module.exports = class TimezoneParams { | ||
var longitude = '1000.0'; | ||
var location = ""; | ||
} | ||
@@ -36,5 +37,7 @@ | ||
setCoordinates(latitude = '1000.0', longitude = '1000.0') { | ||
this.latitude = latitude; | ||
this.longitude = longitude; | ||
setCoordinates(la = '1000.0', lo = '1000.0') { | ||
if ((la >= -90 && la <= 90) && (lo >= -180 && lo <= 180)) { | ||
this.latitude = la; | ||
this.longitude = lo; | ||
} | ||
} | ||
@@ -49,4 +52,10 @@ | ||
} | ||
getLocation() { | ||
return this.location; | ||
} | ||
setLocation(loc = "") { | ||
this.location = loc; | ||
} | ||
} | ||
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
18026
323
154
0