volos-analytics-apigee
Advanced tools
Comparing version 0.3.2 to 0.3.3
@@ -52,2 +52,3 @@ /**************************************************************************** | ||
this.proxy = options.proxy; | ||
this.compress = !!options.compress; | ||
if (options.proxy_revision) { this.proxy_revision = options.proxy_revision; } | ||
@@ -78,2 +79,3 @@ | ||
ApigeeAnalyticsSpi.prototype.flush = function(recordsQueue, cb) { | ||
var recordsToBeUploaded = { | ||
@@ -83,19 +85,21 @@ records: recordsQueue | ||
var req = superagent.post(this.uri); | ||
function sendResponse(err, resp) { | ||
if (err || resp.statusCode != 200) { | ||
cb(err || new Error('error from server: ' + resp.statusCode), recordsToBeUploaded); | ||
} else { | ||
resp.body.rejected > 0 ? cb(undefined, recordsQueue.slice(recordsQueue.length - resp.body.rejected)) : cb(); | ||
} | ||
} | ||
if (this.microgateway) { | ||
req.auth(this.key, this.secret); | ||
if (this.compress) { | ||
var zlib = require('zlib'); | ||
var uncompressed = JSON.stringify(recordsToBeUploaded); | ||
var self = this; | ||
zlib.gzip(uncompressed, function(err, compressed) { | ||
self.send(compressed, sendResponse); | ||
}); | ||
} else { | ||
req.set('x-DNA-Api-Key', this.key); | ||
this.send(recordsToBeUploaded, sendResponse); | ||
} | ||
req | ||
.send(recordsToBeUploaded) | ||
.end(function(err, resp) { | ||
if (err || resp.statusCode != 200) { | ||
cb(err || new Error('error from server: ' + resp.statusCode), recordsToBeUploaded); | ||
} else { | ||
resp.body.rejected > 0 ? cb(undefined, recordsQueue.slice(recordsQueue.length - resp.body.rejected)) : cb(); | ||
} | ||
}); | ||
}; | ||
@@ -125,1 +129,16 @@ | ||
}; | ||
ApigeeAnalyticsSpi.prototype.send = function send(data, cb) { | ||
var req = superagent.post(this.uri); | ||
if (this.microgateway) { | ||
req.auth(this.key, this.secret); | ||
} else { | ||
req.set('x-DNA-Api-Key', this.key); | ||
} | ||
req | ||
.send(data) | ||
.end(cb); | ||
}; |
{ | ||
"name": "volos-analytics-apigee", | ||
"version": "0.3.2", | ||
"version": "0.3.3", | ||
"main": "lib/apigeeanalytics.js", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -111,3 +111,3 @@ /**************************************************************************** | ||
should.not.exist(err); | ||
if(retryRecords) { | ||
if (retryRecords) { | ||
assert(retryRecords.length <= recordsQueue.length); | ||
@@ -118,2 +118,25 @@ } | ||
}); | ||
it('should compress before sending if so configured', function(done) { | ||
var options = extend(config, { | ||
recordLimit: 10000, | ||
proxy: 'testAnalytics', | ||
flushInterval: 100, | ||
uploadLength : 100, | ||
compress: true | ||
}); | ||
var analytics = Spi.create(options); | ||
var recordsQueue = [record, record, record]; | ||
analytics.spi.send = function send(compressed) { | ||
var zlib = require('zlib'); | ||
zlib.gunzip(compressed, function(err, uncompressed) { | ||
var data = JSON.parse(uncompressed); | ||
recordsQueue.should.eql(data.records); | ||
done(); | ||
}); | ||
}; | ||
analytics.spi.flush(recordsQueue); | ||
}); | ||
@@ -120,0 +143,0 @@ describe('Common', function() { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9294
242