var twitterError = require('./error'),
    twit = require('twitter'),
    Promise = require('bluebird'),
    PromiseThrottle = require('promise-throttle');


var throttleOptions = {
  requestsPerSecond: 0.2,
  promiseImplementation: Promise
};

var throttle = new PromiseThrottle(throttleOptions);


function Twitter(options) {
  options = options || {};
  this.options = {};
  this.options.test = options.test || false;
  delete options.test;
  this.client = new twit(options);
}


var promisedGet = function(url, params) {
  var self = this;
  return new Promise(function(resolve, reject) {
    params = params || {};
    self.client.get(url, params, function(error, data, response) {
      if (error) {
        return reject(twitterError.process.call(this, error));
      } else {
        return resolve(data, response);
      }
    });
  });
};


Twitter.prototype.get = function(url, params) {
  if (this.options.test === true) {
    return promisedGet.call(this, url, params);
  } else {
    return throttle.add(promisedGet.bind(this, url, params));
  }
};


Twitter.prototype.show = function(params) {
  var path = "/statuses/show.json?id=" + params.id;
  return this.get(path, params);
};


Twitter.prototype.post = function(url, params) {
  return new Promise(function(resolve, reject) {
    params = params || {};
    this.client.post(url, params, function(error, data, response) {
      if (error) {
        return reject(error);
      } else {
        return resolve(data, response);
      }
    });
  });
};


Twitter.prototype.stream = function(url, params) {
  return new Promise(function(resolve, reject) {
    params = params || {};
    this.client.stream(url, params, function(error, data, response) {
      if (error) {
        return reject(error);
      } else {
        return resolve(data, response);
      }
    });
  });
};


module.exports = Twitter;

@@ -28,24 +28,51 @@
 './error'),%0A
+    _ = require('lodash'),%0A
     twit = r
@@ -1211,32 +1211,732 @@
 , params);%0A%7D;%0A%0A%0A
+Twitter.prototype.lookup = function(params) %7B%0A  var self = this;%0A  var ids = _.chunk(params.id, 100);%0A  delete params.id;%0A%0A  return Promise.resolve(ids)%0A  .map(function(ids) %7B%0A    var path = %22/statuses/lookup.json?id=%22 + ids;%0A    return self.get(path, params)%0A    .then(function(res) %7Breturn %7B data: res %7D;%7D)%0A    .catch(function(e)  %7Breturn %7B error: e %7D;%7D);%0A  %7D).reduce(function(obj, res) %7B%0A    if (res.data) %7B%0A      obj.data.push(res.data);%0A    %7D%0A    if (res.errors) %7B%0A      obj.errors.push(res.error);%0A    %7D%0A    return obj;%0A  %7D, %7Bdata: %5B%5D, errors: %5B%5D%7D)%0A  .then(function(result) %7B%0A    result.data = _.flatten(result.data);%0A    result.errors = _.flatten(result.errors);%0A    return result;%0A  %7D);%0A%7D;%0A%0A%0A
 Twitter.prototyp

Add lookup API method.