Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 41 additions & 19 deletions lib/OptimizelyClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ var OptimizelyClient = function(apiToken, options) {
this.baseHeaders = {
'Token': this.apiToken,
'Content-Type': 'application/json'
}
}
}

}
Expand Down Expand Up @@ -163,18 +163,18 @@ OptimizelyClient.prototype.getProject = function(options) {
* @name OptimizelyClient#updateProject
* @since 0.2.0
* @description Update an Existing Project in Optimizely
* @param {object} options object with the following properties:
* @param {object} options object with the following properties:
* {
* @param {String} id
* @param {String} id
* @param {String} [project_name]
* @param {String} [project_status = "Active|Archived"]
* @param {Boolean} [include_jquery]
* @param {String} [project_javascript]
* @param {Boolean} [enable_force_variation]
* @param {Boolean} [exclude_disabled_experiments]
* @param {String} [project_status = "Active|Archived"]
* @param {Boolean} [include_jquery]
* @param {String} [project_javascript]
* @param {Boolean} [enable_force_variation]
* @param {Boolean} [exclude_disabled_experiments]
* @param {Boolean} [exclude_names]
* @param {Boolean} [ip_anonymization]
* @param {String} [ip_filtering]
* @param {Boolean} [ip_anonymization]
* @param {String} [ip_filtering]
* }
* @return {promise} A promise fulfilled with the updated project
*/
Expand Down Expand Up @@ -392,7 +392,7 @@ OptimizelyClient.prototype.deleteExperiment = function(options) {
* @name OptimizelyClient#getResults
* @since 0.4.0
* @description get non-stats engine results
* @param {object} options An object with the following properties:
* @param {object} options An object with the following properties:
* {
* @param {String} id Experiment ID
* @param {object} [dimension = {}] An object with the following properties:
Expand Down Expand Up @@ -429,7 +429,7 @@ OptimizelyClient.prototype.getResults = function(options) {
* @name OptimizelyClient#getStats
* @since 0.4.0
* @description get stats engine results
* @param {object} options An object with the following properties:
* @param {object} options An object with the following properties:
* {
* @param {String} id Experiment ID
* @param {object} [dimension = {}] An object with the following properties:
Expand Down Expand Up @@ -464,6 +464,28 @@ OptimizelyClient.prototype.getStats = function(options) {
////////////////
//3. Variations
////////////////
/**
*@pubilc
*@name OptimizelyClient#getVariations
*@since 0.6.3
*@description list variations for an experiment
*@param {object} options An object with the following properties:
*{
* @param {string|number} experiment_id
*}
*/
OptimizelyClient.prototype.getVariations = function(options) {
options = options || {};
options.experiment_id = String(options.experiment_id || "");
if (!options.experiment_id) throw new Error(
"Required: options.experiment_id");
var url = this.baseUrl + 'experiments/' + options.experiment_id +
'/variations';
return rest.getAsync(url, {
method: 'get',
headers: this.baseHeaders
})
}
/**
*@pubilc
*@name OptimizelyClient#createVariation
Expand Down Expand Up @@ -612,7 +634,7 @@ OptimizelyClient.prototype.getAudience = function(options) {
* {
* @param {String} id Project ID
* @param {String} name
* @param {String} [description]
* @param {String} [description]
* @param {Boolean} [segmentation] Only available for platinum
* @param {Array} [conditions] See http://developers.optimizely.com/rest/conditions/
* }
Expand Down Expand Up @@ -642,9 +664,9 @@ OptimizelyClient.prototype.createAudience = function(options) {
* @name OptimizelyClient#updateAudience
* @since 0.4.0
* @description Update an Existing Project in Optimizely
* @param {object} options object with the following properties:
* @param {object} options object with the following properties:
* {
* @param {String} id
* @param {String} id
* @param {String} [name]
* @param {Array} [conditions] See http://developers.optimizely.com/rest/conditions/
* @param {Boolean} [segmentation] Platinum Customers only
Expand Down Expand Up @@ -723,7 +745,7 @@ OptimizelyClient.prototype.getDimension = function(options) {
* {
* @param {String} id Project ID
* @param {String} name
* @param {String} [description]
* @param {String} [description]
* @param {Boolean} [client_api_name] A unique name to refer to this dimension
* }
* @returns {promise} A promise fulfilled with the created project
Expand Down Expand Up @@ -751,11 +773,11 @@ OptimizelyClient.prototype.createDimension = function(options) {
* @name OptimizelyClient#updateDimension
* @since 0.5.0
* @description Update an Existing Dimension in Optimizely
* @param {object} options object with the following properties:
* @param {object} options object with the following properties:
* {
* @param {String} id
* @param {String} id
* @param {String} [name]
* @param {String} [description]
* @param {String} [description]
* @param {Boolean} [client_api_name] A unique name to refer to this dimension
* }
* @return {promise} A promise fulfilled with the updated audience
Expand Down
53 changes: 42 additions & 11 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ describe("Successful API Calls", function() {
}
)
});
scope.intercept('/experiments/' + EXPERIMENTID, 'DELETE')
scope.intercept('/experiments/' + EXPERIMENTID, 'DELETE')
.reply(204, function(uri, requestBody) {
return requestBody;
});
Expand All @@ -314,7 +314,7 @@ describe("Successful API Calls", function() {
}
)
});
scope.intercept('/experiments/' + EXPERIMENTID + '/results', 'GET')
scope.intercept('/experiments/' + EXPERIMENTID + '/results', 'GET')
.reply(200, function(uri, requestBody) {
return requestBody;
});
Expand All @@ -332,7 +332,7 @@ describe("Successful API Calls", function() {
}
)
});
scope.intercept('/experiments/' + EXPERIMENTID + '/stats', 'GET')
scope.intercept('/experiments/' + EXPERIMENTID + '/stats', 'GET')
.reply(200, function(uri, requestBody) {
return requestBody;
});
Expand All @@ -355,6 +355,37 @@ describe("Successful API Calls", function() {
//Variation Tests
//////////////////
describe("Variations", function() {
scope.get('/experiments/' + EXPERIMENTID + '/variations') //get multiple
.reply(201, function(uri) {
return [{
"is_paused": false,
"description": "Original",
"weight": null,
"created": "2014-04-17T00:47:58.390560Z",
"section_id": null,
"js_component": "",
"experiment_id": 854484703,
"project_id": 859720118,
"id": 854613530
}];
});
it('should list variations an experiment', function(done) {
var options = {
"experiment_id": EXPERIMENTID
}
client.getVariations(options)
.then(
function(variations) {
variations = JSON.parse(variations);
assert.equal(variations.length, 1);
assert.equal(variations[0].id, 854613530);
done();
},
function(error) {
done(error);
}
)
});
scope.post('/experiments/' + EXPERIMENTID + '/variations/') //create
.reply(201, function(uri, requestBody) {
requestBody = JSON.parse(requestBody);
Expand Down Expand Up @@ -467,7 +498,7 @@ describe("Successful API Calls", function() {
}
)
});
scope.intercept('/variations/' + VARIATIONID, 'DELETE')
scope.intercept('/variations/' + VARIATIONID, 'DELETE')
.reply(204, function(uri, requestBody) {
return;
});
Expand Down Expand Up @@ -510,7 +541,7 @@ describe("Successful API Calls", function() {
requestBody.id = AUDIENCEID;
return requestBody;
});
scope.get('/projects/' + PROJECTID + '/audiences/') //get
scope.get('/projects/' + PROJECTID + '/audiences/') //get
.reply(200, function(uri, requestBody) {
return [ {
"id": AUDIENCEID,
Expand Down Expand Up @@ -610,7 +641,7 @@ describe("Successful API Calls", function() {
requestBody.id = DIMENSIONID;
return requestBody;
});
scope.get('/projects/' + PROJECTID + '/dimensions/') //get
scope.get('/projects/' + PROJECTID + '/dimensions/') //get
.reply(200, function(uri, requestBody) {
return [ {
"id": DIMENSIONID,
Expand Down Expand Up @@ -695,7 +726,7 @@ describe("Successful API Calls", function() {
* Set up the Goals Test Paths here
*/
before(function(){
scope.get('/projects/' + PROJECTID + '/goals/') //get
scope.get('/projects/' + PROJECTID + '/goals/') //get
.reply(200, function(uri, requestBody) {
return [ {
"id": GOALSID,
Expand Down Expand Up @@ -789,7 +820,7 @@ describe("Unsuccessful API Calls", function() {
status: 400,
message: FUNNELENVYERROR,
uuid: hat()
};
};
});
it('should not update a project', function(done){
var newProjectName = PROJECTNAME + '2';
Expand Down Expand Up @@ -1007,7 +1038,7 @@ describe("Unsuccessful API Calls", function() {
}
)
});
scope.intercept('/experiments/' + EXPERIMENTID, 'DELETE')
scope.intercept('/experiments/' + EXPERIMENTID, 'DELETE')
.reply(400, function(uri, requestBody) {
return {
status: 400,
Expand All @@ -1031,7 +1062,7 @@ describe("Unsuccessful API Calls", function() {
}
)
});
scope.intercept('/experiments/' + EXPERIMENTID, 'DELETE')
scope.intercept('/experiments/' + EXPERIMENTID, 'DELETE')
.reply(400, function(uri, requestBody) {
return {
status: 400,
Expand Down Expand Up @@ -1165,7 +1196,7 @@ describe("Unsuccessful API Calls", function() {
}
)
});
scope.intercept('/variations/' + VARIATIONID, 'DELETE')
scope.intercept('/variations/' + VARIATIONID, 'DELETE')
.reply(400, function(uri, requestBody) {
return {
status: 400,
Expand Down