Skip to content

Commit

Permalink
Added new post method and get method. Deprecated older getProtectedRe…
Browse files Browse the repository at this point in the history
…source method
  • Loading branch information
ciaranj committed Aug 5, 2010
1 parent 3564e2e commit 7117b2d
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions lib/oauth.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ exports.OAuth.prototype._createClient= function( port, hostname, sshEnabled, cre
return http.createClient(port, hostname, sshEnabled, credentials);
}

exports.OAuth.prototype._performSecureRequest= function( oauth_token, oauth_token_secret, method, url, extra_params, callback ) {
exports.OAuth.prototype._performSecureRequest= function( oauth_token, oauth_token_secret, method, url, extra_params, post_body, callback ) {
var oauthParameters= {
"oauth_timestamp": this._getTimestamp(),
"oauth_nonce": this._getNonce(this._nonceSize),
Expand Down Expand Up @@ -207,7 +207,7 @@ exports.OAuth.prototype._performSecureRequest= function( oauth_token, oauth_toke
headers["Accept"]= "*/*"
headers["Connection"]= "close"
headers["User-Agent"]= "Express authentication"
headers["Content-length"]= 0
headers["Content-length"]= post_body ? post_body.length : 0; //Probably going to fail if not posting ascii
headers["Content-Type"]= "application/x-www-form-urlencoded"

var path;
Expand All @@ -233,7 +233,9 @@ exports.OAuth.prototype._performSecureRequest= function( oauth_token, oauth_toke
});

request.socket.addListener("error",callback);

if( method == "POST" && post_body != null && post_body != "" ) {
request.write(post_body);
}
request.end();
}

Expand All @@ -245,7 +247,7 @@ exports.OAuth.prototype.getOAuthAccessToken= function(oauth_token, oauth_token_s
extraParams.oauth_verifier= oauth_verifier;
}

this._performSecureRequest( oauth_token, oauth_token_secret, "GET", this._accessUrl, extraParams, function(error, data, response) {
this._performSecureRequest( oauth_token, oauth_token_secret, "GET", this._accessUrl, extraParams, "", function(error, data, response) {
if( error ) callback(error);
else {
var results= querystring.parse( data );
Expand All @@ -257,8 +259,18 @@ exports.OAuth.prototype.getOAuthAccessToken= function(oauth_token, oauth_token_s
}
})
}

// Deprecated
exports.OAuth.prototype.getProtectedResource= function(url, method, oauth_token, oauth_token_secret, callback) {
this._performSecureRequest( oauth_token, oauth_token_secret, method, url, null, callback );
this._performSecureRequest( oauth_token, oauth_token_secret, method, url, null, "", callback );
}

exports.OAuth.prototype.get= function(url, oauth_token, oauth_token_secret, callback) {
this._performSecureRequest( oauth_token, oauth_token_secret, "GET", url, null, "", callback );
}

exports.OAuth.prototype.post= function(url, oauth_token, oauth_token_secret, post_body, callback) {
this._performSecureRequest( oauth_token, oauth_token_secret, "POST", url, null, post_body, callback );
}

exports.OAuth.prototype.getOAuthRequestToken= function(extraParams, callback) {
Expand All @@ -271,7 +283,7 @@ exports.OAuth.prototype.getOAuthRequestToken= function(extraParams, callback) {
if( this._authorize_callback ) {
extraParams["oauth_callback"]= this._authorize_callback;
}
this._performSecureRequest( null, null, "POST", this._requestUrl, extraParams, function(error, data, response) {
this._performSecureRequest( null, null, "POST", this._requestUrl, extraParams, "", function(error, data, response) {
if( error ) callback(error);
else {
var results= querystring.parse(data);
Expand Down

0 comments on commit 7117b2d

Please sign in to comment.