UNPKG

scamfree

Version:

scamfree is a project dedicated to helping combat the spread of hackers, spammers, and abusive activity on the internet.

60 lines (33 loc) 1.25 kB
/********************************************* * endpoint : api.scamfree.co/ip/search/ * * parameter : * * - APIKey * * - IP ( IPV4 or IPV6) * **********************************************/ /* jslint node: true, sub: true */ 'use strict'; var request = require('request') // Init the module module.exports = (function() { var findUrl = 'https://api.scamfree.co/ip/search/'; var find = function find(options, callback) { if(typeof callback !== 'function') callback = function callback(err, result) { return err || result; }; if(!options || typeof options !== 'object') return callback('invalid options'); if(!options.IP) return callback('missing IP address'); if(!options.APIKey) return callback('missing APIKey'); var timeout = options.timeout || 2500, reqUrl = findUrl+options.IP+'?token='+options.APIKey request.get({url: reqUrl, timeout: timeout}, function(err, res, body) { if(err) return callback(err); if(res.statusCode !== 200) return callback(new Error('request failed (' + res.statusCode + ')')); return callback(body); }); }; return { find: find }; })();