Socket
Socket
Sign inDemoInstall

ip-geolocation-api-javascript-sdk

Package Overview
Dependencies
1
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.3 to 1.0.4

16

GeolocationParams.js
module.exports = class GeolocationParams {
constructor() {
var ip = "";
var fields = "";
var ips = "";
var ip = "";
var fields = "";
var ips = "";
}
setIp(ip = "") {
this.ip = ip;
setIP(ip = "") {
this.ip = ip;
}
getIp() {
getIP() {
return this.ip;

@@ -25,3 +25,3 @@ }

setIps(ips = "") {
setIPList(ips = []) {
if(ips.length > 50) {

@@ -34,3 +34,3 @@ console.log("Max. number of IP addresses cannot be more than 50.");

getIps() {
getIPList() {
return this.ips;

@@ -37,0 +37,0 @@ }

@@ -6,3 +6,2 @@ var GeolocationParams = require('./GeolocationParams.js');

constructor(apiKey = "") {

@@ -16,125 +15,123 @@ this.apiKey = apiKey;

getGeolocation(params = null) {
if(params.getIps())
{ return postRequest("ipgeo-bulk", params, this.apiKey);
}else{
return getRequest("ipgeo", buildGeolocationUrlParams(params, this.apiKey));
}
getGeolocation(params = null, callback) {
if(params && params.getIPList()) {
return postRequest("ipgeo-bulk", params, this.apiKey, callback);
} else {
return getRequest("ipgeo", buildGeolocationUrlParams(params, this.apiKey), callback);
}
}
getTimezone(params = null) {
return getRequest("timezone", buildTimezoneUrlParams(params, this.apiKey));
getTimezone(params = null, callback) {
return getRequest("timezone", buildTimezoneUrlParams(params, this.apiKey), callback);
}
}
function buildTimezoneUrlParams(params = null, apiKey = "") {
var urlParams = "";
}
if(apiKey) {
urlParams = urlParams.concat("apiKey=", apiKey);
}
if(params) {
var ip = params.getIP();
function buildTimezoneUrlParams(params=null, apiKey="") {
var urlParams = "apiKey=" + apiKey;
if(params != null) {
var param = params.getIp();
if(param && param != "") {
urlParams = urlParams + "&ip=" + param;
if(ip) {
if(urlParams) {
urlParams = urlParams.concat("&");
}
urlParams = urlParams.concat("ip=", ip);
}
param = params.getTimezone();
if(param && param != "") {
urlParams = urlParams + "&tz=" + param;
var tz = params.getTimezone();
if(tz) {
if(urlParams) {
urlParams = urlParams.concat("&");
}
urlParams = urlParams.concat("tz=", tz);
}
var latitude = params.getLatitude();
var longitude = params.getLongitude();
if(latitude && latitude != 1000.0 && longitude && longitude != 1000.0) {
urlParams = urlParams + "&lat=" + latitude + "&long=" + longitude;
var latitude = params.getLatitude();
var longitude = params.getLongitude();
if(latitude && latitude !== 1000.0 && longitude && longitude !== 1000.0) {
if(urlParams) {
urlParams = urlParams.concat("&");
}
urlParams = urlParams.concat("lat=", latitude, "&long=", longitude);
}
return urlParams;
}
return urlParams;
}
function buildGeolocationUrlParams(params = null, apiKey = "") {
var urlParams = "";
if(apiKey) {
urlParams = urlParams.concat("apiKey=", apiKey);
}
function buildGeolocationUrlParams(params=null, apiKey="") {
if(params) {
var ip = params.getIP();
var urlParams = "apiKey=" + apiKey;
if(params != null) {
var param = params.getIp();
if(param && param != "") {
urlParams = urlParams + "&ip=" + param;
if(ip) {
if(urlParams) {
urlParams = urlParams.concat("&");
}
urlParams = urlParams.concat("ip=", ip);
}
param = params.getFields();
if(param && param != "") {
urlParams = urlParams + "&fields=" + param;
var fields = params.getFields();
if(fields) {
if(urlParams) {
urlParams = urlParams.concat("&");
}
urlParams = urlParams.concat("fields=", fields);
}
return urlParams;
}
return urlParams;
}
function getRequest(subUrl = "", params = "", callback) {
var jsonData = null;
var XMLHttpRequest = require("./xmlhttprequest").XMLHttpRequest;
var xhttp = new XMLHttpRequest();
xhttp.withCredentials = true;
xhttp.onreadystatechange = function() {
if (this.readyState === 4) {
jsonData = JSON.parse(this.responseText);
function getRequest(subUrl = "", params = ""){
var jsonData = null;
var data = null;
var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener("readystatechange", function () {
if (this.readyState === 4) {
if(this.status == 0){
jsonData = {
"message": "Internet is not connected!"
};
}else{
jsonData = JSON.parse(this.responseText);
}
if (callback && typeof(callback) === typeof(Function)) {
callback(jsonData);
}
}
};
xhttp.open("GET", "https://api.ipgeolocation.io/".concat(subUrl, "?", params, ""), true);
xhttp.send();
}
});
xhr.open("GET", "https://api.ipgeolocation.io/"+subUrl+"?"+params+"", false);
xhr.send(data);
return jsonData;
}
function postRequest(subUrl = "", params = "", apiKey = "", callback) {
var jsonData = null;
var data = JSON.stringify({
"ips": params.getIPList()
});
var XMLHttpRequest = require("./xmlhttprequest").XMLHttpRequest;
var xhttp = new XMLHttpRequest();
function postRequest(subUrl = "", params = "", apiKey=""){
var jsonData = null;
var data = JSON.stringify({
"ips": params.getIps()
});
var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener("readystatechange", function () {
if (this.readyState === 4) {
if(this.status == 0){
jsonData = {
"message": "Internet is not connected!"
};
}else{
jsonData = JSON.parse(this.responseText);
}
xhttp.withCredentials = true;
xhttp.onreadystatechange = function() {
if (this.readyState === 4) {
jsonData = JSON.parse(this.responseText);
if (callback && typeof(callback) === typeof(Function)) {
callback(jsonData);
}
}
};
xhttp.open("POST", "https://api.ipgeolocation.io/".concat(subUrl, "?apiKey=", apiKey, ""), true);
xhttp.setRequestHeader("Content-Type", "application/json");
xhttp.send(data);
}
});
xhr.open("POST", "https://api.ipgeolocation.io/"+subUrl+"?apiKey="+apiKey+"", false);
xhr.setRequestHeader("Content-Type", "application/json");
xhr.send(data);
return jsonData;
}
{
"name": "ip-geolocation-api-javascript-sdk",
"version": "1.0.3",
"description": "",
"main": "IPGeolocationAPI.js",
"_from": "ip-geolocation-api-javascript-sdk",
"_id": "ip-geolocation-api-javascript-sdk@1.0.4",
"_inBundle": false,
"_integrity": "sha512-NgAKkoq1xRbOWuwOQYHrMNyWOl/m6SvfE/CqSF+BE7PBJurxRTY+9D1YAFz9qSgLyf9nNUoCjNbSAstcMcrzGw==",
"_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.4.tgz",
"_shasum": "cfdd4c808bef4a42d714bc77b981e121d28e1627",
"_spec": "ip-geolocation-api-javascript-sdk",
"_where": "/home/developer/jvs/npm",
"author": {
"name": "ipgeolocation"
},
"bundleDependencies": false,
"dependencies": {
"xmlhttprequest": "^1.8.0"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"deprecated": false,
"description": "## Installation ```cli npm i ip-geolocation-api-javascript-sdk ```",
"keywords": [

@@ -24,4 +47,9 @@ "ip",

],
"author": "ipgeolocation",
"license": "ISC"
"license": "ISC",
"main": "IPGeolocationAPI.js",
"name": "ip-geolocation-api-javascript-sdk",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"version": "1.0.4"
}

@@ -32,6 +32,12 @@ # IPGeolocation API Javascript SDK

console.log(api.getGeolocation(geolocationParams));
api.getGeolocation(geolocationParams, geoResponse);
function geoResponse(json) {
console.log(json);
}
// Query geolocation for the calling machine's IP address for all fields
console.log(api.getGeolocation());
api.getGeolocation(geoResponse);
function geoResponse(json) {
console.log(json);
}
```

@@ -45,3 +51,6 @@

console.log(api.getGeolocation(geolocationParams));
api.getGeolocation(geolocationParams);
function geoResponse(json) {
console.log(json);
}
```

@@ -55,4 +64,7 @@

tzParams.setIp("1.1.1.1");
console.log(obj.getTimezone());
obj.getTimezone(geoResponse);
function geoResponse(json) {
console.log(json);
}
```
module.exports = class TimezoneParams {
constructor() {

@@ -19,7 +18,7 @@ var timezone = "";

setIp(ip = "") {
setIP(ip = "") {
this.ip = ip;
}
getIp() {
getIP() {
return this.ip;

@@ -40,5 +39,4 @@ }

}
}
SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc