<commit_before>'use strict'

var sha1 = require('sha1')
  , md5 = require('md5')
  , exec = require('child_process').exec;

function OmnitureAPI( userName, sharedSecret ) {
	this.userName = userName;
	this.sharedSecret = sharedSecret;
}

OmnitureAPI.prototype.queueAndFetchReport = function(requestData,callback) {

	var scope = this;

	this.makeRequest('Report.Queue',requestData,function(success,reportIdData) {
		if ( success ) {

			//Requires at least a small delay before making the subsequent request.
			setTimeout(function() {

				scope.fetchReport(reportIdData.reportID,function(success,reportData) {
					callback(success,reportData);
				});

			},500);

		} else {
			callback(false,reportIdData);
		}
	});
}

OmnitureAPI.prototype.fetchReport = function(reportId,callback) {

	var scope = this;

	this.makeRequest('Report.Get',{"reportID":reportId},function(success,reportData) {

		if (success) {

			callback(true,reportData);

		} else {

			if ( reportData.error == 'report_not_ready' ) {

				setTimeout(function() {
					scope.fetchReport(reportId,callback);
				}, 2000);

			} else {
				callback(false,reportData);

			}
		}
	});

}

OmnitureAPI.prototype.makeRequest = function(endpoint,data,callback) {

	var date = new Date();
	var nonce = md5(Math.random());
	var nonce_ts = date.toISOString();
	nonce_ts = nonce_ts.replace(/(\.\d\d\dZ)/ ,'Z');

	var digest = (new Buffer(sha1(nonce + nonce_ts + this.sharedSecret)).toString('base64'));
	
	var cmd = 'curl -H \'X-WSSE: UsernameToken Username="'+this.userName+'", PasswordDigest="'+digest+'", Nonce="'+nonce+'", Created="'+nonce_ts+'"\' --data \''+JSON.stringify(data)+'\' https://api.omniture.com/admin/1.4/rest/?method='+endpoint;
<commit_msg>Made nonce_ts more concise.<commit_after>'use strict'

var sha1 = require('sha1')
  , md5 = require('md5')
  , exec = require('child_process').exec;

function OmnitureAPI( userName, sharedSecret ) {
	this.userName = userName;
	this.sharedSecret = sharedSecret;
}

OmnitureAPI.prototype.queueAndFetchReport = function(requestData,callback) {

	var scope = this;

	this.makeRequest('Report.Queue',requestData,function(success,reportIdData) {
		if ( success ) {

			//Requires at least a small delay before making the subsequent request.
			setTimeout(function() {

				scope.fetchReport(reportIdData.reportID,function(success,reportData) {
					callback(success,reportData);
				});

			},500);

		} else {
			callback(false,reportIdData);
		}
	});
}

OmnitureAPI.prototype.fetchReport = function(reportId,callback) {

	var scope = this;

	this.makeRequest('Report.Get',{"reportID":reportId},function(success,reportData) {

		if (success) {

			callback(true,reportData);

		} else {

			if ( reportData.error == 'report_not_ready' ) {

				setTimeout(function() {
					scope.fetchReport(reportId,callback);
				}, 2000);

			} else {
				callback(false,reportData);

			}
		}
	});

}

OmnitureAPI.prototype.makeRequest = function(endpoint,data,callback) {

	//Create info used for header authentication
	var date = new Date();
	var nonce = md5(Math.random());
	var nonce_ts = date.toISOString().replace(/(\.\d\d\dZ)/ ,'Z');;
	var digest = (new Buffer(sha1(nonce + nonce_ts + this.sharedSecret)).toString('base64'));
	
	var cmd = 'curl -H \'X-WSSE: UsernameToken Username="'+this.userName+'", PasswordDigest="'+digest+'", Nonce="'+nonce+'", Created="'+nonce_ts+'"\' --data \''+JSON.stringify(data)+'\' https://api.omniture.com/admin/1.4/rest/?method='+endpoint;

{'fraction_non_alphanumeric': 0.16599655370476737, 'fraction_numerical': 0.009764503159103963, 'mean_word_length': 4.5728, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4677671', 'n_tokens_mistral': 1308, 'n_tokens_neox': 1160, 'n_words': 195}