alexarank

A simple node package to get Alexa traffic rank for a domain or URL
Log | Files | Refs | README | LICENSE

commit afbbd134d689bf9e8073677c277fcee3f190a3d6
parent ef7ed44bbe51b041b45f04ccb87f70a692b28076
Author: Frederic Cambus <fred@statdns.com>
Date:   Tue, 25 Oct 2016 09:29:23 +0200

Reformatting: spaces => tabs

Diffstat:
Mbin/alexarank | 18+++++++++---------
Mlib/alexarank.js | 54+++++++++++++++++++++++++++---------------------------
Mtest/test.js | 22+++++++++++-----------
3 files changed, 47 insertions(+), 47 deletions(-)

diff --git a/bin/alexarank b/bin/alexarank @@ -7,7 +7,7 @@ /* https://github.com/fcambus/alexarank */ /* */ /* Created: 2013-12-14 */ -/* Last Updated: 2016-01-05 */ +/* Last Updated: 2016-10-25 */ /* */ /* alexarank is released under the BSD 2-Clause license. */ /* See LICENSE file for details. */ @@ -17,15 +17,15 @@ var alexa = require('../lib/alexarank'); if (process.argv.length == 2) { - console.log('USAGE : alexarank domain\n'); - console.log('EXAMPLES : alexarank http://www.echojs.com\n alexarank echojs.com'); - process.exit(1); + console.log('USAGE : alexarank domain\n'); + console.log('EXAMPLES : alexarank http://www.echojs.com\n alexarank echojs.com'); + process.exit(1); } alexa(process.argv[2], function(error, result) { - if (!error) { - console.log(JSON.stringify(result)); - } else { - console.log(error); - } + if (!error) { + console.log(JSON.stringify(result)); + } else { + console.log(error); + } }); diff --git a/lib/alexarank.js b/lib/alexarank.js @@ -7,7 +7,7 @@ /* https://github.com/fcambus/alexarank */ /* */ /* Created: 2013-12-14 */ -/* Last Updated: 2016-01-05 */ +/* Last Updated: 2016-10-25 */ /* */ /* alexarank is released under the BSD 2-Clause license. */ /* See LICENSE file for details. */ @@ -19,33 +19,33 @@ var fetch = require('isomorphic-fetch'); var xml2js = require('xml2js'); module.exports = function(url, callback) { - fetch('https://data.alexa.com/data?cli=10&url=' + encodeURIComponent(url)) - .then(function (res) { - return res.text(); - }) - .then(function (body) { - xml2js.parseString(body, { - normalizeTags: true, - explicitArray: false - }, function(error, result) { - if (error) { - callback(new Error('Cannot parse Alexa API Data')); - } else { - var alexa = {}; + fetch('https://data.alexa.com/data?cli=10&url=' + encodeURIComponent(url)) + .then(function (res) { + return res.text(); + }) + .then(function (body) { + xml2js.parseString(body, { + normalizeTags: true, + explicitArray: false + }, function(error, result) { + if (error) { + callback(new Error('Cannot parse Alexa API Data')); + } else { + var alexa = {}; - alexa.url = result.alexa.$.URL; - alexa.idn = result.alexa.$.IDN; + alexa.url = result.alexa.$.URL; + alexa.idn = result.alexa.$.IDN; - if (typeof result.alexa.sd != "undefined") { - alexa.rank = result.alexa.sd.popularity.$.TEXT; - alexa.reach = result.alexa.sd.reach.$.RANK; - } + if (typeof result.alexa.sd != "undefined") { + alexa.rank = result.alexa.sd.popularity.$.TEXT; + alexa.reach = result.alexa.sd.reach.$.RANK; + } - callback(null, alexa); - } - }); - }) - .catch(function (err) { - callback(err); - }); + callback(null, alexa); + } + }); + }) + .catch(function (err) { + callback(err); + }); }; diff --git a/test/test.js b/test/test.js @@ -2,19 +2,19 @@ var alexa = require('../lib/alexarank'); var should = require('should'); describe('alexarank', function() { - it('Should return an object with correct elements types', function(done) { - alexa("http://www.echojs.com", function(error, result) { - should.not.exist(error); + it('Should return an object with correct elements types', function(done) { + alexa("http://www.echojs.com", function(error, result) { + should.not.exist(error); - result.should.be.an.Object; + result.should.be.an.Object; - result.url.should.equal('echojs.com/'); - result.idn.should.equal('echojs.com/'); + result.url.should.equal('echojs.com/'); + result.idn.should.equal('echojs.com/'); - parseInt(result.rank).should.be.a.Number; - parseInt(result.reach).should.be.a.Number; + parseInt(result.rank).should.be.a.Number; + parseInt(result.reach).should.be.a.Number; - done(); - }); - }); + done(); + }); + }); });