From 7dfb385fc3f228b381daa3ec7fe4bf0653e7c6fd Mon Sep 17 00:00:00 2001 From: Mike Bannister Date: Sun, 29 Jul 2012 20:57:47 -0400 Subject: [PATCH] move methods around --- packages/oauth1/oauth1.js | 54 +++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/packages/oauth1/oauth1.js b/packages/oauth1/oauth1.js index 28e9bed8fa..d24e7f817d 100644 --- a/packages/oauth1/oauth1.js +++ b/packages/oauth1/oauth1.js @@ -5,12 +5,6 @@ OAuth = function(config) { _.extend(this, config); }; -OAuth.prototype._getAuthHeaderString = function(headers) { - return 'OAuth ' + _.map(headers, function(val, key) { - return encodeURIComponent(key) + '="' + encodeURIComponent(val) + '"'; - }).sort().join(', '); -}; - OAuth.prototype.getRequestToken = function(callbackUrl) { var headers = this._buildHeader({ @@ -36,27 +30,6 @@ OAuth.prototype.getAccessToken = function(oauthToken) { this.accessTokenSecret = tokens.oauth_token_secret; }; -OAuth.prototype._call = function(method, url, headers) { - - // Get the signature - headers.oauth_signature = this._getSignature(method.toUpperCase(), url, headers, this.accessTokenSecret); - - // Make a authorization string according to oauth1 spec - var authString = this._getAuthHeaderString(headers); - - // Make signed request - var response = Meteor.http[method.toLowerCase()](url, { - headers: { - Authorization: authString - } - }); - - if (response.error) - throw response.error; - - return response; -}; - OAuth.prototype.call = function(method, url) { var headers = this._buildHeader({ oauth_token: this.accessToken @@ -102,9 +75,36 @@ OAuth.prototype._getSignature = function(method, url, rawHeaders, oauthSecret) { return crypto.createHmac('SHA1', signingKey).update(signatureBase).digest('base64'); }; +OAuth.prototype._call = function(method, url, headers) { + + // Get the signature + headers.oauth_signature = this._getSignature(method.toUpperCase(), url, headers, this.accessTokenSecret); + + // Make a authorization string according to oauth1 spec + var authString = this._getAuthHeaderString(headers); + + // Make signed request + var response = Meteor.http[method.toLowerCase()](url, { + headers: { + Authorization: authString + } + }); + + if (response.error) + throw response.error; + + return response; +}; + OAuth.prototype._encodeHeader = function(header) { return _.reduce(header, function(memo, val, key) { memo[encodeURIComponent(key)] = encodeURIComponent(val); return memo; }, {}); }; + +OAuth.prototype._getAuthHeaderString = function(headers) { + return 'OAuth ' + _.map(headers, function(val, key) { + return encodeURIComponent(key) + '="' + encodeURIComponent(val) + '"'; + }).sort().join(', '); +};