Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

test added

  • Loading branch information...
commit d3a800b4ef6673222b18be806d7df7b551898e5c 1 parent 5d9500a
@masylum authored
View
10 Readme.md
@@ -34,3 +34,13 @@ Params must contain the token.
);
});
});
+
+## Test
+
+To test and see this module working:
+
+ * copy the test folder
+ * set up the keys and password of your app
+ * run it _node test/client.js_
+ * Add 127.0.0.1 twitter-js.com at your hosts file
+ * Open your browser at localhost:3003
View
5 lib/twitter_client.js
@@ -13,7 +13,7 @@ var url = require("url"),
querystring = require("querystring");
module.exports = function (api_key, api_secret, redirect) {
- var client = {version: '0.0.2'},
+ var client = {version: '0.0.3'},
// PRIVATE
oAuth = new OAuth(
@@ -69,7 +69,7 @@ module.exports = function (api_key, api_secret, redirect) {
var parsedUrl = url.parse(req.url, true);
// Acces token
- if (parsedUrl.query && parsedUrl.query.oauth_token && req.session.auth.twitter_oauth_token_secret) {
+ if (parsedUrl.query && parsedUrl.query.oauth_token && req.session.auth && req.session.auth.twitter_oauth_token_secret) {
oAuth.getOAuthAccessToken(
parsedUrl.query.oauth_token,
@@ -91,6 +91,7 @@ module.exports = function (api_key, api_secret, redirect) {
function (error, oauth_token, oauth_token_secret, oauth_authorize_url, additionalParameters) {
if (!error) {
req.session.twitter_redirect_url = req.url;
+ req.session.auth = req.session.auth || {};
req.session.auth.twitter_oauth_token_secret = oauth_token_secret;
req.session.auth.twitter_oauth_token = oauth_token;
res.redirect("http://api.twitter.com/oauth/authorize?oauth_token=" + oauth_token);
View
12 test/client.jade
@@ -0,0 +1,12 @@
+h1 Test, twitter-js
+form(action: '/message', method: 'post')
+ label token
+ input(name: 'oauth_token', value: token && token.oauth_token)
+ br
+ label token secret
+ input(name: 'oauth_token_secret', value: token && token.oauth_token_secret)
+ br
+ label message
+ textarea(name: 'message')
+ br
+ input(type: 'submit') Post
View
49 test/client.js
@@ -0,0 +1,49 @@
+/**
+ * IMPORTANT:
+ * In order to make this test work add
+ * 127.0.0.1 twitter-js to your /etc/hosts
+ */
+
+var express = require('express'),
+ connect = require('connect');
+
+// Prevent reap timer
+var twitterClient = require('./../')(
+ 'yourKey',
+ 'yourPass',
+ 'http://twitter-js.com:3003/'
+ ),
+ app = express.createServer(
+ connect.bodyDecoder(),
+ connect.cookieDecoder(),
+ connect.session()
+ );
+
+app.set('views', __dirname);
+
+app.get('/', function (req, res) {
+ twitterClient.getAccessToken(req, res, function (error, token) {
+ res.render('client.jade', {
+ layout: false,
+ locals: {
+ token: token
+ }
+ });
+ });
+});
+
+app.post('/message', function (req, res) {
+ twitterClient.apiCall(
+ 'POST',
+ '/statuses/update.json',
+ {token: {oauth_token_secret: req.param('oauth_token_secret'), oauth_token: req.param('oauth_token'), status: req.param('message')}},
+ function (error, result) {
+ console.log(error);
+ console.log(result);
+ res.render('done.jade', {layout: false});
+ }
+ );
+});
+
+app.listen(3003);
+
View
0  test/done.jade
No changes.
Please sign in to comment.
Something went wrong with that request. Please try again.