org.codeforamerica.open311.facade
Class APIWrapper

java.lang.Object
  extended by org.codeforamerica.open311.facade.APIWrapper
Direct Known Subclasses:
InvalidXMLWrapper

public class APIWrapper
extends Object

Base class of the API. This is the entry point to the system. You can build objects of this class using the APIWrapperFactory class.

Author:
Santiago MunĂ­n

Method Summary
 Cache getCache()
          Returns the cache used by the wrapper.
 String getEndpointUrl()
           
 ServiceDefinition getServiceDefinition(String serviceCode)
          Gets the service definition of a concrete service.
 List<Service> getServiceList()
          Gets a list of services from the endpoint.
 ServiceRequest getServiceRequest(String serviceRequestId)
          GET Service Request operation.
 ServiceRequestIdResponse getServiceRequestIdFromToken(String token)
          This function is useful when the POST Service Request returns a token.
 List<ServiceRequest> getServiceRequests(GETServiceRequestsFilter operationData)
          Retrieves all the service requests which accord to the given data.
 String getWrapperInfo()
          Returns a string with some info.
protected  String networkGet(URL url)
          Tries to perform an HTTP GET operation and returns the result.
protected  String networkPost(URL url, Map<String,String> parameters)
          Tries to perform an HTTP POST operation and returns the result.
 POSTServiceRequestResponse postServiceRequest(POSTServiceRequestData operationData)
          Performs a POST Service Request operation.
 void setFormat(Format format)
          Updates the format of the wrapper.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

getEndpointUrl

public String getEndpointUrl()

getWrapperInfo

public String getWrapperInfo()
Returns a string with some info.

Returns:
endpointUrl - type.

getCache

public Cache getCache()
Returns the cache used by the wrapper.

Returns:
Cache used by the wrapper, useful to delete it.

setFormat

public void setFormat(Format format)
Updates the format of the wrapper. A new URLBuilder will be instantiated.

Parameters:
format - New format.

getServiceList

public List<Service> getServiceList()
                             throws APIWrapperException
Gets a list of services from the endpoint. More info

Returns:
List of fetched services.
Throws:
APIWrapperException - If there was any problem (data parsing, I/O...).

getServiceDefinition

public ServiceDefinition getServiceDefinition(String serviceCode)
                                       throws APIWrapperException
Gets the service definition of a concrete service. More info

Parameters:
serviceCode - Code of the service of interest.
Returns:
All the information related to the given code.
Throws:
APIWrapperException - If there was any problem (data parsing, I/O...).

getServiceRequestIdFromToken

public ServiceRequestIdResponse getServiceRequestIdFromToken(String token)
                                                      throws APIWrapperException
This function is useful when the POST Service Request returns a token.

Parameters:
token - Given token.
Returns:
A service id useful to the operation GET Service Request.
Throws:
APIWrapperException - If there was any problem.

getServiceRequests

public List<ServiceRequest> getServiceRequests(GETServiceRequestsFilter operationData)
                                        throws APIWrapperException
Retrieves all the service requests which accord to the given data.

Parameters:
operationData - An object with all the desired optional filtering parameters to send.
Returns:
A list of service requests.
Throws:
APIWrapperException - If there was any problem.

getServiceRequest

public ServiceRequest getServiceRequest(String serviceRequestId)
                                 throws APIWrapperException
GET Service Request operation.

Parameters:
serviceRequestId - ID of the request to be fetched.
Returns:
The info related to the given ID.
Throws:
APIWrapperException - If there was any problem.

postServiceRequest

public POSTServiceRequestResponse postServiceRequest(POSTServiceRequestData operationData)
                                              throws APIWrapperException
Performs a POST Service Request operation.

Parameters:
operationData - An object with all the desired parameters and attributes to be sent.
Returns:
The server's response.
Throws:
APIWrapperException - If there was any problem.

networkGet

protected String networkGet(URL url)
                     throws APIWrapperException
Tries to perform an HTTP GET operation and returns the result.

Parameters:
url - Target.
Returns:
Server response.
Throws:
APIWrapperException - If there was any problem with the request.

networkPost

protected String networkPost(URL url,
                             Map<String,String> parameters)
                      throws APIWrapperException
Tries to perform an HTTP POST operation and returns the result.

Parameters:
url - Target.
parameters - Parameters of the request.
Returns:
Server response.
Throws:
APIWrapperException - If there was any problem with the request.

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2013 Code for America. All Rights Reserved.