Skip to content

Commit

Permalink
Merge pull request #34 from rakyll/missing-listings
Browse files Browse the repository at this point in the history
pubsub: Adding topic listing
  • Loading branch information
silvolu committed Jul 24, 2014
2 parents 1f8ca9b + 2af89bf commit 38ce51d
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion lib/pubsub/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,34 @@ Connection.prototype.subscribe = function(opts, opt_callback) {
});
};

// TODO(jbd): Add listTopics.
/**
* Lists topics.
* @param {string} query.pageToken Page token.
* @param {Number} query.maxResults Max number of results to return.
* @param {Function} callback Callback function.
*/
Connection.prototype.listTopics = function(query, callback) {
var that = this;
if (arguments.length < 2) {
callback = query;
query = {};
}
var q = util.extend({}, query);
q.query = 'cloud.googleapis.com/project in (' + this.fullProjectName_() + ')';
this.makeReq('GET', 'topics', q, true, function(err, result) {
if (err) { return callback(err); }
var items = result.topic || [];
var topics = items.map(function(item) {
return new Topic(that, item.name);
});
var nextQuery = null;
if (result.nextPageToken) {
nextQuery = q;
nextQuery.pageToken = result.nextPageToken;
}
callback(null, topics, nextQuery);
});
};

/**
* Gets a topic.
Expand Down

0 comments on commit 38ce51d

Please sign in to comment.