Permalink
Browse files

Added first subscription method, updated tests

  • Loading branch information...
1 parent 4b0134b commit fec57bf3de712a15b43831d47c5e55acdc67c684 @andzdroid committed Jun 11, 2011
Showing with 64 additions and 2 deletions.
  1. +17 −1 lib/posterous.js
  2. +2 −0 tests/auth.js
  3. +42 −0 tests/subscriptions.js
  4. +3 −1 tests/user.js
View
@@ -80,7 +80,7 @@ Posterous.prototype.auth = function getAuthKey(callback) {
}
//Save api token
- t.setToken(result.api_token);
+ t._token = result.api_token;
callback(null, result.api_token);
});
@@ -100,6 +100,22 @@ Posterous.prototype.getUser = function getCurrentUser(callback) {
//Subscriptions
+//getSubscriptions([page number], callback)
+//Use as getSubscriptions(2, callback) for page 2 of subscriptions
+//Or getSubscriptions(callback) for page 1 of subcriptions
+Posterous.prototype.getSubscriptions = function getSubscriptions(page, callback) {
+ if (callback == undefined) {
+ callback = page;
+ page = 1;
+ }
+
+ this.request('GET', 'users/me/subscriptions', {page: page}, function(err, result) {
+ if (err) {
+ return callback(err);
+ }
+ callback(null, result);
+ });
+};
module.exports = Posterous;
View
@@ -5,6 +5,7 @@ module.exports['API Token'] = function(test) {
//To test, add your posterous email/password
var posterous = new Posterous(config.user, config.pass);
+ console.log('Fetching api token...');
posterous.auth(function(err, result) {
//Don't expect an error
test.ok(!err, 'An error occurred: ' + err);
@@ -21,6 +22,7 @@ module.exports['Bad Auth'] = function(test) {
//Make a bad api token request with no username/password
var posterous = new Posterous('', '');
+ console.log('Fetching api token...');
posterous.auth(function(err, result) {
//Expect an error
test.ok(err);
View
@@ -0,0 +1,42 @@
+var Posterous = require('../index');
+var config = require('./config');
+
+module.exports['Subscribed 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 your username/password in config/index.js');
+ }
+
+ console.log('Fetching page 1 of subscriptions...');
+ posterous.getSubscriptions(function(err, result) {
+ test.ok(!err, 'An error occurred: ' + err);
+
+ test.ok(result, 'Could not retrieve the user\'s subscriptions');
+
+ test.done();
+ });
+ });
+};
+
+module.exports['Subscribed Sites Page 2'] = 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 your username/password in config/index.js');
+ }
+
+ console.log('Fetching page 2 of subscriptions...');
+ posterous.getSubscriptions(2, function(err, result) {
+ test.ok(!err, 'An error occurred: ' + err);
+
+ test.ok(result, 'Could not retrieve page 2 of the user\'s subscriptions');
+
+ test.done();
+ });
+ });
+};
View
@@ -4,12 +4,14 @@ var config = require('./config');
module.exports['Current User'] = 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 your username/password in config.js');
+ test.ok(!err, 'Could not get api token, check your username/password in config/index.js');
return test.done();
}
+ console.log('Fetching user details...');
posterous.getUser(function(err, result) {
test.ok(!err, 'An error occurred: ' + err);

0 comments on commit fec57bf

Please sign in to comment.