From 7cc2fc305779430a11116d5c7dd45c842a847f0c Mon Sep 17 00:00:00 2001 From: Scott Cressler Date: Thu, 13 Apr 2017 14:55:48 -0700 Subject: [PATCH] Finished support for JavaScript, Java and Python code examples, including substituting into the sample code the application, experiment and/or page names, as well as the correct protocol (HTTP or HTTPS) and host name (including port) of the server, where appearing in the sample code. --- .../samplecode/java/Action.java.html | 11 ++-- .../samplecode/java/Assignment.java.html | 11 ++-- .../java/AssignmentWithSegmentation.java.html | 11 ++-- .../samplecode/java/BatchAssignment.java.html | 11 ++-- .../BatchAssignmentWithSegmentation.java.html | 12 ++-- .../samplecode/java/Impression.java.html | 11 ++-- .../samplecode/javascript/action.js.html | 49 +++++++++++++++ .../samplecode/javascript/assignment.js.html | 49 +++++++++++++++ .../javascript/assignment_with_seg.js.html | 57 +++++++++++++++++ .../javascript/batch_assignment.js.html | 49 +++++++++++++++ .../batch_assignment_with_seg.js.html | 57 +++++++++++++++++ .../samplecode/javascript/impression.js.html | 47 ++++++++++++++ .../samplecode/python/action.py.html | 13 ++-- .../samplecode/python/assignments.py.html | 13 ++-- .../python/assignments_with_seg.py.html | 13 ++-- .../python/batch_assignments.py.html | 13 ++-- .../python/batch_assignments_with_seg.py.html | 13 ++-- .../samplecode/python/impression.py.html | 13 ++-- .../app/scripts/controllers/APICallsCtrl.js | 24 ++++++- .../controllers/DisplaySourceCodeModal.js | 15 ++++- .../controllers/ExperimentDetailsCtrl.js | 17 ----- .../controllers/ExperimentModalCtrl.js | 3 +- modules/ui/app/styles/wasabi.scss | 18 ++++++ modules/ui/app/views/APICallsTab.html | 63 +++++++++++++++++++ .../ui/app/views/DisplaySourceCodeModal.html | 4 +- modules/ui/app/views/ExperimentDetails.html | 59 +---------------- modules/ui/app/views/ExperimentModal.html | 40 +----------- 27 files changed, 483 insertions(+), 213 deletions(-) create mode 100644 modules/ui/app/resources/samplecode/javascript/action.js.html create mode 100644 modules/ui/app/resources/samplecode/javascript/assignment.js.html create mode 100644 modules/ui/app/resources/samplecode/javascript/assignment_with_seg.js.html create mode 100644 modules/ui/app/resources/samplecode/javascript/batch_assignment.js.html create mode 100644 modules/ui/app/resources/samplecode/javascript/batch_assignment_with_seg.js.html create mode 100644 modules/ui/app/resources/samplecode/javascript/impression.js.html create mode 100644 modules/ui/app/views/APICallsTab.html diff --git a/modules/ui/app/resources/samplecode/java/Action.java.html b/modules/ui/app/resources/samplecode/java/Action.java.html index 3719eb03d..42980522c 100644 --- a/modules/ui/app/resources/samplecode/java/Action.java.html +++ b/modules/ui/app/resources/samplecode/java/Action.java.html @@ -1,6 +1,4 @@ - - - +
 import java.io.IOException;
 import java.io.OutputStreamWriter;
