PageSourceSearch

https://www.researchcommons.org/assets/cgi/js/statsDispatcher.debug.js

js researchcommons.org collected 2026-10-01 12:09:23 UTC 2,287 bytes, 89 lines download raw bytes

1YUI.add('bepress.utility.statsdispatcher', function (Y) {
2
3	// **** Constructor **** //
4	function StatsDispatcher(type, tokenInfo, sampleRate) {
5		this.type = type || 't';
6		
7		// Bucket Name
8		this.tokenData = tokenInfo.data;
9		this.token = tokenInfo.token;
10
11		// Group, App, SampleRate - Optional
12		this.sampleRate = sampleRate || null;
13
14		// Endpoint Definition
15		this.endpoint = Bepress.cgiUrlBase + '/do/api/stats/d?';
16	}
17	
18	StatsDispatcher.TIMING = 't';
19	StatsDispatcher.INCREMENT = 'i';
20	StatsDispatcher.DECREMENT = 'd';
21	
22	// **** Factory **** //
23	StatsDispatcher.createTimer = function(tokenInfo, sampleRate) {
24		return new StatsDispatcher(StatsDispatcher.TIMING, tokenInfo, sampleRate);
25	}
26	
27	// **** Factory **** //
28	StatsDispatcher.createIncrementer = function(tokenInfo, sampleRate) {
29		return new StatsDispatcher(StatsDispatcher.INCREMENT, tokenInfo, sampleRate);
30	}
31	
32	// **** Factory **** //
33	StatsDispatcher.createDecrementer = function(tokenInfo, sampleRate) {
34		return new StatsDispatcher(StatsDispatcher.DECREMENT, tokenInfo, sampleRate);
35	}
36
37	Y.namespace('bepress.utility');
38	Y.bepress.utility.StatsDispatcher = StatsDispatcher;
39
40	SDProto = StatsDispatcher.prototype;
41	SDProto._getTypeErrMsg = function(operation) {
42		return operation + " is not supported for StatsDispatcher of type " + this.type;
43	}
44
45	SDProto.setStatValue = function( inValue ) {
46		this.statValue = inValue;
47		return this;
48	}
49
50	SDProto.dispatch = function() {
51		var uri, cfg, theRequest;
52
53		// make sure we have statValue
54		if ( ! this.statValue ) {
55			throw "Won't dispatch stats. statValue isn't set.";
56		}
57
58		// Gather relevant parameters and fire off dispatch request to endpoint
59		cfg = {
60			method: 'POST'
61			, data: this.getEndpointParamObj()
62		};
63
64		uri = this.endpoint;
65		theRequest = Y.io(uri, cfg);
66	}
67
68	SDProto.getEndpointParamObj = function() {
69		var paramObj = {
70			't'       : this.type
71			, 'token'   : this.token.toString()
72		};
73		
74		for ( var p in this.tokenData ) {
75			if ( this.tokenData.hasOwnProperty( p ) ) {
76				paramObj[ p ] = this.tokenData[ p ];
77			}
78		}
79		
80		paramObj[ 'v' ] = this.statValue.toString();
81
82		if (this.sampleRate) {
83			paramObj['s'] = this.sampleRate.toString();
84		}
85
86		return paramObj;
87	}
88
89},'0.01',{requires: ['io', 'querystring-stringify-simple'] } );

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.