org.codeforamerica.open311.facade
Class APIWrapperFactory

java.lang.Object
  extended by org.codeforamerica.open311.facade.APIWrapperFactory

public class APIWrapperFactory
extends Object

Builds APIWrapper instances from different aspects specified by the user. To set the optional parameters, use the setter methods and, then, call build().

Author:
Santiago Munin

Constructor Summary
APIWrapperFactory(City city)
          Builds an instance from the desired city.
APIWrapperFactory(City city, EndpointType endpointType)
          Builds an instance from the desired city and endpoint type.
APIWrapperFactory(String endpointUrl)
          Builds an instance from the endpoint url.
APIWrapperFactory(String endpointUrl, Format format)
          Builds an instance from the endpoint url and the data interchange format.
APIWrapperFactory(String endpointUrl, String jurisdictionId)
          Builds an instance from the endpoint url and the jurisdiction_id.
APIWrapperFactory(String endpointUrl, String jurisdictionId, Format format)
          Builds an instance from the endpoint url and the jurisdiction_id.
 
Method Summary
 APIWrapper build()
          Builds an APIWrapper.
 APIWrapperFactory setApiKey(String apiKey)
          Sets the api key.
 APIWrapperFactory setCache(Cache cache)
          Sets a desired cache system.
 APIWrapperFactory setFormat(Format format)
          Selects the desired data exchange format.
 APIWrapperFactory setNetworkManager(NetworkManager networkManager)
          Sets a custom NetworkManager, useful if you need to use mocks or a platform-dependent network client which you can build implementing the NetworkManager interface.
 String toString()
           
 APIWrapperFactory withLogs()
          The built instance will be logged.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

APIWrapperFactory

public APIWrapperFactory(String endpointUrl)
Builds an instance from the endpoint url.

Parameters:
endpointUrl - Url of the endpoint.

APIWrapperFactory

public APIWrapperFactory(String endpointUrl,
                         String jurisdictionId)
Builds an instance from the endpoint url and the jurisdiction_id.

Parameters:
endpointUrl - Url of the endpoint.
jurisdictionId - Desired jurisdiction_id (can be null).

APIWrapperFactory

public APIWrapperFactory(String endpointUrl,
                         Format format)
Builds an instance from the endpoint url and the data interchange format.

Parameters:
endpointUrl - Url of the endpoint.
format - Data format. It is your responsibility to check if the given format is allowed.

APIWrapperFactory

public APIWrapperFactory(String endpointUrl,
                         String jurisdictionId,
                         Format format)
Builds an instance from the endpoint url and the jurisdiction_id.

Parameters:
endpointUrl - Url of the endpoint.
jurisdictionId - Desired jurisdiction_id (can be null).
format - Data format. It is your responsibility to check if the given format is allowed.

APIWrapperFactory

public APIWrapperFactory(City city)
Builds an instance from the desired city. The type of the endpoint will be EndpointType.PRODUCTION) and the format will be Format.XML.

Parameters:
city - Desired city.

APIWrapperFactory

public APIWrapperFactory(City city,
                         EndpointType endpointType)
Builds an instance from the desired city and endpoint type. The format will be Format.XML.

Parameters:
city - Desired city.
endpointType - Desired endpoint type.
Method Detail

setFormat

public APIWrapperFactory setFormat(Format format)
Selects the desired data exchange format.

Parameters:
format - Desired format.
Returns:
The same instance with the new selected format.

setApiKey

public APIWrapperFactory setApiKey(String apiKey)
Sets the api key. "" by default.

Parameters:
apiKey - Api key for the endpoint.
Returns:
The same instance with the new specified api key.

setNetworkManager

public APIWrapperFactory setNetworkManager(NetworkManager networkManager)
Sets a custom NetworkManager, useful if you need to use mocks or a platform-dependent network client which you can build implementing the NetworkManager interface.

Parameters:
networkManager - A implementation of the NetworkManager interface.
Returns:
The same instance with the new specified NetworkManager.

setCache

public APIWrapperFactory setCache(Cache cache)
Sets a desired cache system.

Parameters:
cache - Implementation of the Cache interface.
Returns:
The same instance with the new specified Cache.

withLogs

public APIWrapperFactory withLogs()
The built instance will be logged.

Returns:
The same instance.

build

public APIWrapper build()
                 throws APIWrapperException
Builds an APIWrapper. WARNING: This operation could require some time to be done (it could involve network operations).

Returns:
An instance built from the given parameters to this object.
Throws:
APIWrapperException - If there was any problem.

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2013 Code for America. All Rights Reserved.