Search in sources :

Example 1 with Lookup

use of com.smartystreets.api.us_street.Lookup in project API by ca-cwds.

the class SmartyStreet method getSmartyStreetsCandidates.

/**
   * @param street incoming street address
   * @param city incoming city name
   * @param state incoming state
   * @param zipCode incoming zip code
   * @return returns a address back
   */
public List<Candidate> getSmartyStreetsCandidates(String street, String city, String state, Integer zipCode) {
    Client client = new ClientBuilder(smartyStreetsDao.getClientId(), smartyStreetsDao.getToken()).build();
    Lookup lookup = createSmartyStreetsLookup(street, city, state, zipCode);
    try {
        client.send(lookup);
    } catch (SmartyException e) {
        LOGGER.error("SmartyStreet error, Unable to validate the address", e);
        throw new ApiException("ERROR calling SmartyStreet - ", e);
    } catch (IOException e) {
        LOGGER.error("SmartyStreet IO error, Unable to validate the address", e);
        throw new ApiException("ERROR calling SmartyStreet - ", e);
    }
    return lookup.getResult();
}
Also used : SmartyException(com.smartystreets.api.exceptions.SmartyException) Lookup(com.smartystreets.api.us_street.Lookup) IOException(java.io.IOException) Client(com.smartystreets.api.us_street.Client) ClientBuilder(com.smartystreets.api.us_street.ClientBuilder) ApiException(gov.ca.cwds.rest.api.ApiException)

Example 2 with Lookup

use of com.smartystreets.api.us_street.Lookup in project API by ca-cwds.

the class SmartyStreet method createSmartyStreetsLookup.

/**
   * @param street incoming street address
   * @param city incoming city name
   * @param state incoming state
   * @param zipCode incoming zip code
   * @return returns lookup
   */
public Lookup createSmartyStreetsLookup(String street, String city, String state, Integer zipCode) {
    Lookup lookup = new Lookup();
    lookup.setStreet(street);
    lookup.setCity(city);
    lookup.setState(state);
    if (zipCode > 0) {
        lookup.setZipCode(Integer.toString(zipCode));
    } else {
        lookup.setZipCode("");
    }
    lookup.setMaxCandidates(smartyStreetsDao.getMaxCandidates());
    return lookup;
}
Also used : Lookup(com.smartystreets.api.us_street.Lookup)

Aggregations

Lookup (com.smartystreets.api.us_street.Lookup)2 SmartyException (com.smartystreets.api.exceptions.SmartyException)1 Client (com.smartystreets.api.us_street.Client)1 ClientBuilder (com.smartystreets.api.us_street.ClientBuilder)1 ApiException (gov.ca.cwds.rest.api.ApiException)1 IOException (java.io.IOException)1