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

Commit ae3ac7e

Browse files
author
Axel Freudiger
committed
changed tab-style and getTimestamp
1 parent 1973ec0 commit ae3ac7e

File tree

1 file changed

+52
-46
lines changed

1 file changed

+52
-46
lines changed

src/OAuth/Consumer.js

Lines changed: 52 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -35,31 +35,32 @@
3535
verifier: empty,
3636

3737
signatureMethod: options.signatureMethod || 'HMAC-SHA1',
38-
timeStampFormat: options.timeStampFormat || 'ms'
38+
timeStampFormat: options.timeStampFormat || 'ms'
3939
};
4040

4141
this.realm = options.realm || empty;
4242
this.requestTokenUrl = options.requestTokenUrl || empty;
4343
this.authorizationUrl = options.authorizationUrl || empty;
4444
this.accessTokenUrl = options.accessTokenUrl || empty;
45-
this.headerParams = {};
46-
47-
this.getTimeStampFormat= function () {
48-
return oauth.timeStampFormat;
49-
}
50-
51-
this.getHeaderParams = function (options) {
52-
if (typeof options == "undefined")
53-
var options = {};
54-
var url, headers, data, urlString, method, signature, signatureString, signatureMethod, urlString, appendQueryString, signatureData = {}, withFile = false;
55-
56-
method = options.method || 'GET';
57-
url = options.url ? URI(options.url) : '';
58-
data = options.data || {};
59-
headers = options.headers || {};
60-
appendQueryString = options.appendQueryString ? options.appendQueryString : false;
61-
62-
headerParams = {
45+
this.headerParams = {};
46+
47+
this.getTimeStampFormat= function () {
48+
return oauth.timeStampFormat;
49+
}
50+
51+
//pulled this out of this.request to be accessible from not-closure context
52+
this.getHeaderParams = function (options) {
53+
if (typeof options == "undefined")
54+
var options = {};
55+
var url, headers, data, urlString, method, signature, signatureString, signatureMethod, urlString, appendQueryString, signatureData = {}, withFile = false;
56+
57+
method = options.method || 'GET';
58+
url = options.url ? URI(options.url) : '';
59+
data = options.data || {};
60+
headers = options.headers || {};
61+
appendQueryString = options.appendQueryString ? options.appendQueryString : false;
62+
63+
headerParams = {
6364
'oauth_callback': oauth.callbackUrl,
6465
'oauth_consumer_key': oauth.consumerKey,
6566
'oauth_token': oauth.accessTokenKey,
@@ -70,9 +71,9 @@
7071
'oauth_version': OAUTH_VERSION_1_0
7172
};
7273

73-
this.setHeaderParams(headerParams);
74+
this.setHeaderParams(headerParams);
7475
signatureMethod = oauth.signatureMethod;
75-
76+
7677
// Handle GET params first
7778
params = url.query.toObject();
7879
for (i in params) {
@@ -91,7 +92,7 @@
9192
}
9293

9394
urlString = url.scheme + '://' + url.host + url.path;
94-
95+
9596
signatureString = toSignatureBaseString(method, urlString, headerParams, signatureData);
9697

9798
signature = OAuth.signatureMethod[signatureMethod](oauth.consumerSecret, oauth.accessTokenSecret, signatureString);
@@ -135,18 +136,19 @@
135136
query.append(i, data[i]);
136137
}
137138
}
138-
139-
return oauth.headerParams;
140-
}
141-
142-
this.getHeaderString = function (url){
143-
return toHeaderString(this.getHeaderParams({url:url}));
144-
}
145-
146-
this.setHeaderParams = function (headerParams) {
147-
oauth.headerParams = headerParams;
148-
}
149-
139+
140+
return oauth.headerParams;
141+
}
142+
143+
//transforms params to string
144+
this.getHeaderString = function (url){
145+
return toHeaderString(this.getHeaderParams({url:url}));
146+
}
147+
148+
this.setHeaderParams = function (headerParams) {
149+
oauth.headerParams = headerParams;
150+
}
151+
150152
this.getAccessToken = function () {
151153
return [oauth.accessTokenKey, oauth.accessTokenSecret];
152154
};
@@ -264,7 +266,7 @@
264266
}
265267
};
266268

267-
headerParams = this.getHeaderParams(options);
269+
headerParams = this.getHeaderParams(options);
268270

269271
xhr.open(method, url+'', true);
270272

@@ -388,17 +390,21 @@
388390
}, failure);
389391
},
390392

391-
/**
392-
* Generate a timestamp for the request
393-
*/
394-
getTimestamp: function() {
395-
var oauth = this;
396-
397-
if (oauth.getTimeStampFormat() == 's')
398-
return parseInt(+new Date() / 100000, 10); // use short form of getting a timestamp
399-
else
400-
return parseInt(+new Date() / 1000, 10); // use short form of getting a timestamp
401-
}
393+
/**
394+
* Generate a timestamp for the request
395+
*
396+
* moved function into prototype to have oauth.getTimeStampFormat() of instance avalable
397+
*/
398+
getTimestamp: function() {
399+
var oauth = this;
400+
401+
switch (oauth.getTimeStampFormat()){
402+
case ('ms'):
403+
return parseInt(+new Date() / 1000, 10); // use short form of getting a milliseconds-timestamp
404+
default:
405+
return parseInt(+new Date() / 100000, 10); // use short form of getting a seconds-timestamp
406+
}
407+
}
402408
};
403409

404410
OAuth.signatureMethod = {

0 commit comments

Comments
 (0)