Skip to content
This repository was archived by the owner on Apr 6, 2021. It is now read-only.

Added PUT/DELETE methods #4

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
16 changes: 14 additions & 2 deletions bitbucket/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,14 @@ var BitBucket = exports.BitBucket = function(debug, proxy, http) {

/**
* Call any route, DELETE method
* Ex: api.delete('repos/show/my-username/my-repo')
* Ex: api.delete('repos/show/my-username/my-repo/ressoure-id')
*
* @param {String} route the GitHub route
* @param {Object} parameters GET parameters
* @param {Object} requestOptions reconfigure the request
*/
this["delete"] = function(route, parameters, requestOptions, callback) {
return this.getRequest().send(route, parameters, 'DELETE', requestOptions, callback);
return this.getRequest().delete(route, parameters || {}, requestOptions, callback);
};

/**
Expand All @@ -156,6 +156,18 @@ var BitBucket = exports.BitBucket = function(debug, proxy, http) {
return this.getRequest().post(route, parameters || {}, requestOptions, callback);
};

/**
* Call any route, PUT method
* Ex: api.put('repos/show/my-username/ressoure-id', {'email': '[email protected]'})
*
* @param {String} route the GitHub route
* @param {Object} parameters POST parameters
* @param {Object} requestOptions reconfigure the request
*/
this.put = function(route, parameters, requestOptions, callback) {
return this.getRequest().put(route, parameters || {}, requestOptions, callback);
};

/**
* Get the request
*
Expand Down
29 changes: 23 additions & 6 deletions bitbucket/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ var Request = exports.Request = function(options) {
this.configure = function(options)
{
options = options || {};
this.$options = {};
this.$options = this.$options || {};
for (var key in this.$defaults) {
this.$options[key] = options[key] !== undefined ? options[key] : this.$defaults[key];
if (options[key] !== undefined) this.$options[key] = options[key]
else if (!this.$options[key]) this.$options[key] = this.$defaults[key]
}

return this;
Expand Down Expand Up @@ -93,6 +94,22 @@ var Request = exports.Request = function(options) {
return this.send(apiPath, parameters, 'POST', options, callback);
};

/**
* Send a PUT request
* @see send
*/
this.put = function(apiPath, parameters, options, callback) {
return this.send(apiPath, parameters, 'PUT', options, callback);
};

/**
* Send a DELETE request
* @see send
*/
this.delete = function(apiPath, parameters, options, callback) {
return this.send(apiPath, parameters, 'DELETE', options, callback);
};

/**
* Send a request to the server, receive a response,
* decode the response and returns an associative array
Expand Down Expand Up @@ -146,8 +163,8 @@ var Request = exports.Request = function(options) {
"Content-Length": "0",
"Content-Type": "application/x-www-form-urlencoded"
};
var getParams = httpMethod != "POST" ? parameters : {};
var postParams = httpMethod == "POST" ? parameters : {};
var getParams = httpMethod == "GET" ? parameters : {};
var postParams = httpMethod != "GET" ? parameters : {};


var getQuery = querystring.stringify(getParams);
Expand Down Expand Up @@ -193,7 +210,7 @@ var Request = exports.Request = function(options) {

var getOptions = {
host: host,
post: port,
port: port,
path: path,
method: httpMethod,
headers: headers
Expand Down Expand Up @@ -227,7 +244,7 @@ var Request = exports.Request = function(options) {
});
});

if (httpMethod == "POST")
if (httpMethod != "GET")
request.write(postQuery);

request.end();
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name" : "bitbucket",
"version" : "0.0.1",
"name" : "bitbucket2",
"version" : "0.0.2",
"description" : "Wrapper for the BitBucket API",
"author": "Fabian Jakobs <[email protected]>",
"homepage": "http://github.com/ajaxorg/node-bitbucket.git",
Expand Down