|
2 | 2 | * @fileOverview Optimizely Client for Node |
3 | 3 | * @name Optimizely Client |
4 | 4 | * @author Arun |
5 | | - * @version 0.3.0 |
| 5 | + * @version 0.5.0 |
6 | 6 | */ |
7 | 7 |
|
8 | 8 | /** @access private */ |
@@ -653,4 +653,113 @@ OptimizelyClient.prototype.getAudiences = function(options){ |
653 | 653 | headers: this.baseHeaders |
654 | 654 | }); |
655 | 655 | } |
| 656 | + |
| 657 | +//////////////// |
| 658 | +//5. Dimensions |
| 659 | +//////////////// |
| 660 | +/** |
| 661 | + * @pubilc |
| 662 | + * @name OptimizelyClient#getDimension |
| 663 | + * @since 0.5.0 |
| 664 | + * @description Read a dimension in Optimizely |
| 665 | + * @param {object} options An object with the following properties: |
| 666 | + * { |
| 667 | + * @param {string|number} id The Dimension ID |
| 668 | + * } |
| 669 | + * @returns {promise} A promise fulfilled with the Dimension |
| 670 | + * @note the id may be passed as a string instead of a member of an object |
| 671 | + */ |
| 672 | +OptimizelyClient.prototype.getDimension = function(options) { |
| 673 | + if (typeof options === "string") options = { |
| 674 | + id: options |
| 675 | + }; |
| 676 | + if (!options.id) throw new Error("Required: options.id"); |
| 677 | + var theUrl = this.baseUrl + 'dimensions/' + options.id; |
| 678 | + return rest.getAsync(theUrl, { |
| 679 | + method: 'get', |
| 680 | + headers: this.baseHeaders |
| 681 | + }); |
| 682 | + } |
| 683 | +/** |
| 684 | + * @pubilc |
| 685 | + * @name OptimizelyClient#createDimension |
| 686 | + * @since 0.5.0 |
| 687 | + * @description Create an Dimension in Optimizely |
| 688 | + * @param {object} options An object with the following properties: |
| 689 | + * { |
| 690 | + * @param {String} id Project ID |
| 691 | + * @param {String} name |
| 692 | + * @param {String} [description] |
| 693 | + * @param {Boolean} [client_api_name] A unique name to refer to this dimension |
| 694 | + * } |
| 695 | + * @returns {promise} A promise fulfilled with the created project |
| 696 | + */ |
| 697 | +OptimizelyClient.prototype.createDimension = function(options) { |
| 698 | + var optionsToSend = {}; |
| 699 | + options = options || {}; |
| 700 | + if (!options.name) throw new Error("Required: options.name"); |
| 701 | + if (!options.id) throw new Error("Required: options.id"); |
| 702 | + |
| 703 | + optionsToSend.name = options.name; |
| 704 | + optionsToSend.id = options.id; |
| 705 | + optionsToSend.description = options.description || ""; |
| 706 | + optionsToSend.client_api_name = options.client_api_name || ""; |
| 707 | + |
| 708 | + var postUrl = this.baseUrl + 'projects/' + options.id + '/dimensions/'; |
| 709 | + return rest.postAsync(postUrl, { |
| 710 | + method: 'post', |
| 711 | + headers: this.baseHeaders, |
| 712 | + data: JSON.stringify(optionsToSend) |
| 713 | + }) |
| 714 | + } |
| 715 | +/** |
| 716 | + * @public |
| 717 | + * @name OptimizelyClient#updateDimension |
| 718 | + * @since 0.5.0 |
| 719 | + * @description Update an Existing Dimension in Optimizely |
| 720 | + * @param {object} options object with the following properties: |
| 721 | + * { |
| 722 | + * @param {String} id |
| 723 | + * @param {String} [name] |
| 724 | + * @param {String} [description] |
| 725 | + * @param {Boolean} [client_api_name] A unique name to refer to this dimension |
| 726 | + * } |
| 727 | + * @return {promise} A promise fulfilled with the updated audience |
| 728 | + */ |
| 729 | +OptimizelyClient.prototype.updateDimension = function(options) { |
| 730 | + options = options || {}; |
| 731 | + options.id = options.id || false; |
| 732 | + if(!options.id) throw new Error('required: options.id'); |
| 733 | + var putUrl = this.baseUrl + 'dimensions/' + options.id; |
| 734 | + return rest.putAsync(putUrl, { |
| 735 | + method: 'put', |
| 736 | + headers: this.baseHeaders, |
| 737 | + data: JSON.stringify(options) |
| 738 | + }); |
| 739 | + } |
| 740 | +/** |
| 741 | + * @public |
| 742 | + * @name OptimizelyClient#getDimensions |
| 743 | + * @since 0.5.0 |
| 744 | + * @description Retrieves a list of Dimensions in a project from Optimizely |
| 745 | + * @param {object} options An object with the following properties: |
| 746 | + * { |
| 747 | + * @param {string|number} id The Project ID |
| 748 | + * } |
| 749 | + * @return {promise} A promise fulfilled with an array of all Audiences |
| 750 | + * |
| 751 | + */ |
| 752 | +OptimizelyClient.prototype.getDimensions = function(options){ |
| 753 | + if (typeof options === "string" || typeof options === "number") options = { |
| 754 | + id: options |
| 755 | + }; |
| 756 | + options = options || {}; |
| 757 | + options.id = options.id || ""; |
| 758 | + if (!options.id) throw new Error("required: options.id"); |
| 759 | + var theUrl = this.baseUrl + 'projects/' + options.id + '/dimensions/'; |
| 760 | + return rest.getAsync(theUrl, { |
| 761 | + method: 'get', |
| 762 | + headers: this.baseHeaders |
| 763 | + }); |
| 764 | + } |
656 | 765 | module.exports = OptimizelyClient; |
0 commit comments