Skip to content

Instantly share code, notes, and snippets.

@megatolya
Created November 5, 2013 19:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save megatolya/7324643 to your computer and use it in GitHub Desktop.
Save megatolya/7324643 to your computer and use it in GitHub Desktop.
twitter post module
/**
* Модуль, отвечающий за отправку сообщений в твиттер
*/
var Twitter = require('node-twitter');
var path = require('path');
var restClient = new Twitter.RestClient(
// ;)
);
var DEFAULT_STATUS = 'У нас гости!';
/*
* Отправка фотографии в твиттер
*
* @param {Object} params хеш вида:
* photo {String} абсолютный путь до картинки
* status {String} сообщение (необяз.)
* @param {Function} callback колбек (необяз.)
*
* @todo сделать возможность отправки без фото
*/
module.exports.post = function(params, callback) {
// @link https://github.com/istrategylabs/node-twitter#upload
restClient.statusesUpdateWithMedia({
'status': params.status || DEFAULT_STATUS,
'media[]': path.resolve(params.photo)
}, function(error, res) {
if (error) {
if (callback)
return callback(error);
else
throw error;
}
callback && callback(null, res);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment