-
Notifications
You must be signed in to change notification settings - Fork 238
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a0604d2
commit bb1cc73
Showing
5 changed files
with
97 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import java.io.IOException; | ||
import java.io.OutputStreamWriter; | ||
import java.net.HttpURLConnection; | ||
import java.net.URL; | ||
|
||
/** | ||
* This class contains the sample code to post a Wasabi action. | ||
*/ | ||
public class Action { | ||
|
||
public static void main(String[] args) throws IOException { | ||
System.out.print(postAction("ApplicationName", "ExperimentName", "UserName") ? "Action recorded" : "Action not recorded"); | ||
} | ||
|
||
|
||
/** | ||
* This method calls the Wasabi Api to post an action for the specified experiment and user. | ||
* | ||
* @param application the ApplicationName the experiment is running in | ||
* @param experiment the name of the Experiment | ||
* @param user the user for whom the action should be posted | ||
* @return <code>true</code> if the action was recorded <code>false</code> otherwise | ||
* @throws IOException | ||
*/ | ||
private static boolean postAction(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); | ||
|
||
URL url = new URL(urlImpression); | ||
HttpURLConnection connection = (HttpURLConnection) url.openConnection(); | ||
connection.setRequestProperty("content-type", "application/json"); | ||
connection.setRequestMethod("POST"); | ||
connection.setDoOutput(true); | ||
|
||
OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream()); | ||
// the following could also be created with json frameworks | ||
writer.write("{\"events\":[{\"name\":\"ButtonClicked\", \"payload\":\"{\\\"state\\\":\\\"CA\\\"}\"}]}"); | ||
writer.flush(); | ||
|
||
// give it 500 milliseconds to respond | ||
connection.setReadTimeout(500); | ||
connection.connect(); | ||
|
||
return connection.getResponseCode() == 201 ? true : false; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import java.io.IOException; | ||
import java.io.OutputStreamWriter; | ||
import java.net.HttpURLConnection; | ||
import java.net.URL; | ||
|
||
/** | ||
* This class contains the sample code to post a Wasabi impression. | ||
*/ | ||
public class Impression { | ||
|
||
public static void main(String[] args) throws IOException { | ||
System.out.print(postImpression("ApplicationName", "ExperimentName", "UserName") ? "Impression recorded" : "Impression not recorded"); | ||
} | ||
|
||
|
||
/** | ||
* This method calls the Wasabi Api to post an impression for the specified experiment and user. | ||
* | ||
* @param application the ApplicationName the experiment is running in | ||
* @param experiment the name of the Experiment | ||
* @param user the user for whom the Impression should be posted | ||
* @return <code>true</code> if the impression was recorded <code>false</code> otherwise | ||
* @throws IOException | ||
*/ | ||
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); | ||
|
||
URL url = new URL(urlImpression); | ||
HttpURLConnection connection = (HttpURLConnection) url.openConnection(); | ||
connection.setRequestProperty("content-type", "application/json"); | ||
connection.setRequestMethod("POST"); | ||
connection.setDoOutput(true); | ||
|
||
OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream()); | ||
writer.write("{\"events\":[{\"name\":\"IMPRESSION\"}]}"); | ||
writer.flush(); | ||
|
||
// give it 500 milliseconds to respond | ||
connection.setReadTimeout(500); | ||
connection.connect(); | ||
|
||
return connection.getResponseCode() == 201 ? true : false; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters