Skip to content

Commit

Permalink
add Consumer object.
Browse files Browse the repository at this point in the history
  • Loading branch information
benoitc committed Jun 30, 2010
1 parent 2454ee4 commit c07b841
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 9 deletions.
12 changes: 10 additions & 2 deletions NOTICE
Expand Up @@ -9,7 +9,6 @@ file for the complete license.

mime.js
-------

under MIT License.

copyright TJ Holowaychuk <tj@vision-media.ca>
Expand All @@ -33,4 +32,13 @@ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
OTHER DEALINGS IN THE SOFTWARE.

base64.js
---------
Copyright (C) 1999 Masanao Izumo <iz@onicos.co.jp>
Version: 1.0
LastModified: Dec 25 1999
This library is free. You can redistribute it and/or modify it.

Modified by Dan Webb not to require Narwhal's binary library */
43 changes: 43 additions & 0 deletions lib/noddycouch.js
Expand Up @@ -427,7 +427,50 @@ Database.prototype.copyDoc = function() {

}

var Consumer = function(uri) {
resource.Resource.call(this, uri);

}
sys.inherits(Consumer, resource.Resource);

Consumer.prototype.wait = function(params) {
var self = this;
var params = params || {}

params["feed"] = "continuous";

this.get("_changes", {
params: params,
startResponse: function(response) {

var get_line = function(chunk) {
if (chunk != "\n")
try {
var change = JSON.parse(chunk);
if (!change.id) {
self.emit("end", change);
response.removeListener("data", get_line);
} else {
self.emit("change", change);
return
}

} catch(e) {}
}

response
.addListener("data", get_line)
.addListener("end", function() {
self.emit("end", "");
response.removeListener("data", get_line);
});
}
});
}



exports.Server = Server;
exports.Uuids = Uuids;
exports.Database = Database;
exports.Consumer = Consumer;
10 changes: 4 additions & 6 deletions lib/noddycouch/base64.js
@@ -1,9 +1,7 @@
/* Copyright (C) 1999 Masanao Izumo <iz@onicos.co.jp>
* Version: 1.0
* LastModified: Dec 25 1999
* This library is free. You can redistribute it and/or modify it.
*/
/* Modified by Dan Webb not to require Narwhal's binary library */
/*
* This file is part of noddycouch released under the MIT license.
* See the NOTICE for more information. */


var encodeChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
var decodeChars = [
Expand Down
5 changes: 4 additions & 1 deletion lib/noddycouch/mime.js
@@ -1,4 +1,7 @@
// Express - Mime - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)
/*
* This file is part of noddycouch released under the MIT license.
* See the NOTICE for more information. */


var types = {
'3gp' : 'video/3gpp',
Expand Down
13 changes: 13 additions & 0 deletions test_consumer.js
@@ -0,0 +1,13 @@
var sys = require("sys"),
Consumer = require('./lib/noddycouch').Consumer;

var c = new Consumer("http://127.0.0.1:5984/testdb");

c.addListener("change", function(change) {
sys.puts("Got change "
+ "seq: " + change.seq
+ " on docid: " + change.id
+ " rev: " + change.changes[0].rev);
})

c.wait({heartbeat: true})

0 comments on commit c07b841

Please sign in to comment.