twitst4tz

twitter statistics web application
Log | Files | Refs | README | LICENSE

helpers.js (1208B)


      1 var EventEmitter = require('events').EventEmitter;
      2 var stream = require('stream');
      3 var util = require('util');
      4 
      5 // Used to stub out calls to `request`.
      6 exports.FakeRequest = function () {
      7   EventEmitter.call(this)
      8 }
      9 util.inherits(exports.FakeRequest, EventEmitter)
     10 exports.FakeRequest.prototype.destroy = function () {
     11 
     12 }
     13 
     14 // Used to stub out the http.IncomingMessage object emitted by the "response" event on `request`.
     15 exports.FakeResponse = function (statusCode, body) {
     16   if (!body) {
     17     body = '';
     18   }
     19   this.statusCode = statusCode;
     20   stream.Readable.call(this);
     21   this.push(body);
     22   this.push(null);
     23 }
     24 util.inherits(exports.FakeResponse, stream.Readable);
     25 
     26 exports.FakeResponse.prototype._read = function () {
     27 
     28 }
     29 exports.FakeResponse.prototype.destroy = function () {
     30 
     31 }
     32 
     33 exports.generateRandomString = function generateRandomString (length) {
     34   var length = length || 10
     35   var ret = ''
     36   var alphabet = 'abcdefghijklmnopqrstuvwxyz0123456789'
     37   for (var i = 0; i < length; i++) {
     38     // use an easy set of unicode as an alphabet - twitter won't reformat them
     39     // which makes testing easier
     40     ret += alphabet[Math.floor(Math.random()*alphabet.length)]
     41   }
     42 
     43   ret = encodeURI(ret)
     44 
     45   return ret
     46 }