Skip to content

Instantly share code, notes, and snippets.

@SantiMunin
Last active December 16, 2015 19:19
Show Gist options
  • Save SantiMunin/5484519 to your computer and use it in GitHub Desktop.
Save SantiMunin/5484519 to your computer and use it in GitHub Desktop.

JReport

A Java wrapper of the Open311 API. It allows developers of web, mobile or desktop to use the Open311 without effort and almost no configuration.

Installation

  • Add the .jar to your Java project
  • Add the maven dependency: .....

Overview

Some code samples:

// First of all you have to obtain your wrapper object
JWrapper sfWrapper = JReport.getInstance().createWrapper(CITY.SAN_FRANCISCO, "my_sf_api_key");

// Get all services
List<Service> services = sfWrapper.getServices();

Service service = services.get(0);
service.getName() -> "Cans left out 24x7"
service.getCode() -> "001"
service.toString() -> "[001] Cans left out 24x7"
service.getGroup() -> "sanitation"

// Get all the service requests
List<ServiceRequest> requests = sfWrapper.getServiceRequests();
ServiceRequest request = requests.get(0);
request.getId() -> 638344
request.getStatus() -> Status.CLOSED
request.getServiceCode() -> 6

// You could also get service requests by the service code
List<ServiceRequest> requests = sfWrapper.getServiceRequests("001");

How would I implement it?

The wrapper will need the following subsystems:

  • Data parsing (XML and JSON)
  • HTTP requests (using Apache HttpComponents) and data caching.
  • System facade (a simple entry point, the JReport and JWrapper classes)
  • In most applications you can't perform requests through the main thread. It would be very interesting to develop a simple subsystem to wrap the thread-related logic in order to make the usage even simpler (I made a little research about this in an article about Android design.

How would I approach the development process?

I am a big fan of the Test Driven Development and, in general, the clean code. I would do the following things:

  • All the system will have tests to assure its correct behaviour (very important point of the development). Also, these tests will help to mantain the code and extend it.
  • Clearly documented code with Javadoc (this would generate a very good system documentation).
  • Document the project with practical examples (code) any feature of the wrapper.
  • I would try to get it working in Scala (a popular language which uses the Java Virtual Machine, Twitter uses it).

What happens If I finish my work early?

  • I would like to make a simple webpage to show/advertise the library (how to use it, documentation...).
  • I would like to develop a simple web application to show the wrapper working in a real environment.
  • I could extend the library and make it asynchronous in order to make the Android usage very easy (forget about thread control and all, just draw boxes and let me do the rest).

Outcomes of this project

This library could be used in:

  • Android applications
  • Java/Scala web applications
  • Java/Scala desktop applications
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment