Skip to content

Instantly share code, notes, and snippets.

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 marcooliveira/10012552 to your computer and use it in GitHub Desktop.
Save marcooliveira/10012552 to your computer and use it in GitHub Desktop.
fs = require('fs')
path = require('path')
request = require('request')
class twitter_update_with_media
constructor: (@auth_settings) ->
@api_url = 'https://api.twitter.com/1.1/statuses/update_with_media.json'
post: (status, file_path, callback) ->
r = request.post(@api_url, oauth:@auth_settings, callback)
form = r.form()
form.append('status', status)
form.append('media[]', fs.createReadStream(path.normalize(file_path)))
module.exports = twitter_update_with_media
// Generated by CoffeeScript 1.6.3
(function() {
var fs, path, request, twitter_update_with_media;
fs = require('fs');
path = require('path');
request = require('request');
twitter_update_with_media = (function() {
function twitter_update_with_media(auth_settings) {
this.auth_settings = auth_settings;
this.api_url = 'https://api.twitter.com/1.1/statuses/update_with_media.json';
}
twitter_update_with_media.prototype.post = function(status, file_path, callback) {
var form, r;
r = request.post(this.api_url, {
oauth: this.auth_settings
}, callback);
form = r.form();
form.append('status', status);
return form.append('media[]', fs.createReadStream(path.normalize(file_path)));
};
return twitter_update_with_media;
})();
module.exports = twitter_update_with_media;
}).call(this);
twitter_update_with_media = require 'twitter_update_with_media'
tuwm = new twitter_update_with_media({
consumer_key: '...'
consumer_secret: '...'
token: '...'
token_secret: '...'
})
tuwm.post('This is a test', '/path_to_image.png', (err, response) ->
console.log(err) if err
console.log(response)
)
var twitter_update_with_media = require('twitter_update_with_media');
var tuwm = new twitter_update_with_media({
consumer_key: '...',
consumer_secret: '...',
token: '...',
token_secret: '...'
});
tuwm.post('This is a test', '/path_to_image.png', function(err, response) {
if (err) {
console.log(err);
}
console.log(response);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment