Node Bitbucket now includes access to sources.
Published on Oct 15, 2012A few hours ago I pushed version 0.0.3 of the bitbucket-api node.js module to npm.
In the new version I added access to the src end point via the sources(path, revision) method.
This method gives you access to the src resources .
These resources allow you to get access to information about files and directories in the repository as well as raw content from a file or folder structure.
Usage.
repo.sources('/package.json').info(function (err, result) {
//get access to the info for the package.json file
});
repo.sources('/').info(function (err, result) {
//get access to the info for the root folder
});
repo.sources('/package.json').raw(function (err, result) {
//gets the content of the package.json file
});
repo.sources('/').raw(function (err, result) {
//gets the content (as a string) of the root folder.
});
Instance methods
All callbacks follow the standard node signature cb(err, result).
info(cb)
The result is a literal with the data returned by the API.
raw(cb)
The result contains a data and a lines properties.
This only works for text files, binary files will return a 500 status code.
obj.data //Contains a string with the file raw content
obj.lines //Contains an array with the string split by '\n' characters.
In case of an error parsing the data at the moment we return a result with this form.
{
success: false,
status: 500 //Or other HTTP status code
}
This API will change in the next release and the module will use the err object to return any and all errors.