@@ -13,7 +11,7 @@
 public class Action {
 
   public static void main(String[] args) throws IOException {
-    System.out.print(postAction("ApplicationName", "ExperimentName", "UserName") ? "Action recorded" : "Action not recorded");
+    System.out.print(postAction("{{experiment.applicationName}}", "{{experiment.label}}", "UserName") ? "Action recorded" : "Action not recorded");
   }
 
 
@@ -28,7 +26,7 @@
    */
   private static boolean postAction(String application, String experiment, String user) throws IOException {
 
-    String urlAction = String.format("https://abtesting.intuit.com/api/v1/events/applications/%s/experiments/%s/users/%s", application, experiment, user);
+    String urlAction = String.format("{{baseUrl}}/events/applications/%s/experiments/%s/users/%s", application, experiment, user);
 
     URL url = new URL(urlAction);
     HttpURLConnection connection = (HttpURLConnection) url.openConnection();
@@ -50,6 +48,5 @@
 
 }
 
- - +
diff --git a/modules/ui/app/resources/samplecode/java/Assignment.java.html b/modules/ui/app/resources/samplecode/java/Assignment.java.html index d9a9fb809..48fb6095f 100644 --- a/modules/ui/app/resources/samplecode/java/Assignment.java.html +++ b/modules/ui/app/resources/samplecode/java/Assignment.java.html @@ -1,6 +1,4 @@ - - - +
 import org.json.simple.JSONObject;
 import org.json.simple.parser.JSONParser;
@@ -18,7 +16,7 @@
 public class Assignment {
 
   public static void main(String[] args) throws IOException, ParseException {
-    System.out.print(getAssignment("ApplicationName", "ExperimentName", "UserName"));
+    System.out.print(getAssignment("{{experiment.applicationName}}", "{{experiment.label}}", "UserName"));
   }
 
 
@@ -34,7 +32,7 @@
    */
   private static Object getAssignment(String application, String experiment, String user) throws IOException, ParseException {
 
-    String urlAssignment = String.format("https://abtesting.intuit.com/api/v1/assignments/applications/%s/experiments/%s/users/%s", application, experiment, user);
+    String urlAssignment = String.format("{{baseUrl}}/assignments/applications/%s/experiments/%s/users/%s", application, experiment, user);
 
     URL url = new URL(urlAssignment);
     HttpURLConnection connection = (HttpURLConnection) url.openConnection();
@@ -66,7 +64,6 @@
 
 }
 
- - +
diff --git a/modules/ui/app/resources/samplecode/java/AssignmentWithSegmentation.java.html b/modules/ui/app/resources/samplecode/java/AssignmentWithSegmentation.java.html index 4b5d6063b..f764fb14a 100644 --- a/modules/ui/app/resources/samplecode/java/AssignmentWithSegmentation.java.html +++ b/modules/ui/app/resources/samplecode/java/AssignmentWithSegmentation.java.html @@ -1,6 +1,4 @@ - - - +
 import org.json.simple.JSONObject;
 import org.json.simple.parser.JSONParser;
@@ -20,7 +18,7 @@
 public class AssignmentWithSegmentation {
 
   public static void main(String[] args) throws IOException, ParseException {
-    System.out.print(postAssignmentWithSegmentation("ApplicationName", "ExperimentName", "UserName", "10001"));
+    System.out.print(postAssignmentWithSegmentation("{{experiment.applicationName}}", "{{experiment.label}}", "UserName", "10001"));
   }
 
 
@@ -37,7 +35,7 @@
    */
   private static Object postAssignmentWithSegmentation(String application, String experiment, String user, String salary) throws IOException, ParseException {
 
-    String urlAssignmentWithSegmentation = String.format("https://abtesting.intuit.com/api/v1/assignments/applications/%s/experiments/%s/users/%s", application, experiment, user);
+    String urlAssignmentWithSegmentation = String.format("{{baseUrl}}/assignments/applications/%s/experiments/%s/users/%s", application, experiment, user);
 
     URL url = new URL(urlAssignmentWithSegmentation);
     HttpURLConnection connection = (HttpURLConnection) url.openConnection();
@@ -75,6 +73,5 @@
 
 }
 
- - +
diff --git a/modules/ui/app/resources/samplecode/java/BatchAssignment.java.html b/modules/ui/app/resources/samplecode/java/BatchAssignment.java.html index 963df669d..98906124d 100644 --- a/modules/ui/app/resources/samplecode/java/BatchAssignment.java.html +++ b/modules/ui/app/resources/samplecode/java/BatchAssignment.java.html @@ -1,6 +1,4 @@ - - - +
 import org.json.simple.JSONObject;
 import org.json.simple.parser.JSONParser;
@@ -19,7 +17,7 @@
 
   public static void main(String[] args) throws IOException, ParseException {
     // TODO: not sure if this will work, since this response is an array of assignments.
-    System.out.print(getBatchAssignment("ApplicationName", "PageName", "UserName"));
+    System.out.print(getBatchAssignment("{{experiment.applicationName}}", "{{pageName}}", "UserName"));
   }
 
 
@@ -35,7 +33,7 @@
    */
   private static Object getBatchAssignment(String application, String page, String user) throws IOException, ParseException {
 
-    String urlAssignment = String.format("https://abtesting.intuit.com/api/v1/assignments/applications/%s/pages/%s/users/%s", application, page, user);
+    String urlAssignment = String.format("{{baseUrl}}/assignments/applications/%s/pages/%s/users/%s", application, page, user);
 
     URL url = new URL(urlAssignment);
     HttpURLConnection connection = (HttpURLConnection) url.openConnection();
@@ -76,7 +74,6 @@
 
 }
 
- - +
diff --git a/modules/ui/app/resources/samplecode/java/BatchAssignmentWithSegmentation.java.html b/modules/ui/app/resources/samplecode/java/BatchAssignmentWithSegmentation.java.html index 208bcfad5..9e35c1482 100644 --- a/modules/ui/app/resources/samplecode/java/BatchAssignmentWithSegmentation.java.html +++ b/modules/ui/app/resources/samplecode/java/BatchAssignmentWithSegmentation.java.html @@ -1,6 +1,4 @@ - - - +
 import org.json.simple.JSONObject;
 import org.json.simple.parser.JSONParser;
@@ -21,7 +19,7 @@
 
   public static void main(String[] args) throws IOException, ParseException {
     // TODO: not sure if this will work, since this response is an array of assignments.
-    System.out.print(postBatchAssignmentWithSegmentation("ApplicationName", "PageName", "UserName", "10001"));
+    System.out.print(postBatchAssignmentWithSegmentation("{{experiment.applicationName}}", "{{pageName}}", "UserName", "10001"));
   }
 
 
@@ -38,7 +36,7 @@
    */
   private static Object postBatchAssignmentWithSegmentation(String application, String page, String user, String salary) throws IOException, ParseException {
 
-    String urlBatchAssignmentWithSegmentation = String.format("https://abtesting.intuit.com/api/v1/assignments/applications/%s/pages/%s/users/%s", application, page, user);
+    String urlBatchAssignmentWithSegmentation = String.format("{{baseUrl}}/assignments/applications/%s/pages/%s/users/%s", application, page, user);
 
     URL url = new URL(urlBatchAssignmentWithSegmentation);
     HttpURLConnection connection = (HttpURLConnection) url.openConnection();
@@ -85,6 +83,4 @@
 
 }
 
- - - +
diff --git a/modules/ui/app/resources/samplecode/java/Impression.java.html b/modules/ui/app/resources/samplecode/java/Impression.java.html index 23c281cb7..f927e33f9 100644 --- a/modules/ui/app/resources/samplecode/java/Impression.java.html +++ b/modules/ui/app/resources/samplecode/java/Impression.java.html @@ -1,6 +1,4 @@ - - - +
 import java.io.IOException;
 import java.io.OutputStreamWriter;
@@ -13,7 +11,7 @@
 public class Impression {
 
   public static void main(String[] args) throws IOException {
-    System.out.print(postImpression("ApplicationName", "ExperimentName", "UserName") ? "Impression recorded" : "Impression not recorded");
+    System.out.print(postImpression("{{experiment.applicationName}}", "{{experiment.label}}", "UserName") ? "Impression recorded" : "Impression not recorded");
   }
 
 
@@ -28,7 +26,7 @@
    */
   private static boolean postImpression(String application, String experiment, String user) throws IOException {
 
-    String urlImpression = String.format("https://abtesting.intuit.com/api/v1/events/applications/%s/experiments/%s/users/%s", application, experiment, user);
+    String urlImpression = String.format("{{baseUrl}}/events/applications/%s/experiments/%s/users/%s", application, experiment, user);
 
     URL url = new URL(urlImpression);
     HttpURLConnection connection = (HttpURLConnection) url.openConnection();
@@ -49,6 +47,5 @@
 
 }
 
- - +
diff --git a/modules/ui/app/resources/samplecode/javascript/action.js.html b/modules/ui/app/resources/samplecode/javascript/action.js.html new file mode 100644 index 000000000..59b376671 --- /dev/null +++ b/modules/ui/app/resources/samplecode/javascript/action.js.html @@ -0,0 +1,49 @@ +
+

+ This example is taken from the Hello World example in the contrib folder of Wasabi. That example uses the + wasabi.js library that is available from the same server as this Admin UI. In order to use the library, + you would add the following to your index.html (or equivalent initial load page): +

+
+    <script src="https://code.jquery.com/jquery-1.12.3.min.js"></script>
+    <script src='{{webServingUrl}}scripts/wasabi.js'></script>
+
+

+ Of course, you can choose whatever version of jQuery works for you and your Wasabi server may be running on + a different host or port. +

+

+ In order to record an action for a user for an experiment using the library, you would make a call like this: +

+
+    // Set up properties that will be the same on all Wasabi calls.
+    WASABI.setOptions({
+        'applicationName': '{{experiment.applicationName}}',
+        'experimentName': '{{experiment.label}}',
+        'protocol': '{{serverProtocol}}',
+        'host': '{{serverHostAndPort}}'
+    });
+
+    // Check Wasabi to record an action for this user.
+    WASABI.postAction(
+        'MyEventName',
+        '{\\\"myPayloadKey1\\\":\\\"payloadKey1Value\\\"}',
+        {
+            'userID': 'UserName'
+        }
+    ).then(
+        function(response) {
+            console.log('postAction: success');
+            // Note: there is no response from posting an Action.
+        },
+        function(error) {
+            console.log('postAction: error');
+        }
+    );
+
+

+ In order to see and run locally a working example using JavaScript, AngularJS and node, go to:
+ https://github.com/intuit/wasabi/tree/develop/contrib/hello-world +

+
+ diff --git a/modules/ui/app/resources/samplecode/javascript/assignment.js.html b/modules/ui/app/resources/samplecode/javascript/assignment.js.html new file mode 100644 index 000000000..88d89cbe9 --- /dev/null +++ b/modules/ui/app/resources/samplecode/javascript/assignment.js.html @@ -0,0 +1,49 @@ +
+

+ This example is taken from the Hello World example in the contrib folder of Wasabi. That example uses the + wasabi.js library that is available from the same server as this Admin UI. In order to use the library, + you would add the following to your index.html (or equivalent initial load page): +

+
+    <script src="https://code.jquery.com/jquery-1.12.3.min.js"></script>
+    <script src='{{webServingUrl}}scripts/wasabi.js'></script>
+
+

+ Of course, you can choose whatever version of jQuery works for you and your Wasabi server may be running on + a different host or port. +

+

+ In order to retrieve an assignment for an experiment using the library, you would make a call like this: +

+
+    // Set up properties that will be the same on all Wasabi calls.
+    WASABI.setOptions({
+        'applicationName': '{{experiment.applicationName}}',
+        'experimentName': '{{experiment.label}}',
+        'protocol': '{{serverProtocol}}',
+        'host': '{{serverHostAndPort}}'
+    });
+
+    // Check Wasabi to see if this user should be in the test and which bucket.
+    WASABI.getAssignment({
+        'userID': 'UserName'
+    }).then(
+        function(response) {
+            console.log('getAssignment: success');
+            console.log(JSON.stringify(response));
+            // This object will include the assignment made and the status, which might tell you the experiment
+            // has not been started, etc.
+            // Note that if the experiment doesn't exist or hasn't been started, response.assignment is undefined, which is OK.
+            console.log(response.assignment);
+        },
+        function(error) {
+            console.log('getAssignment: error');
+        }
+    );
+
+

+ In order to see and run locally a working example using JavaScript, AngularJS and node, go to:
+ https://github.com/intuit/wasabi/tree/develop/contrib/hello-world +

+
+ diff --git a/modules/ui/app/resources/samplecode/javascript/assignment_with_seg.js.html b/modules/ui/app/resources/samplecode/javascript/assignment_with_seg.js.html new file mode 100644 index 000000000..d0195a5ee --- /dev/null +++ b/modules/ui/app/resources/samplecode/javascript/assignment_with_seg.js.html @@ -0,0 +1,57 @@ +
+

+ This example is taken from the Hello World example in the contrib folder of Wasabi. That example uses the + wasabi.js library that is available from the same server as this Admin UI. In order to use the library, + you would add the following to your index.html (or equivalent initial load page): +

+
+    <script src="https://code.jquery.com/jquery-1.12.3.min.js"></script>
+    <script src='{{webServingUrl}}scripts/wasabi.js'></script>
+
+

+ Of course, you can choose whatever version of jQuery works for you and your Wasabi server may be running on + a different host or port. +

+

+ In order to retrieve an assignment for an experiment passing + a profile for use in evaluating a segmentation rule using the library, you would make a call like this: +

+
+    // Set up properties that will be the same on all Wasabi calls.
+    WASABI.setOptions({
+        'applicationName': '{{experiment.applicationName}}',
+        'experimentName': '{{experiment.label}}',
+        'protocol': '{{serverProtocol}}',
+        'host': '{{serverHostAndPort}}'
+    });
+
+    // Check Wasabi to see if this user should be in the test and which bucket.
+    WASABI.getAssignmentWithSegmentation(
+        '{\
+            "profile": {\
+                "platform": "mac"\
+            }\
+        }',
+        {
+            'userID': 'UserName'
+        }
+    ).then(
+        function(response) {
+            console.log('getAssignmentWithSegmentation: success');
+            console.log(JSON.stringify(response));
+            // This object will include the assignment made and the status, which might tell you the experiment
+            // has not been started, etc.
+            // Note that if the experiment doesn't exist or hasn't been started, response.assignment is undefined, which is OK.
+            console.log(response.assignment);
+        },
+        function(error) {
+            console.log('getAssignmentWithSegmentation: error');
+        }
+    );
+
+

+ In order to see and run locally a working example using JavaScript, AngularJS and node, go to:
+ https://github.com/intuit/wasabi/tree/develop/contrib/hello-world +

+
+ diff --git a/modules/ui/app/resources/samplecode/javascript/batch_assignment.js.html b/modules/ui/app/resources/samplecode/javascript/batch_assignment.js.html new file mode 100644 index 000000000..794288bf3 --- /dev/null +++ b/modules/ui/app/resources/samplecode/javascript/batch_assignment.js.html @@ -0,0 +1,49 @@ +
+

+ This example is modeled after the Hello World example in the contrib folder of Wasabi. That example uses the + wasabi.js library that is available from the same server as this Admin UI. In order to use the library, + you would add the following to your index.html (or equivalent initial load page): +

+
+    <script src="https://code.jquery.com/jquery-1.12.3.min.js"></script>
+    <script src='{{webServingUrl}}scripts/wasabi.js'></script>
+
+

+ Of course, you can choose whatever version of jQuery works for you and your Wasabi server may be running on + a different host or port. +

+

+ In order to retrieve an assignment for the experiments associated with a given page (the "batch API") using the library, you would make a call like this: +

+
+    // Set up properties that will be the same on all Wasabi calls.
+    WASABI.setOptions({
+        'applicationName': '{{experiment.applicationName}}',
+        'pageName': '{{pageName}}',
+        'protocol': '{{serverProtocol}}',
+        'host': '{{serverHostAndPort}}'
+    });
+
+    // Check Wasabi to see if this user should be in the test and which bucket.
+    WASABI.getPageAssignment({
+        'userID': 'UserName'
+    }).then(
+        function(response) {
+            console.log('getBatchAssignment: success');
+            console.log(JSON.stringify(response));
+            // This object will include an array of the assignments made and the status of each, which might tell you the experiment
+            // has not been started, etc.
+            // Note that if an experiment doesn't exist or hasn't been started, that particular assignment may not succeed.
+            console.dir(response.assignments);
+        },
+        function(error) {
+            console.log('getBatchAssignment: error');
+        }
+    );
+
+

+ In order to see and run locally a working example using JavaScript, AngularJS and node, go to:
+ https://github.com/intuit/wasabi/tree/develop/contrib/hello-world +

+
+ diff --git a/modules/ui/app/resources/samplecode/javascript/batch_assignment_with_seg.js.html b/modules/ui/app/resources/samplecode/javascript/batch_assignment_with_seg.js.html new file mode 100644 index 000000000..6af39bfa2 --- /dev/null +++ b/modules/ui/app/resources/samplecode/javascript/batch_assignment_with_seg.js.html @@ -0,0 +1,57 @@ +
+

+ This example is modeled after the Hello World example in the contrib folder of Wasabi. That example uses the + wasabi.js library that is available from the same server as this Admin UI. In order to use the library, + you would add the following to your index.html (or equivalent initial load page): +

+
+    <script src="https://code.jquery.com/jquery-1.12.3.min.js"></script>
+    <script src='{{webServingUrl}}scripts/wasabi.js'></script>
+
+

+ Of course, you can choose whatever version of jQuery works for you and your Wasabi server may be running on + a different host or port. +

+

+ In order to retrieve an assignment for the experiments associated with a given page (the "batch API") passing + a profile for use in evaluating segmentation rules using the library, you would make a call like this: +

+
+    // Set up properties that will be the same on all Wasabi calls.
+    WASABI.setOptions({
+        'applicationName': '{{experiment.applicationName}}',
+        'pageName': '{{pageName}}',
+        'protocol': '{{serverProtocol}}',
+        'host': '{{serverHostAndPort}}'
+    });
+
+    // Check Wasabi to see if this user should be in the test and which bucket.
+    WASABI.getPageAssignmentWithSegmentation(
+        '{\
+            "profile": {\
+                "platform": "mac"\
+            }\
+        }',
+        {
+            'userID': 'UserName'
+        }
+    ).then(
+        function(response) {
+            console.log('getBatchAssignmentWithSegmentation: success');
+            console.log(JSON.stringify(response));
+            // This object will include an array of the assignments made and the status of each, which might tell you the experiment
+            // has not been started, etc.
+            // Note that if an experiment doesn't exist or hasn't been started, that particular assignment may not succeed.
+            console.dir(response.assignments);
+        },
+        function(error) {
+            console.log('getBatchAssignmentWithSegmentation: error');
+        }
+    );
+
+

+ In order to see and run locally a working example using JavaScript, AngularJS and node, go to:
+ https://github.com/intuit/wasabi/tree/develop/contrib/hello-world +

+
+ diff --git a/modules/ui/app/resources/samplecode/javascript/impression.js.html b/modules/ui/app/resources/samplecode/javascript/impression.js.html new file mode 100644 index 000000000..3b0c6a67d --- /dev/null +++ b/modules/ui/app/resources/samplecode/javascript/impression.js.html @@ -0,0 +1,47 @@ +
+

+ This example is taken from the Hello World example in the contrib folder of Wasabi. That example uses the + wasabi.js library that is available from the same server as this Admin UI. In order to use the library, + you would add the following to your index.html (or equivalent initial load page): +

+
+    <script src="https://code.jquery.com/jquery-1.12.3.min.js"></script>
+    <script src='{{webServingUrl}}scripts/wasabi.js'></script>
+
+

+ Of course, you can choose whatever version of jQuery works for you and your Wasabi server may be running on + a different host or port. +

+

+ In order to record an impression for a user for an experiment using the library, you would make a call like this: +

+
+    // Set up properties that will be the same on all Wasabi calls.
+    WASABI.setOptions({
+        'applicationName': '{{experiment.applicationName}}',
+        'experimentName': '{{experiment.label}}',
+        'protocol': '{{serverProtocol}}',
+        'host': '{{serverHostAndPort}}'
+    });
+
+    // Check Wasabi to record an impression for this user.
+    WASABI.postImpression(
+        {
+            'userID': 'UserName'
+        }
+    ).then(
+        function(response) {
+            console.log('postImpression: success');
+            // Note: there is no response from posting an Impression.
+        },
+        function(error) {
+            console.log('postImpression: error');
+        }
+    );
+
+

+ In order to see and run locally a working example using JavaScript, AngularJS and node, go to:
+ https://github.com/intuit/wasabi/tree/develop/contrib/hello-world +

+
+ diff --git a/modules/ui/app/resources/samplecode/python/action.py.html b/modules/ui/app/resources/samplecode/python/action.py.html index bd4cc811f..b2d24b1c9 100644 --- a/modules/ui/app/resources/samplecode/python/action.py.html +++ b/modules/ui/app/resources/samplecode/python/action.py.html @@ -1,6 +1,4 @@ - - - +
 import requests
 import json
@@ -15,7 +13,7 @@
         user:        the user who should be assigned
     """
 
-    urlAssignment = "https://abtesting.intuit.com/api/v1/events/applications/%s/experiments/%s/users/%s" %(application, experiment, user);
+    urlAssignment = "{{baseUrl}}/events/applications/%s/experiments/%s/users/%s" %(application, experiment, user);
 
     headers = {'content-type': 'application/json'}
     # The actoin name can be freely assigned and an additional payload is
@@ -29,11 +27,10 @@
     return False
 
 if __name__ == "__main__":
-    application = 'ApplicationName'
-    experiment = 'ExperimentName'
+    application = '{{experiment.applicationName}}'
+    experiment = '{{experiment.label}}'
     user = 'UserName'
 
     print('Action recorded' if post_action(application, experiment, user) else 'Action not recorded')
 
- - +
diff --git a/modules/ui/app/resources/samplecode/python/assignments.py.html b/modules/ui/app/resources/samplecode/python/assignments.py.html index 50f82d42c..413e6424d 100644 --- a/modules/ui/app/resources/samplecode/python/assignments.py.html +++ b/modules/ui/app/resources/samplecode/python/assignments.py.html @@ -1,6 +1,4 @@ - - - +
 import requests
 import json
@@ -15,7 +13,7 @@
         experiment:  the running experiment for which the assignment should be retrieved
         user:        the user who should be assigned
     """
-    urlAssignment = "https://abtesting.intuit.com/api/v1/assignments/applications/%s/experiments/%s/users/%s" %(application, experiment, user);
+    urlAssignment = "{{baseUrl}}/assignments/applications/%s/experiments/%s/users/%s" %(application, experiment, user);
     r = requests.get(urlAssignment)
     try:
         assignment = json.loads(r.text)['assignment']
@@ -28,11 +26,10 @@
     return assignment
 
 if __name__ == "__main__":
-    application = 'ApplicationName'
-    experiment = 'ExperimentName'
+    application = '{{experiment.applicationName}}'
+    experiment = '{{experiment.label}}'
     user = 'UserName'
 
     print(get_assignment(application, experiment, user))
 
- - +
diff --git a/modules/ui/app/resources/samplecode/python/assignments_with_seg.py.html b/modules/ui/app/resources/samplecode/python/assignments_with_seg.py.html index d664cbc4e..a774fc51c 100644 --- a/modules/ui/app/resources/samplecode/python/assignments_with_seg.py.html +++ b/modules/ui/app/resources/samplecode/python/assignments_with_seg.py.html @@ -1,6 +1,4 @@ - - - +
 import requests
 import json
@@ -17,7 +15,7 @@
         salary:      the salary of the user, to be used in evaluating a segmentation rule
     """
 
-    urlAssignment = "https://abtesting.intuit.com/api/v1/assignments/applications/%s/experiments/%s/users/%s" %(application, experiment, user);
+    urlAssignment = "{{baseUrl}}/assignments/applications/%s/experiments/%s/users/%s" %(application, experiment, user);
 
     headers = {'content-type': 'application/json'}
     profile = {'profile':{'salary': salary}}
@@ -34,12 +32,11 @@
     return assignment
 
 if __name__ == "__main__":
-    application = 'ApplicationName'
-    experiment = 'ExperimentName'
+    application = '{{experiment.applicationName}}'
+    experiment = '{{experiment.label}}'
     user = 'UserName'
     salary = '10000'
 
     print(post_assignment_with_segmentation(application, experiment, user, salary))
 
- - +
diff --git a/modules/ui/app/resources/samplecode/python/batch_assignments.py.html b/modules/ui/app/resources/samplecode/python/batch_assignments.py.html index 1572d8e2f..f254fbfa8 100644 --- a/modules/ui/app/resources/samplecode/python/batch_assignments.py.html +++ b/modules/ui/app/resources/samplecode/python/batch_assignments.py.html @@ -1,6 +1,4 @@ - - - +
 import requests
 import json
@@ -15,7 +13,7 @@
         page:        the page (group of experiments) for which assignments should be retrieved
         user:        the user who should be assigned
     """
-    urlAssignment = "https://abtesting.intuit.com/api/v1/assignments/applications/%s/pages/%s/users/%s" %(application, page, user);
+    urlAssignment = "{{baseUrl}}/assignments/applications/%s/pages/%s/users/%s" %(application, page, user);
     r = requests.get(urlAssignment)
     try:
         assignments = json.loads(r.text)['assignments']
@@ -28,11 +26,10 @@
     return assignments
 
 if __name__ == "__main__":
-    application = 'ApplicationName'
-    page = 'PageName'
+    application = '{{experiment.applicationName}}'
+    page = '{{pageName}}'
     user = 'UserName'
 
     print(get_batch_assignment(application, page, user))
 
- - +
diff --git a/modules/ui/app/resources/samplecode/python/batch_assignments_with_seg.py.html b/modules/ui/app/resources/samplecode/python/batch_assignments_with_seg.py.html index 55f8bd60b..24bf9e016 100644 --- a/modules/ui/app/resources/samplecode/python/batch_assignments_with_seg.py.html +++ b/modules/ui/app/resources/samplecode/python/batch_assignments_with_seg.py.html @@ -1,6 +1,4 @@ - - - +
 import requests
 import json
@@ -17,7 +15,7 @@
         salary:      the salary of the user, to be used in evaluating a segmentation rule
     """
 
-    urlAssignment = "https://abtesting.intuit.com/api/v1/assignments/applications/%s/pages/%s/users/%s" %(application, page, user);
+    urlAssignment = "{{baseUrl}}/assignments/applications/%s/pages/%s/users/%s" %(application, page, user);
 
     headers = {'content-type': 'application/json'}
     profile = {'profile':{'salary': salary}}
@@ -34,12 +32,11 @@
     return assignments
 
 if __name__ == "__main__":
-    application = 'ApplicationName'
-    page = 'PageName'
+    application = '{{experiment.applicationName}}'
+    page = '{{pageName}}'
     user = 'UserName'
     salary = '10000'
 
     print(post_batch_assignment_with_segmentation(application, page, user, salary))
 
- - +
diff --git a/modules/ui/app/resources/samplecode/python/impression.py.html b/modules/ui/app/resources/samplecode/python/impression.py.html index deeffb910..1ba663a66 100644 --- a/modules/ui/app/resources/samplecode/python/impression.py.html +++ b/modules/ui/app/resources/samplecode/python/impression.py.html @@ -1,6 +1,4 @@ - - - +
 import requests
 import json
@@ -15,7 +13,7 @@
         user:        the user who should be assigned
     """
 
-    urlAssignment = "https://abtesting.intuit.com/api/v1/events/applications/%s/experiments/%s/users/%s" %(application, experiment, user);
+    urlAssignment = "{{baseUrl}}/events/applications/%s/experiments/%s/users/%s" %(application, experiment, user);
     headers = {'content-type': 'application/json'}
     events = {'events':[{'name':'IMPRESSION'}]}
 
@@ -26,11 +24,10 @@
     return False
 
 if __name__ == "__main__":
-    application = 'ApplicationName'
-    experiment = 'ExperimentName'
+    application = '{{experiment.applicationName}}'
+    experiment = '{{experiment.label}}'
     user = 'UserName'
 
     print('Impression recorded' if post_impression(application, experiment, user) else 'Impression not recorded')
 
- - +
diff --git a/modules/ui/app/scripts/controllers/APICallsCtrl.js b/modules/ui/app/scripts/controllers/APICallsCtrl.js index e22a140ea..bd4f11f33 100644 --- a/modules/ui/app/scripts/controllers/APICallsCtrl.js +++ b/modules/ui/app/scripts/controllers/APICallsCtrl.js @@ -1,8 +1,28 @@ 'use strict'; angular.module('wasabi.controllers'). - controller('APICallsCtrl', ['$scope', 'ConfigFactory', - function ($scope, ConfigFactory) { + controller('APICallsCtrl', ['$scope', '$modal', 'ConfigFactory', + function ($scope, $modal, ConfigFactory) { $scope.hostUrl = ConfigFactory.baseUrl(); + $scope.showCode = function(codeURL) { + var modalInstance = $modal.open({ + templateUrl: 'views/DisplaySourceCodeModal.html', + controller: 'DisplaySourceCodeModalCtrl', + windowClass: 'xxx-dialog', + backdrop: 'static', + resolve: { + codeURL: function () { + return codeURL; + }, + experiment: function() { + return $scope.experiment; + }, + pageName: $scope.firstPageEncoded + } + }); + + modalInstance.result.then(function () { + }); + }; }]); diff --git a/modules/ui/app/scripts/controllers/DisplaySourceCodeModal.js b/modules/ui/app/scripts/controllers/DisplaySourceCodeModal.js index 41206621f..5ed78cebf 100644 --- a/modules/ui/app/scripts/controllers/DisplaySourceCodeModal.js +++ b/modules/ui/app/scripts/controllers/DisplaySourceCodeModal.js @@ -3,10 +3,19 @@ angular.module('wasabi.controllers') .controller('DisplaySourceCodeModalCtrl', - ['$scope', '$filter', '$modalInstance', 'codeURL', 'UtilitiesFactory', '$modal', 'ConfigFactory', - function ($scope, $filter, $modalInstance, codeURL, UtilitiesFactory, $modal, ConfigFactory) { + ['$scope', '$filter', '$modalInstance', 'codeURL', 'experiment', 'pageName', 'UtilitiesFactory', '$modal', 'ConfigFactory', + function ($scope, $filter, $modalInstance, codeURL, experiment, pageName, UtilitiesFactory, $modal, ConfigFactory) { - $scope.codeURL = '../' + codeURL; + $scope.webServingUrl = window.location.protocol + '//' + window.location.host + '/'; + $scope.codeURL = $scope.webServingUrl + codeURL; + $scope.experiment = experiment; + $scope.baseUrl = ConfigFactory.baseUrl(); + $scope.pageName = pageName; + + // Get the protocol and hostname, including port, from server URL, for use in examples. + var parts = ConfigFactory.baseUrl().split('/'); + $scope.serverProtocol = parts[0]; + $scope.serverHostAndPort = parts[2]; $scope.cancel = function () { // Changed this to call close() instead of dismiss(). We need to catch the Close or Cancel so diff --git a/modules/ui/app/scripts/controllers/ExperimentDetailsCtrl.js b/modules/ui/app/scripts/controllers/ExperimentDetailsCtrl.js index da8bf4289..d40768ee0 100644 --- a/modules/ui/app/scripts/controllers/ExperimentDetailsCtrl.js +++ b/modules/ui/app/scripts/controllers/ExperimentDetailsCtrl.js @@ -1109,23 +1109,6 @@ angular.module('wasabi.controllers'). return false; }; - $scope.showCode = function(codeURL) { - var modalInstance = $modal.open({ - templateUrl: 'views/DisplaySourceCodeModal.html', - controller: 'DisplaySourceCodeModalCtrl', - windowClass: 'xxx-dialog', - backdrop: 'static', - resolve: { - codeURL: function () { - return codeURL; - } - } - }); - - modalInstance.result.then(function () { - }); - }; - $scope.openSegmentationTestModal = function () { var modalInstance = $modal.open({ templateUrl: 'views/SegmentationTestModal.html', diff --git a/modules/ui/app/scripts/controllers/ExperimentModalCtrl.js b/modules/ui/app/scripts/controllers/ExperimentModalCtrl.js index 8117b0b9f..80cfaa88e 100644 --- a/modules/ui/app/scripts/controllers/ExperimentModalCtrl.js +++ b/modules/ui/app/scripts/controllers/ExperimentModalCtrl.js @@ -12,7 +12,8 @@ angular.module('wasabi.controllers') $scope.data = { disableSimple: false, - userCapValue: (experiment && experiment.isRapidExperiment ? experiment.userCap : '') + userCapValue: (experiment && experiment.isRapidExperiment ? experiment.userCap : ''), + apiLanguage: 'curl' }; $scope.experiment = experiment; diff --git a/modules/ui/app/styles/wasabi.scss b/modules/ui/app/styles/wasabi.scss index 75e1a0dff..7a44a7dc7 100755 --- a/modules/ui/app/styles/wasabi.scss +++ b/modules/ui/app/styles/wasabi.scss @@ -4508,3 +4508,21 @@ form input.ng-dirty.ng-invalid:not(.ng-focused) { .gridWithAdvanced { margin-top: 40px; } + +.displaySourceCode { + display: block; + overflow: auto; + background: white; + height: 500px; + padding: 0 20px; + p { + margin: 0 0 10px; + } + pre { + font-family: Menlo, Monaco, Consolas, "Courier New", monospace; + font-size: 13px; + background: white; + overflow: visible; + margin-bottom: 10px; + } +} \ No newline at end of file diff --git a/modules/ui/app/views/APICallsTab.html b/modules/ui/app/views/APICallsTab.html new file mode 100644 index 000000000..acff540c6 --- /dev/null +++ b/modules/ui/app/views/APICallsTab.html @@ -0,0 +1,63 @@ +
+ + Curl + JavaScript + Java + Python +
+
Assignment
+ + + + View code... + View code... + View code... +
+
+
Record an Impression
+ + + View code... + View code... + View code... +
+
+
Record an Action
+ + View code... + View code... + View code... +
+
+
Batch Assignment
+ + View code... + View code... + View code... +
+
+
Assignment Providing Profile For Use By Segmentation Rule
+ + View code... + View code... + View code... +
+
+
Batch Assignment Providing Profile For Use By Segmentation Rule
+ + View code... + View code... + View code... +
+
+
Experiment ID
+ +
+
diff --git a/modules/ui/app/views/DisplaySourceCodeModal.html b/modules/ui/app/views/DisplaySourceCodeModal.html index e15993eac..fc655b727 100644 --- a/modules/ui/app/views/DisplaySourceCodeModal.html +++ b/modules/ui/app/views/DisplaySourceCodeModal.html @@ -1,8 +1,8 @@
-

Analysis

+

Example Source Code

- +
diff --git a/modules/ui/app/views/ExperimentDetails.html b/modules/ui/app/views/ExperimentDetails.html index 84765be40..ce0bfad6f 100644 --- a/modules/ui/app/views/ExperimentDetails.html +++ b/modules/ui/app/views/ExperimentDetails.html @@ -303,67 +303,10 @@

{{experiment.applicationName}}
{
-
- - Curl - JavaScript - Java - Python -
-
Assignment
- - - - View code... - View code... -
-
-
Record an Impression
- - - View code... - View code... -
-
-
Record an Action
- - View code... - View code... -
-
-
Batch Assignment
- - View code... - View code... -
-
-
Assignment Providing Profile For Use By Segmentation Rule
- - View code... - View code... -
-
-
Batch Assignment Providing Profile For Use By Segmentation Rule
- - View code... - View code... -
-
-
Experiment ID
- -
-
+
-
Download Assignment Data Close diff --git a/modules/ui/app/views/ExperimentModal.html b/modules/ui/app/views/ExperimentModal.html index e7582e0ba..2d9d294a8 100644 --- a/modules/ui/app/views/ExperimentModal.html +++ b/modules/ui/app/views/ExperimentModal.html @@ -435,45 +435,7 @@

Edit Experiment

-
- -
(Note: This experiment is in Draft and so these API calls will not succeed.)
-
-
Assignment
- -
-
-
Record an Impression
- -
-
-
Record an Action
- -
-
-
Batch Assignment
- -
-
-
Assignment Providing Profile For Use By Segmentation Rule
- -
-
-
Batch Assignment Providing Profile For Use By Segmentation Rule
- -
-
-
Experiment ID
- -
-
+