Skip to content

Instantly share code, notes, and snippets.

@ghermeto
Created August 4, 2011 14:46
Show Gist options
  • Save ghermeto/1125323 to your computer and use it in GitHub Desktop.
Save ghermeto/1125323 to your computer and use it in GitHub Desktop.
Using blitz java api client
package com.example;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
import io.blitz.curl.*;
import io.blitz.curl.config.*;
import io.blitz.curl.rush.*;
import io.blitz.curl.sprint.*;
public class BlitzApp {
private static String USERNAME = "[email protected]";
private static String API_KEY = "aqbcdge-sjfkgurti-sjdhgft-skdiues";
private static String MY_URL = "http://your.cool.app";
public static void main( String[] args ) {
// Run sprint using command parser
try {
Sprint s1 = (Sprint) io.blitz.command.Curl.parse(
USERNAME,
API_KEY,
"-r japan http://your.cool.app"
);
s1.addListener(new ISprintListener() {
public boolean onStatus(SprintResult result) {
System.err.print(".");
}
public void onComplete(SprintResult result) {
System.err.println("SUCCESS!");
}
});
s1.execute();
} catch (Exception ex) {
System.err.println("Sprint failed.");
}
// Run a sprint using setters
try {
Sprint s2 = new Sprint(USERNAME, API_KEY);
s2.setUrl(new URL(MY_URL));
s2.addListener(new ISprintListener() {
public boolean onStatus(SprintResult result) {
System.err.print(".");
}
public void onComplete(SprintResult result) {
System.err.println("SUCCESS!");
}
});
s2.execute();
} catch (Exception ex) {
System.err.println("Sprint failed.");
}
// Run a rush using command parser
try {
Rush r1 = (Rush) io.blitz.command.Curl.parse(
USERNAME,
API_KEY,
"-p 10-50:60 -r california http://your.cool.app"
);
r1.addListener(new IRushListener() {
public boolean onStatus(RushResult result) {
System.err.print(".");
}
public void onComplete(RushResult result) {
System.err.println("SUCCESS!");
}
});
r1.execute();
} catch (Exception ex) {
System.err.println("Rush failed.");
}
// Run a rush using setters
try {
Rush r2 = new Rush(USERNAME, API_KEY);
r2.setUrl(new URL(MY_URL));
Collection<Interval> intervals = new ArrayList<Interval>();
intervals.add(new Interval(1, 10, 10));
r2.setPattern(new Pattern(intervals));
r2.addListener(new IRushListener() {
public boolean onStatus(RushResult result) {
System.err.print(".");
}
public void onComplete(RushResult result) {
System.err.println("SUCCESS!");
}
});
r2.execute();
} catch (Exception ex) {
System.err.println("Rush failed.");
}
}
}
<project>
<groupId>com.example</groupId>
<artifactId>my-blitz-app</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>My Blitz App</name>
<url>http://example.com</url>
<dependencies>
<dependency>
<groupId>io.blitz</groupId>
<artifactId>api-client</artifactId>
<version>0.2.3</version>
</dependency>
</dependencies>
</project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment