Created
February 20, 2012 16:27
-
-
Save timhodson/1869997 to your computer and use it in GitHub Desktop.
JAVA: Retrieve Kasabi API key from shell environment.
This file contains hidden or 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
| 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