Created
August 28, 2010 21:38
-
-
Save mbleigh/555612 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
require.paths.unshift './vendor' | |
Twitter = require './twitter' | |
# ... | |
app.get '/sign_in', (req, res)-> | |
Twitter.consumer.getOAuthRequestToken (error, token, secret, url, params)-> | |
# save it to the session | |
# Hard-coded URL for callback (OAuth 1.0) | |
app.get '/oauth/callback', (req, res)-> | |
Twitter.consumer.getOAuthAccessToken req.session['req.token'], req.session['req.secret'], (error, access_token, access_secret, params)-> | |
# voila, access token acquired |
This file contains hidden or 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
require.paths.unshift './vendor' | |
sys = require 'sys' | |
OAuth = require('oauth').OAuth | |
Consumer = new OAuth( | |
'http://api.twitter.com/oauth/request_token', | |
'http://api.twitter.com/oauth/access_token', | |
process.env.TWITTER_KEY, | |
process.env.TWITTER_SECRET, | |
'1.0', null, 'HMAC-SHA1' | |
) | |
Client = (token, secret)-> | |
this.token = token | |
this.secret = secret | |
Client.prototype.request = (method, path, callback)-> | |
url = "http://api.twitter.com/1#{path}" | |
sys.puts "[Twitter] Fetching #{path}" | |
Consumer.getProtectedResource url, method, this.token, this.secret, (error, data, response)-> | |
if error | |
sys.puts sys.inspect(error) | |
else | |
callback JSON.parse(data) | |
Client.prototype.get = (path, callback)-> | |
this.request 'GET', path, callback | |
exports.consumer = Consumer | |
exports.client = Client |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment