Created
November 5, 2013 19:24
-
-
Save megatolya/7324643 to your computer and use it in GitHub Desktop.
twitter post module
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Модуль, отвечающий за отправку сообщений в твиттер | |
*/ | |
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