#CartoDB Java Client
##Description Tiny CartoDB Java client that can be instantiated as regular (public) or secured (private). Once instantiated, you can send queries to CartoDB and get a JSON string as response.
##Usage
With this library you have access to private and public tables. In order to access to public tables you do not need to be authenticated but if you want to read or write data to a private table or write data to a public table you need to.
CartoDB provides two ways to auth, oauth or api key, please read CartoDB Authentication documentation for detailed info on this topic.
//Access to your private table or update your table
CartoDBClientIF cartoDBCLient= new SecuredCartoDBClient("youraccount","yourpassword","consumerKey","consumerSecret");
System.out.println(cartoDBCLient.executeQuery("UPDATE yourtable SET yourvalue = 'test' WHERE yourid = 1"));
//Access to your private table or update your table using the api key
CartoDBClientIF cartoDBCLient= new ApiKeyCartoDBClient("youraccount", YOUR_API_KEY);
System.out.println(cartoDBCLient.executeQuery("UPDATE yourtable SET yourvalue = 'test' WHERE yourid = 1"));
//Access to your public table
CartoDBClientIF cartoDBCLient= new CartoDBClient("youraccount");
System.out.println(cartoDBCLient.executeQuery("SELECT * FROM yourtable LIMIT 1"));
executeQuery method returns the raw json response. If you want to retrieve the json already parsed into a java object you can use request method, see next example:
// get rows as a Map
CartoDBResponse<Map<String, Object>> res = cartoDBCLient.request("select * from mytable limit 1");
System.out.print(res.getTotal_rows(), 1);
System.out.print(res.getRows().get(0).get("cartodb_id"));
##Dependencies Included in lib folder
Create your own Secret class, e.g. src/test/java/com/cartodb/Secret.java and fill in your credentials and testing table info
public class Secret {
public static final String USER = "";
public static final String API_KEY = "";
public static final String PASSWORD = "";
public static final String CONSUMER_KEY = "";
public static final String CONSUMER_SECRET = "";
public static final String EXISTING_TABLE_WITH_DATA = "";
}
##TODO
- Include error JSON on HTTP response 400.