'use strict';
Convenience methods for Tweets actions directly from Twitter’s API 1.1.
var Tweets;
module.exports = Tweets = (function() {
function Tweets(uri, opts) {
this.uri = uri;
this.opts = opts;
var tt = require('twitter-rest-lite');
this.api = tt.API(this.opts);
}
A callback with an Error object as first parameter if there was any
(otherwise just null
) and an Array with tweets as second parameter.
Tweets.prototype.retweets = function(id, params, callback) {
var self = this;
if (id == null) {
return callback(new Error(
'Twitter:Tweets.retweets() requires an ID to be provided'
));
}
self.api.get('/statuses/retweets/' + id + '.json', params, callback);
};
Returns a callback with an Error object as first parameter if there was any
(otherwise just null
) and a Tweet object as second parameter.
Tweets.prototype.show = function(id, params, callback) {
var self = this;
if (id == null) {
return callback(new Error(
'Twitter:Tweets.show() requires and ID to be provided'
));
}
self.api.get('/statuses/show/' + id + '.json', params, callback);
};
This only works with oauth_token
from the same user.
Returns a callback with an Error object as first parameter if there was any
(otherwise just null
) and a Tweet object of the removed status as second
parameter.
Tweets.prototype.destroy = function(id, params, callback) {
var self = this;
if (id == null) {
return callback(new Error(
'Twitter:Tweets.destroy() requires an ID to be provided'
));
}
self.api.post('/statuses/destroy/' + id + '.json', params, callback);
};
This only works with oauth_token
from the same user.
Tweets.prototype.update = function(params, callback) {
var self = this;
if ((params == null) || (params.status == null) || (params.status === '')) {
return callback(new Error(
'Twitter:Tweets.update() requires params.status to be defined'
));
}
if (params.status.length > 140) {
return callback(new Error(
'Twitter:Tweets.update(): status is longer than 140 characters'
));
}
self.api.post('/statuses/update.json', params, callback);
};
Tweets.prototype.retweet = function(id, params, callback) {
var self = this;
if (id == null) {
return callback(new Error(
'Twitter:Tweets.retweet() requires an ID to be provided'
));
}
self.api.post('/statuses/retweet/' + id + '.json', params, callback);
};
Tweets.prototype.updateWithMedia = function() {
var self = this;
/* FIXME: IMPLEMENT! */
};
params
- Object with params:id
: [Required if url
is not given]url
: [Required if id
is not given]callback
- Callback Function Tweets.prototype.oembed = function(params, callback) {
var self = this;
if ((params.id == null) && (params.url == null)) {
return callback(new Error(
'Twitter:Tweets.oembed() requires either id or url on the params'
));
}
self.api.get('/statuses/oembed.json', params, callback);
};
params
- Object with params:id
callback
- Callback Function Tweets.prototype.retweeters = function(params, callback) {
var self = this;
if (params.id == null) {
return callback(new Error(
'Twitter:Tweets.retweeters() requires an id on the params'
));
}
self.api.get('/statuses/retweeters/ids.json', params, callback);
};
return Tweets;
})();