Adds support for PUT & DELETE verbs. Fixes #13

This commit is contained in:
ciaranj
2010-12-12 23:06:24 +00:00
parent 213bc49a20
commit fd2fad54da
2 changed files with 185 additions and 5 deletions

View File

@ -264,7 +264,7 @@ exports.OAuth.prototype._performSecureRequest= function( oauth_token, oauth_toke
}
}
if( method == "POST" && ( post_body == null && extra_params != null) ) {
if( (method == "POST" || method == "PUT") && ( post_body == null && extra_params != null) ) {
post_body= querystring.stringify(extra_params);
}
@ -295,13 +295,14 @@ exports.OAuth.prototype._performSecureRequest= function( oauth_token, oauth_toke
});
request.socket.addListener("error",callback);
if( method == "POST" && post_body != null && post_body != "" ) {
if( (method == "POST" || method =="PUT") && post_body != null && post_body != "" ) {
request.write(post_body);
}
request.end();
}
else {
if( method == "POST" && post_body != null && post_body != "" ) {
if( (method == "POST" || method =="PUT") && post_body != null && post_body != "" ) {
request.write(post_body);
}
return request;
@ -336,11 +337,15 @@ exports.OAuth.prototype.getProtectedResource= function(url, method, oauth_token,
this._performSecureRequest( oauth_token, oauth_token_secret, method, url, null, "", null, callback );
}
exports.OAuth.prototype.delete= function(url, oauth_token, oauth_token_secret, callback) {
return this._performSecureRequest( oauth_token, oauth_token_secret, "DELETE", url, null, "", null, callback );
}
exports.OAuth.prototype.get= function(url, oauth_token, oauth_token_secret, callback) {
return this._performSecureRequest( oauth_token, oauth_token_secret, "GET", url, null, "", null, callback );
}
exports.OAuth.prototype.post= function(url, oauth_token, oauth_token_secret, post_body, post_content_type, callback) {
exports.OAuth.prototype._putOrPost= function(method, url, oauth_token, oauth_token_secret, post_body, post_content_type, callback) {
var extra_params= null;
if( typeof post_content_type == "function" ) {
callback= post_content_type;
@ -351,9 +356,18 @@ exports.OAuth.prototype.post= function(url, oauth_token, oauth_token_secret, pos
extra_params= post_body;
post_body= null;
}
return this._performSecureRequest( oauth_token, oauth_token_secret, "POST", url, extra_params, post_body, post_content_type, callback );
return this._performSecureRequest( oauth_token, oauth_token_secret, method, url, extra_params, post_body, post_content_type, callback );
}
exports.OAuth.prototype.put= function(url, oauth_token, oauth_token_secret, post_body, post_content_type, callback) {
return this._putOrPost("PUT", url, oauth_token, oauth_token_secret, post_body, post_content_type, callback);
}
exports.OAuth.prototype.post= function(url, oauth_token, oauth_token_secret, post_body, post_content_type, callback) {
return this._putOrPost("POST", url, oauth_token, oauth_token_secret, post_body, post_content_type, callback);
}
exports.OAuth.prototype.getOAuthRequestToken= function(extraParams, callback) {
if( typeof extraParams == "function" ){
callback = extraParams;