index.js

'use strict';

twitter-rest-lite

A lightweight Twitter REST-API library with OAuth and basic POST/GET API requests modules.

For more convenient methods you should check twitter-rest.

var API = require('./lib/api');
var OAuth = require('./lib/oauth');

Quick Usage

var TwitterLib = require('twitter-rest-list'),
    twitter = new TwitterLib({
      consumer_key: "blahblahblah",
      consumer_secret: "blahblahblah",
      token: 'blah',
      token_secret: 'blah',
      callback: "randomurl"
    });

twitter.api.get('/statuses/user_timeline.json', {
  screen_name: 'twitter',
  count: 1
}, function (err, response) {
  if (err) throw err;

  console.log(response);
});

/ #### PLEASE BE WARNED

Using the complete require is only recommended if token and token_secret already exists.

Otherwise the API module will throw an Error since it does need those two variables to do any of the calls./

What’s available on the initialized object?

Initializes two objects: api and oauth. You can initialize them separated too (this is my preferred method).

Parameters to initialize any of the exported Objects

All the exported functions expect an Object with the params:

Base URIs for Twitter API (These should be overwritten if to be used with a compatible API)

var uri = {
  base: 'https://api.twitter.com/1.1',
  search: 'https://api.twitter.com/1.1/search'
};

Usage

var TwitterLib = require('twitter-rest-lite'),
    keys = {consumer_key: '...', consumer_secret: '...', token: '...', token_secret: '...' callback: '...'},
    twitter = new TwitterLib(keys);

/* twitter.oauth object */
twitter.oauth.requestToken( /* ... */ );
twitter.oauth.accessToken( /* ... */ );
twitter.oauth.authenticate( /* ... */ );
twitter.oauth.authorize( /* ... */ );

/* twitter.api object */
twitter.api.get( /* ... */ );
twitter.api.post( /* ... */ );

PLEASE BE WARNED

Using the complete require is only recommended if token and token_secret already exists.

Otherwise the API module will throw an Error since it does need those two variables to do any of the calls.

Code

module.exports = function(opts) {
  return {
    API: new API(uri, opts),
    OAuth: new OAuth(uri, opts)
  };
};

OAuth Quick Usage

var TwitterLib = require('twitter-rest-lite'),
toauth = new TwitterLib.OAuth({
  consumer_key: 'blah',
  consumer_secret: 'blah',
  callback: 'randomurl'
});

toauth.requestToken(function (err, response) {
  if (err)
    throw err;

  console.log(response);
});

More on the OAuth module documentation.

Code

module.exports.OAuth = module.exports.oauth = function(opts) {
  return new OAuth(uri, opts);
};

API Quick Usage

var TwitterLib = require('twitter-rest-lite'),
tapi = new TwitterLib.API({
  consumer_key: 'blah',
  consumer_secret: 'blah',
  token: 'blah',
  token_secret: 'blah',
  callback: 'randomurl'
 });

 tapi.get('/statuses/user_timeline.json', {
   screen_name: 'twitter'
 }, function (err, response) {
   if (err)
     throw err;

   console.log(response);
 });

More on the API module documentation.

Code

module.exports.API = module.exports.api = function(opts) {
  return new API(uri, opts);
};

module.exports.helper = require('./lib/helper');
h