Permalink
Browse files

- very simple NNTP client for article grabbing - not yet tested with …

…all error conditions/etc - skeleton for Queue
  • Loading branch information...
1 parent 70f31ee commit 115709dc77e84caa111f434f1220d0b364061eb5 @benvanik committed Jan 18, 2010
Showing with 406 additions and 0 deletions.
  1. +2 −0 .gitignore
  2. +46 −0 examples/client-ex.js
  3. +11 −0 examples/example-config.js.EXAMPLE
  4. +20 −0 examples/queue-ex.js
  5. +317 −0 lib/nntp/Client.js
  6. +8 −0 lib/nntp/Queue.js
  7. +2 −0 lib/node-nntp.js
View
@@ -0,0 +1,2 @@
+
+/examples/example-config.js
View
@@ -0,0 +1,46 @@
+var sys = require("sys");
+var nntp = require("../lib/node-nntp")
+var exconfig = require("./example-config")
+
+var client = new nntp.Client();
+client.connect(exconfig.host, exconfig.port).addCallback(function() {
+ // if username provided, attempt to authenticate
+ if (exconfig.username) {
+ client.authenticate(
+ exconfig.username, exconfig.password
+ ).addCallback(function(responseCode, responseLine) {
+ onReady();
+ }).addErrback(function() {
+ sys.puts("failed to authenticate");
+ client.quit().wait();
+ });
+ } else {
+ onReady();
+ }
+}).addErrback(function() {
+ sys.puts("failed to connect");
+});
+
+function onReady() {
+ sys.puts("connected!");
+ // pipeline request of the given articles
+ var messageIDs = [
+ "<hith8d$go$1@newshub.netvisao.pt>",
+ "<06BTm.317446$BL3.253161@en-nntp-08.dc1.easynews.com>",
+ "<26BTm.317447$BL3.300217@en-nntp-08.dc1.easynews.com>"
+ ];
+ var outstanding = messageIDs.length;
+ for (var n = 0; n < messageIDs.length; n++) {
+ client.getArticle(
+ messageIDs[n]
+ ).addCallback(function(responseCode, responseLine, headers, message) {
+ sys.puts("message received!");
+ // TODO: do something meaningful here
+ outstanding--;
+ if (outstanding == 0) {
+ // done
+ client.quit().wait();
+ }
+ });
+ }
+}
@@ -0,0 +1,11 @@
+// hostname of nntp server - like 'news.giganews.com'
+exports.host = "MY.NEWSSERVER.COM";
+
+// port to access server on - either omit (for default of 119) or specify a non-SSL port
+exports.port = 119;
+
+// username to use when authenticating if authentication is required
+exports.username = "USERNAME";
+
+// password to use when authenticating if required
+exports.password = "PASSWORD";
View
@@ -0,0 +1,20 @@
+var sys = require("sys");
+var nntp = require("../lib/node-nntp")
+var exconfig = require("./example-config")
+
+var queue = new nntp.Queue();
+queue.connect({
+ host: exconfig.host,
+ port: exconfig.port,
+ username: exconfig.username,
+ password: exconfig.password,
+ connectionCount: 4
+}).addCallback(function() {
+ onReady();
+}).addErrback(function() {
+ sys.puts("failed to connect");
+});
+
+function onReady() {
+
+}
Oops, something went wrong.

0 comments on commit 115709d

Please sign in to comment.