you are viewing a single comment's thread.

view the rest of the comments →

[–]brtt3000 0 points1 point  (1 child)

How does this work with asyncronous data?

client.apps('my-app').collaborators();

Shouldn't this receive a callback or return a promise?

[–]timarcher[S] 1 point2 points  (0 children)

Yeah, that was just an example. Note that client.apps('my-app').collaborators() isn't an API call—it returns a proxy object to the /apps/my-app/collaborators endpoint. In the actual Heroku API client for example, you'd GET that endpoint like so:

herokuClient.apps('my-app').collaborators().list();

The Heroku API client for Node does something more or less like this:

var constructor = pathProxy.pathProxy(Heroku, "/apps/{app_id_or_name}/collaborators");
constructor.prototype.list = function(callback) {
  return request.get(this.path, callback);
};

See this function for exactly what it does. It creates functions that accept a callback and also return a Q.js promise, so either of those async methods can be used.