Skip to content

Instantly share code, notes, and snippets.

@timhodson
Created February 20, 2012 16:27
Show Gist options
  • Select an option

  • Save timhodson/1869997 to your computer and use it in GitHub Desktop.

Select an option

Save timhodson/1869997 to your computer and use it in GitHub Desktop.
JAVA: Retrieve Kasabi API key from shell environment.
package example;
import com.hp.hpl.jena.query.Query;
import com.hp.hpl.jena.query.QueryExecution;
import com.hp.hpl.jena.query.QueryExecutionFactory;
import com.hp.hpl.jena.query.QueryFactory;
import com.hp.hpl.jena.query.ResultSet;
import com.hp.hpl.jena.query.ResultSetFormatter;
import com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP;
public class ExampleKasabiSparqlApiUse {
// Get our apikey from the environment
private static final String apikey = System.getenv("KASABI_API_KEY");
public static void main(String[] args) {
String queryString = "SELECT * {?s?p?o} LIMIT 10";
Query query = QueryFactory.create(queryString);
QueryExecution qexec =
QueryExecutionFactory.sparqlService("http://api.kasabi.com/dataset/bbc/apis/sparql", query);
// the next line adds the apikey parameter to our query
((QueryEngineHTTP) qexec).addParam("apikey", apikey);
ResultSet results = qexec.execSelect();
ResultSetFormatter.out(System.out, results, query);
qexec.close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment