Saucisse
A tiny Node.js module to share on social networks
Only have a few simple commands Create a new instance
saucisse = new Saucisse(myConfig)
Post a tweet
saucisse.tweet "This is a saucisse tweet", console.log
Post a facebook message
saucisse.fb "This is a saucisse facebook message", console.log
Dependencies
We need an oauth authentication library to authenticate on twitter API.
Oauth = require'oauth'OAuthhttps = require 'https'
Let's do it
Our main module class Saucisse
: @options = options
Configuration part
There's a lot of configuration happening there
To get an app access token for facebook, cf : Publishing with an access token
if optionstwitter? throw "Missing twitter key" if not optionstwitterconsumer_key? throw "Missing twitter secret" if not optionstwitterconsumer_secret? throw "Missing twitter token" if not optionstwitteraccess_token? throw "Missing twitter token secret" if not optionstwitteraccess_token_secret? @twitterOauth = 'http://twitter.com/oauth/request_token' 'http://twitter.com/oauth/access_token' @optionstwitterconsumer_key @optionstwitterconsumer_secret '1.0A' null 'HMAC-SHA1' if optionsfacebook? throw "Missing app access token" if not optionsfacebookaccess_token? throw "Missing facebook graph id" if not optionsfacebookgraph_id?
twitter methods
Send a tweet.
Just take the text of the tweet as a parameter
: data = status : text @twitterOauthpost 'http://api.twitter.com/1/statuses/update.json' @optionstwitteraccess_token @optionstwitteraccess_token_secret data doneerrJSONparseresp
fb methods
Send a facebook message.
on the graphid configured for this instance Just take the text as a parameter
: postData = "message=" postData += "&access_token=" opts = host : "graph.facebook.com" port : 443 path : "//feed" method : "POST" headers: 'Content-Type' : 'application/x-www-form-urlencoded' 'Content-Length' : postDatalength req = httpsrequest opts ressetEncoding 'utf-8' reson 'data' done nullJSONparsechunk reqwrite postData reqend
Public methods
module.exports = Saucisse