Skip to content

Commit

Permalink
Add search(), minor documentation updates.
Browse files Browse the repository at this point in the history
  • Loading branch information
jdub committed Dec 24, 2010
1 parent 3612f7c commit 9bf5b25
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
14 changes: 10 additions & 4 deletions 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

Expand All @@ -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)

Expand Down Expand Up @@ -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:
Expand All @@ -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) {
Expand All @@ -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

Expand Down
23 changes: 20 additions & 3 deletions lib/twitter.js
Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
Expand All @@ -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
*/
Expand Down Expand Up @@ -174,7 +191,7 @@ Twitter.prototype.stream = function(method, params, callback) {


/*
* CONVENIENCE FUNCTIONS
* CONVENIENCE FUNCTIONS (not API stable!)
*/

// Timeline resources
Expand Down

0 comments on commit 9bf5b25

Please sign in to comment.