diff --git a/bitbucket/index.js b/bitbucket/index.js index ca5c696..adcfd08 100644 --- a/bitbucket/index.js +++ b/bitbucket/index.js @@ -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); }; /** @@ -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': 'my-new-email@provider.org'}) + * + * @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 * diff --git a/bitbucket/request.js b/bitbucket/request.js index c7617de..409270a 100644 --- a/bitbucket/request.js +++ b/bitbucket/request.js @@ -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; @@ -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 @@ -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); @@ -193,7 +210,7 @@ var Request = exports.Request = function(options) { var getOptions = { host: host, - post: port, + port: port, path: path, method: httpMethod, headers: headers @@ -227,7 +244,7 @@ var Request = exports.Request = function(options) { }); }); - if (httpMethod == "POST") + if (httpMethod != "GET") request.write(postQuery); request.end(); diff --git a/package.json b/package.json index 7653a6e..d593210 100644 --- a/package.json +++ b/package.json @@ -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 ", "homepage": "http://github.com/ajaxorg/node-bitbucket.git",