nodejitsu/pkgcloud — pull request #112 by kenperkins (2013-04-23 21:55:23+00:00)
Title: [refactor] Updating client.request to take options and callback

With this change I've standardized all internal `request`, `query`, and `xmlRequest` methods to use the standard node convention of `function(options, callback)` where callback takes `err and data`.

For example:

```javascript
exports.disableServerBackup = function (server, callback) {
var serverId = server instanceof base.Server ? server.id : server,
disableUrl = ['servers', serverId, 'backup_schedule'].join('/');

this.request({
method: 'DELETE',
path: disableUrl
}, function (err, body, res) {
return err
? callback(err)
: callback(null, res);
});
};
```

As of now, `options` are passed into `Client._doRequest(options, callback)` where they are whitelisted into an official `opts` object for use when passing to the `request` package for creation of the request stream.

## Simplifications

There have been a number of changes to make parts of the internal API more explicit and simple.

* `Client.request` takes an `options` argument, in lieu of having arguments derived for each call.
* `options.path` in the aforementioned `Client.request` is always a string. There were a number of confusing cases with arrays being sliced, popped, joined, etc.
* `Client.url()` has been changed to `Client.getUrl(options)` and now takes options, instead of implicit arguments. These options can be leveraged based on the specifics of each client.
* Explicitly leverage the `qs` object literal for requests with querystring paramenters, in lieu of adding these to the uri by hand. This was especially confusing in some cases where `path: [true]` became `+ '?format=json'`.
* fixed multiple cases in current tests where errors were being squashed by incorrect test code