Permalink
Browse files

Added list sites method

  • Loading branch information...
1 parent b10b6e4 commit ca276a1fb2af3c2afd3c61d244a7884b8115d48e @andzdroid committed Jun 11, 2011
Showing with 40 additions and 0 deletions.
  1. +14 −0 lib/posterous.js
  2. +26 −0 tests/sites.js
View
@@ -118,6 +118,8 @@ Posterous.prototype.getSubscriptions = function getSubscriptions(page, callback)
});
};
+//Subscription posts
+//Use the same way as getSubscriptions
Posterous.prototype.getSubscriptionPosts = function getSubscriptionPosts(page, callback) {
if (callback == undefined) {
callback = page;
@@ -134,5 +136,17 @@ Posterous.prototype.getSubscriptionPosts = function getSubscriptionPosts(page, c
};
+//Sites
+Posterous.prototype.getSites = function getSites(callback) {
+ this.request('GET', 'sites', null, function(err, result) {
+ if (err) {
+ return callback(err);
+ }
+
+ callback(null, result);
+ });
+};
+
+
module.exports = Posterous;
View
@@ -0,0 +1,26 @@
+var Posterous = require('../index');
+var config = require('./config');
+
+module.exports['Listing Sites'] = function(test) {
+ var posterous = new Posterous(config.user, config.pass);
+
+ console.log('Fetching api token...');
+ posterous.auth(function(err, result) {
+ if (err) {
+ test.ok(!err, 'Could not get api token, check yoru username/password in config/index.js');
+ }
+
+ console.log('Fetching sites...');
+ posterous.getSites(function(err, result) {
+ test.ok(!err, 'An error occurred: ' + err);
+
+ test.ok(result, 'Could not retrieve list of sites.');
+
+ if (result[0] && "name" in result[0]) {
+ console.log('Site name: ' + result[0].name);
+ }
+
+ test.done();
+ });
+ });
+};

0 comments on commit ca276a1

Please sign in to comment.