From bc3afe9665e31833dc23ba17d3ab69bc69fa82af Mon Sep 17 00:00:00 2001 From: ahsan nawaz Date: Fri, 3 Aug 2018 20:20:34 +0500 Subject: [PATCH 1/2] First commit --- index.js | 108 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 index.js diff --git a/index.js b/index.js new file mode 100644 index 0000000..0a3f697 --- /dev/null +++ b/index.js @@ -0,0 +1,108 @@ +exports.Ipgeo = function Ipgeo(apiKey){ + +this.apiKey = apiKey; + +this.ipgeoByFieldsAndIp = function(fields="" ,ip="") { +getRequest("ipgeo", this.apiKey, fields, ip, ""); +}; + +this.ipgeoByFields = function(fields="") { +getRequest("ipgeo", this.apiKey, fields, "", ""); +}; + +this.ipgeoByIp = function(ip="") { +getRequest("ipgeo", this.apiKey, "", ip, ""); +}; + +this.ipgeoByApikey = function(){ +getRequest("ipgeo", this.apiKey, "", "", "") +}; + +this.ipgeoByIps = function(ips=""){ +postRequest("ipgeo-bulk", this.apiKey, ips); +}; + +} + + + +exports.Timezone = function Timezone(apiKey){ + +this.apiKey = apiKey; +this.timezoneByIp = function(ip="") { +getRequest("timezone", this.apiKey, "", ip, ""); +} + +this.timezoneByApikey = function() { +getRequest("timezone", this.apiKey, "", "", ""); +} + +this.timezoneByTz = function(tz="") { +getRequest("timezone", this.apiKey, "", "", tz); +} + +} + + +function getRequest(subUrl=null, apiKey="", fields="", ip="", tz=""){ + +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; + } + + } +var data = null; +var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest; +var xhr = new XMLHttpRequest(); +xhr.withCredentials = true; +xhr.addEventListener("readystatechange", function () { + if (this.readyState === 4) { + var data = JSON.parse(this.responseText); + console.log(data); + return data; + } +}); +xhr.open("GET", "https://api.ipgeolocation.io/"+URL+""); +xhr.send(data); +} + +function postRequest(subUrl=null, apiKey="", ips=""){ + +var data = JSON.stringify({ + "ips": ips +}); + +var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest; +var xhr = new XMLHttpRequest(); +xhr.withCredentials = true; + +xhr.addEventListener("readystatechange", function () { + if (this.readyState === 4) { + var data = JSON.parse(this.responseText); + console.log(data); + return data; + } +}); + +xhr.open("POST", "https://api.ipgeolocation.io/"+subUrl+"?apiKey="+apiKey+""); +xhr.setRequestHeader("Content-Type", "application/json"); + +xhr.send(data); + +} + + + From 2b6bc2b6406433f90331ddc735a1ce392805763b Mon Sep 17 00:00:00 2001 From: ahsan nawaz Date: Fri, 3 Aug 2018 20:24:40 +0500 Subject: [PATCH 2/2] First commit --- package.json | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 package.json diff --git a/package.json b/package.json new file mode 100644 index 0000000..798283f --- /dev/null +++ b/package.json @@ -0,0 +1,17 @@ +{ + "name": "ipgeolocation-ip-test", + "version": "1.0.0", + "description": "new pkg", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [ + "ipgeolocation" + ], + "author": "NPM ipgeolocation (http://ipgeolocation.io)", + "license": "ISC", + "dependencies": { + "xmlhttprequest": "^1.8.0" + } +}