Initial commit
This commit is contained in:
85
themes/keepit/node_modules/algoliasearch/src/createAnalyticsClient.js
generated
vendored
Normal file
85
themes/keepit/node_modules/algoliasearch/src/createAnalyticsClient.js
generated
vendored
Normal file
@@ -0,0 +1,85 @@
|
||||
module.exports = createAnalyticsClient;
|
||||
|
||||
var algoliasearch = require('../index.js');
|
||||
|
||||
function createAnalyticsClient(appId, apiKey, opts) {
|
||||
var analytics = {};
|
||||
|
||||
opts = opts || {};
|
||||
// there need to be 4 hosts, like on the client, since if requests fail,
|
||||
// the counter goes up by 1, so we need to have the same amount of hosts
|
||||
// 4 because: -dsn, -1, -2, -3
|
||||
// This is done because the APPID used for search will be the same for the analytics client created,
|
||||
// and since the state of available hosts is shared by APPID globally for the module, we had issues
|
||||
// where the hostIndex would be 1 while the array was only one entry (you got an empty host)
|
||||
opts.hosts = opts.hosts || [
|
||||
'analytics.algolia.com',
|
||||
'analytics.algolia.com',
|
||||
'analytics.algolia.com',
|
||||
'analytics.algolia.com'
|
||||
];
|
||||
opts.protocol = opts.protocol || 'https:';
|
||||
|
||||
analytics.as = algoliasearch(appId, apiKey, opts);
|
||||
|
||||
analytics.getABTests = function(_params, callback) {
|
||||
var params = params || {};
|
||||
var offset = params.offset || 0;
|
||||
var limit = params.limit || 10;
|
||||
|
||||
return this.as._jsonRequest({
|
||||
method: 'GET',
|
||||
url: '/2/abtests?offset=' + encodeURIComponent(offset) + '&limit=' + encodeURIComponent(limit),
|
||||
hostType: 'read',
|
||||
forceAuthHeaders: true,
|
||||
callback: callback
|
||||
});
|
||||
};
|
||||
|
||||
analytics.getABTest = function(abTestID, callback) {
|
||||
return this.as._jsonRequest({
|
||||
method: 'GET',
|
||||
url: '/2/abtests/' + encodeURIComponent(abTestID),
|
||||
hostType: 'read',
|
||||
forceAuthHeaders: true,
|
||||
callback: callback
|
||||
});
|
||||
};
|
||||
|
||||
analytics.addABTest = function(abTest, callback) {
|
||||
return this.as._jsonRequest({
|
||||
method: 'POST',
|
||||
url: '/2/abtests',
|
||||
body: abTest,
|
||||
hostType: 'read',
|
||||
forceAuthHeaders: true,
|
||||
callback: callback
|
||||
});
|
||||
};
|
||||
|
||||
analytics.stopABTest = function(abTestID, callback) {
|
||||
return this.as._jsonRequest({
|
||||
method: 'POST',
|
||||
url: '/2/abtests/' + encodeURIComponent(abTestID) + '/stop',
|
||||
hostType: 'read',
|
||||
forceAuthHeaders: true,
|
||||
callback: callback
|
||||
});
|
||||
};
|
||||
|
||||
analytics.deleteABTest = function(abTestID, callback) {
|
||||
return this.as._jsonRequest({
|
||||
method: 'DELETE',
|
||||
url: '/2/abtests/' + encodeURIComponent(abTestID),
|
||||
hostType: 'write',
|
||||
forceAuthHeaders: true,
|
||||
callback: callback
|
||||
});
|
||||
};
|
||||
|
||||
analytics.waitTask = function(indexName, taskID, callback) {
|
||||
return this.as.initIndex(indexName).waitTask(taskID, callback);
|
||||
};
|
||||
|
||||
return analytics;
|
||||
}
|
||||
Reference in New Issue
Block a user