Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 46 additions & 1 deletion lib/pubsub/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,42 @@ function Connection(opts) {
});
}

// TODO(jbd): List subscriptions.
/**
* Lists subscriptions.
* @param {string} query.filterByTopic Returns subscriptions that are
* subscribed to the topic provided.
* @param {string} query.pageToken Page token.
* @param {Number} query.maxResults Max number of results to return.
* @param {Function} callback Callback function.
*/
Connection.prototype.listSubscriptions = function(query, callback) {
var that = this;
if (arguments.length < 2) {
callback = query;
query = {};
}
var q = util.extend({}, query);
q.query = q.filterByTopic
? 'pubsub.googleapis.com/topic in (' + this.fullTopicName_(q.filterByTopic) + ')'
: 'cloud.googleapis.com/project in (' + this.fullProjectName_() + ')';
delete q.filterByTopic;

this.makeReq('GET', 'subscriptions', q, true, function(err, result) {
if (err) {
return callback(err);
}
var items = result.subscription || [];
var subscriptions = items.map(function(item) {
return new Subscription(that, item.name);
});
var nextQuery = null;
if (result.nextPageToken) {
nextQuery = q;
nextQuery.pageToken = result.nextPageToken;
}
callback(null, subscriptions, nextQuery);
});
};

/**
* Subscribe with the provided options.
Expand Down Expand Up @@ -219,6 +254,16 @@ Connection.prototype.fullTopicName_ = function(name) {
});
};

/**
* Returns the fully qualified project name.
* Full name is in /projects/<projectId> form.
*/
Connection.prototype.fullProjectName_ = function() {
return util.format('/projects/{projectId}', {
projectId: this.id
});
};

// TOOD(jbd): Don't duplicate, unify this with bucket.makeReq.
Connection.prototype.makeReq = function(method, path, q, body, callback) {
var reqOpts = {
Expand Down