From 2af89bf33f400bca7229dc3aa5f0056fd96be8cf Mon Sep 17 00:00:00 2001 From: Burcu Dogan Date: Thu, 24 Jul 2014 12:09:30 -0700 Subject: [PATCH] pubsub: Adding topic listing. --- lib/pubsub/index.js | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/lib/pubsub/index.js b/lib/pubsub/index.js index 30ef4715b63..227bbdb7d7b 100644 --- a/lib/pubsub/index.js +++ b/lib/pubsub/index.js @@ -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.