'use strict';

Module: Timelines

Convenience methods for Timelines actions.

Methods

Usage

var TwitterLib = require('twitter-rest');
var timeline = new TwitterLib.Timelines(var_with_config);

timeline.mentions(params, callback);
timeline.user(params, callback);
timeline.home(params, callback);
timeline.retweets(params, callback);

Constructor

Parameters

Returns

An Object with methods mentions, user, home and retweets.

Code

function Timelines(uri, opts) {
  this.uri = uri;
  this.opts = opts;

  var tt = require('twitter-rest-lite');

  this.api = tt.API(this.opts);
}

Public: get user’s mentions

This only works with oauth_token from the same user.

Parameters

Returns

Returns a callback with an Error object as first parameter if there was any (otherwise just null) and an Array with tweets as second parameter.

Example

var params = { count: 1 };
timeline.mentions(params, function (err, res) {
  if (err)
    throw err;

  console.log(res);
});

Code

Timelines.prototype.mentions = function(params, callback) {
  var self = this;

  if (params == null)
    params = {};

  self.api.get('/statuses/mentions_timeline.json', params, callback);
};

Public: get selected user’s timeline

Parameters

Returns

Returns a callback with an Error object as first parameter if there was any (otherwise just null) and an Array with tweets as second parameter.

Example

timeline.user({
  screen_name: 'random'
}, function (err, res) {
  if (err)
    throw err;

  console.log(res);
});

Code

Timelines.prototype.user = function(params, callback) {
  var self = this;

  if ((params.screen_name == null) && (params.user_id == null)) {
    return callback(new Error(
      'Twitter:Timelines.user requires either screen_name or user_id'
    ));
  }

  self.api.get('/statuses/user_timeline.json', params, callback);
};

Public: get user’s home timeline

This only works with the oauth_token from the same user.

Parameters

Returns

Returns a callback with an Error object as first parameter if there was any (otherwise just null) and an Array with tweets as second parameter.

Example

timeline.home(null, function (err, res) {
  if (err)
    throw err;

  console.log(res);
});

Code

Timelines.prototype.home = function(params, callback) {
  var self = this;

  if (params == null)
    params = {};

  self.api.get('/statuses/home_timeline.json', params, callback);
};

Public: get user’s retweets

This only works with the oauth_token from the same user.

Parameters

Returns

Returns a callback with an Error object as first parameter if there was any (otherwise just null) and an Array with tweets as second parameter.

Example

timeline.retweets({}, function (err, response) {
  if (err)
    throw err;

  console.log(response);
});

Code

Timelines.prototype.retweets = function(params, callback) {
  var self = this;

  if (params == null)
    params = {};

  self.api.get('/statuses/retweets_of_me.json', params, callback);
};

module.exports = Timelines;
h