Skip to content

Commit 38ce51d

Browse files
committed
Merge pull request #34 from rakyll/missing-listings
pubsub: Adding topic listing
2 parents 1f8ca9b + 2af89bf commit 38ce51d

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

lib/pubsub/index.js

+28-1
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,34 @@ Connection.prototype.subscribe = function(opts, opt_callback) {
211211
});
212212
};
213213

214-
// TODO(jbd): Add listTopics.
214+
/**
215+
* Lists topics.
216+
* @param {string} query.pageToken Page token.
217+
* @param {Number} query.maxResults Max number of results to return.
218+
* @param {Function} callback Callback function.
219+
*/
220+
Connection.prototype.listTopics = function(query, callback) {
221+
var that = this;
222+
if (arguments.length < 2) {
223+
callback = query;
224+
query = {};
225+
}
226+
var q = util.extend({}, query);
227+
q.query = 'cloud.googleapis.com/project in (' + this.fullProjectName_() + ')';
228+
this.makeReq('GET', 'topics', q, true, function(err, result) {
229+
if (err) { return callback(err); }
230+
var items = result.topic || [];
231+
var topics = items.map(function(item) {
232+
return new Topic(that, item.name);
233+
});
234+
var nextQuery = null;
235+
if (result.nextPageToken) {
236+
nextQuery = q;
237+
nextQuery.pageToken = result.nextPageToken;
238+
}
239+
callback(null, topics, nextQuery);
240+
});
241+
};
215242

216243
/**
217244
* Gets a topic.

0 commit comments

Comments
 (0)