Skip to content

Commit

Permalink
Finished support for JavaScript, Java and Python code examples, inclu…
Browse files Browse the repository at this point in the history
…ding 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.
  • Loading branch information
longdogz committed Apr 13, 2017
1 parent 37235f8 commit 7cc2fc3
Show file tree
Hide file tree
Showing 27 changed files with 483 additions and 213 deletions.
11 changes: 4 additions & 7 deletions modules/ui/app/resources/samplecode/java/Action.java.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<html>
<head></head>
<body>
<div class="displaySourceCode">
<pre>
import java.io.IOException;
import java.io.OutputStreamWriter;
Expand All @@ -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");
}


Expand All @@ -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();
Expand All @@ -50,6 +48,5 @@

}
</pre>
</body>
</html>
</div>

11 changes: 4 additions & 7 deletions modules/ui/app/resources/samplecode/java/Assignment.java.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<html>
<head></head>
<body>
<div class="displaySourceCode">
<pre>
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
Expand All @@ -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"));
}


Expand All @@ -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();
Expand Down Expand Up @@ -66,7 +64,6 @@

}
</pre>
</body>
</html>
</div>


Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<html>
<head></head>
<body>
<div class="displaySourceCode">
<pre>
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
Expand All @@ -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"));
}


Expand All @@ -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();
Expand Down Expand Up @@ -75,6 +73,5 @@

}
</pre>
</body>
</html>
</div>

Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<html>
<head></head>
<body>
<div class="displaySourceCode">
<pre>
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
Expand All @@ -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"));
}


Expand All @@ -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();
Expand Down Expand Up @@ -76,7 +74,6 @@

}
</pre>
</body>
</html>
</div>


Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<html>
<head></head>
<body>
<div class="displaySourceCode">
<pre>
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
Expand All @@ -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"));
}


Expand All @@ -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();
Expand Down Expand Up @@ -85,6 +83,4 @@

}
</pre>
</body>
</html>

</div>
11 changes: 4 additions & 7 deletions modules/ui/app/resources/samplecode/java/Impression.java.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<html>
<head></head>
<body>
<div class="displaySourceCode">
<pre>
import java.io.IOException;
import java.io.OutputStreamWriter;
Expand All @@ -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");
}


Expand All @@ -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();
Expand All @@ -49,6 +47,5 @@

}
</pre>
</body>
</html>
</div>

49 changes: 49 additions & 0 deletions modules/ui/app/resources/samplecode/javascript/action.js.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<div class="displaySourceCode">
<p>
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):
</p>
<pre>
&lt;script src="https://code.jquery.com/jquery-1.12.3.min.js">&lt;/script>
&lt;script src='{{webServingUrl}}scripts/wasabi.js'>&lt;/script>
</pre>
<p>
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.
</p>
<p>
In order to record an action for a user for an experiment using the library, you would make a call like this:
</p>
<pre>
// 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');
}
);
</pre>
<p>
In order to see and run locally a working example using JavaScript, AngularJS and node, go to:<br/>
<a href="https://github.com/intuit/wasabi/tree/develop/contrib/hello-world" target="_blank">https://github.com/intuit/wasabi/tree/develop/contrib/hello-world</a>
</p>
</div>

49 changes: 49 additions & 0 deletions modules/ui/app/resources/samplecode/javascript/assignment.js.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<div class="displaySourceCode">
<p>
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):
</p>
<pre>
&lt;script src="https://code.jquery.com/jquery-1.12.3.min.js">&lt;/script>
&lt;script src='{{webServingUrl}}scripts/wasabi.js'>&lt;/script>
</pre>
<p>
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.
</p>
<p>
In order to retrieve an assignment for an experiment using the library, you would make a call like this:
</p>
<pre>
// 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');
}
);
</pre>
<p>
In order to see and run locally a working example using JavaScript, AngularJS and node, go to:<br/>
<a href="https://github.com/intuit/wasabi/tree/develop/contrib/hello-world" target="_blank">https://github.com/intuit/wasabi/tree/develop/contrib/hello-world</a>
</p>
</div>

Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<div class="displaySourceCode">
<p>
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):
</p>
<pre>
&lt;script src="https://code.jquery.com/jquery-1.12.3.min.js">&lt;/script>
&lt;script src='{{webServingUrl}}scripts/wasabi.js'>&lt;/script>
</pre>
<p>
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.
</p>
<p>
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:
</p>
<pre>
// 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');
}
);
</pre>
<p>
In order to see and run locally a working example using JavaScript, AngularJS and node, go to:<br/>
<a href="https://github.com/intuit/wasabi/tree/develop/contrib/hello-world" target="_blank">https://github.com/intuit/wasabi/tree/develop/contrib/hello-world</a>
</p>
</div>

0 comments on commit 7cc2fc3

Please sign in to comment.