A Java wrapper for the Ushahidi API. It's simply a Java library that wraps the raw HTTP calls to the Ushahidi APIs. The goal of this SDK is to ease Ushahidi API integration into your applications and to support all the Ushahidi public and admin APIs that are there. For more information on the Ushahidi API, see; https://wiki.ushahidi.com/display/WIKI/Ushahidi+REST+API. The project is hosted on github.com
The Ushahidi Java SDK is built using Apache Ant
Run the following command to build a JAR file of the SDK with all the dependencies.
ant dist
And to compile all the source codes, run
ant compile
The UshahidiApi class allows you to access the various task implemented by this SDK through the object you will create.
UshahidiApi ushahidi = new UshahidiApi("http://demo.ushahidi.com"); //set credentials for the admin APIs ushahidi.factory.setUsername("username"); ushahidi.factory.setPassword("password"); |
Pull all visible categories that have been submitted to the Ushahidi platform
CategoriesTask task = ushahidi.factory.createCategoriesTask(); List<Category> categories = task.all(); |
Add a news article to an existing report
TagNewsTask task = ushahidi.factory.createTagNewsTask(); Response response = task.tagNews(4, "http://www.android.com/whatsnew/"); |
Add a comment to an existing report. You need to know the report ID to be able to add the comment
Comment c = new Comment(); c.setAuthor("Foo Bar"); c.setReportId(64); c.setDescription("Some sample comments"); CommentFields comment = new CommentFields(); comment.fill(c); comment.setEmail("foo@bar.com"); CommentsTask task = ushahidi.factory.createCommentsTask(); Response response = task.submit(comment); |
Submit a new report to the Ushahidi deployment
ReportTask task = ushahidi.factory.createReportTask(); Incident i = new Incident(); i.setTitle("test title"); i.setDescription("test desc"); i.setDate(new Date()); i.setLatitude(12.34); i.setLongitude(56.78); i.setLocationName("foobar"); ReportFields fields = new ReportFields(); fields.fill(i); fields.addCategory(7); fields.addPhotos(new File("/sdcard/photo0.jpg")); Response response = task.submit(fields); |
You can download the latest release from the projects github's download page . It has a single Jar file that you can include in your project. https://github.com/ushahidi/Ushahidi_Java/downloads
You can find the Javadoc which contains all the relevant documentation on the classes and the packages in the doc directory found in the root folder of the project.
To generate recent version of the Javadoc, run
ant javadoc
To clean up the generated distribution file and Javadoc in the root folder, run
ant clean
You can help on this project by using the SDK and giving feedback on how to improvement it. Also, you can browse through the issue tracker to find out which issue you can contribute a fix.