From 9bf5b25b1976016a864312e423c20bd0fe80a3c6 Mon Sep 17 00:00:00 2001 From: Jeff Waugh Date: Fri, 24 Dec 2010 17:03:56 +1100 Subject: [PATCH] Add search(), minor documentation updates. --- README.md | 14 ++++++++++---- lib/twitter.js | 23 ++++++++++++++++++++--- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 36dce7d2..41c13605 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ Asynchronous Twitter client API for node.js =========================================== -`node-twitter` aims to provide a complete, asynchronous client library for Twitter (and other compliant endpoints), including REST, stream and search APIs. It was inspired by, and uses some code from, technoweenie's `twitter-node`. +[node-twitter](https://github.com/jdub/node-twitter) aims to provide a complete, asynchronous client library for Twitter (and other compliant endpoints), including REST, stream and search APIs. It was inspired by, and uses some code from, technoweenie's [twitter-node](https://github.com/technoweenie/twitter-node). ## Requirements @@ -12,7 +12,7 @@ You can install node-twitter and its dependencies with npm: `npm install twitter ## Getting started -It's early days for `node-twitter`, so I'm going to assume a fair amount of knowledge for the moment. Better documentation to come as we head towards a stable release. +It's early days for node-twitter, so I'm going to assume a fair amount of knowledge for the moment. Better documentation to come as we head towards a stable release. ### Setup API (stable) @@ -48,6 +48,12 @@ Note that all functions may be chained: } ); +### Search API (unstable, may change) + + twit.search('nodejs OR #node', function(data) { + sys.puts(sys.inspect(data)); + }); + ### Streaming API (stable) The stream() callback receives a Stream-like EventEmitter: @@ -58,7 +64,7 @@ The stream() callback receives a Stream-like EventEmitter: }); }); -`node-twitter` also supports user and site streams: +node-twitter also supports user and site streams: twit.stream('user', {track:'nodejs'}, function(stream) { stream.on('data', function (data) { @@ -71,7 +77,7 @@ The stream() callback receives a Stream-like EventEmitter: ## Contributors - [Jeff Waugh](http://github.com/jdub) (author) -- [rick](http://github.com/technoweenie) (parser.js and, of course, `twitter-node`!) +- [rick](http://github.com/technoweenie) (parser.js and, of course, twitter-node!) ## TODO diff --git a/lib/twitter.js b/lib/twitter.js index 93ca5d3b..6621bb4d 100644 --- a/lib/twitter.js +++ b/lib/twitter.js @@ -67,7 +67,10 @@ Twitter.prototype.get = function(url, params, callback) { params = null; } - this.oauth.get(this.options.rest_base + url, + if (url.charAt(0) == '/') + url = this.options.rest_base + url; + + this.oauth.get(url, this.options.access_token_key, this.options.access_token_secret, function(error, data, response) { @@ -104,7 +107,10 @@ Twitter.prototype.post = function(url, content, content_type, callback) { content_type = null; } - this.oauth.post(this.options.rest_base + url, + if (url.charAt(0) == '/') + url = this.options.rest_base + url; + + this.oauth.post(url, this.options.access_token_key, this.options.access_token_secret, content, content_type, @@ -129,6 +135,17 @@ Twitter.prototype.post = function(url, content, content_type, callback) { } +/* + * SEARCH (not API stable!) + */ +Twitter.prototype.search = function(q, params, callback) { + var url = this.options.search_base + + '/search.json?' + querystring.stringify({q:q}); + this.get(url, params, callback); + return this; +} + + /* * STREAM */ @@ -174,7 +191,7 @@ Twitter.prototype.stream = function(method, params, callback) { /* - * CONVENIENCE FUNCTIONS + * CONVENIENCE FUNCTIONS (not API stable!) */ // Timeline resources