Skip to content

Commit

Permalink
Various fixes based on integration testing. Updates to match the late…
Browse files Browse the repository at this point in the history
…st rest endpoints.
  • Loading branch information
RyanLCox1 committed Aug 4, 2022
1 parent 54d2884 commit 8a148f0
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 19 deletions.
24 changes: 12 additions & 12 deletions src/main/java/com/smartystreets/api/us_autocomplete_pro/Lookup.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
*/
public class Lookup {
final int PREFER_RATIO_DEFAULT = 100;
final int MAX_SUGGESTIONS_DEFAULT = 10;
final int MAX_RESULTS_DEFAULT = 10;

//region [ Fields ]

private Suggestion[] result;
private String search;
private int maxSuggestions;
private int maxResults;
private List<String> cityFilter;
private List<String> stateFilter;
private List<String> zipcodeFilter;
Expand All @@ -39,7 +39,7 @@ public class Lookup {
* If you use this constructor, don't forget to set the <b>prefix</b>. It is required.
*/
public Lookup() {
this.maxSuggestions = this.MAX_SUGGESTIONS_DEFAULT;
this.maxResults = this.MAX_RESULTS_DEFAULT;
this.preferGeolocation = GeolocateType.CITY;
this.cityFilter = new ArrayList<>();
this.stateFilter = new ArrayList<>();
Expand Down Expand Up @@ -117,14 +117,14 @@ public GeolocateType getGeolocateType() {
return preferGeolocation;
}

public int getMaxSuggestions() {
return maxSuggestions;
public int getMaxResults() {
return maxResults;
}

String getMaxSuggestionsStringIfSet() {
if (this.maxSuggestions == this.MAX_SUGGESTIONS_DEFAULT)
if (this.maxResults == this.MAX_RESULTS_DEFAULT)
return null;
return Integer.toString(this.maxSuggestions);
return Integer.toString(this.maxResults);
}

//endregion
Expand Down Expand Up @@ -178,14 +178,14 @@ public void setGeolocateType(GeolocateType geolocateType) {

/***
* Sets the maximum number of suggestions to return.
* @param maxSuggestions A positive integer range [1, 10]. Default is 10.
* @param maxResults A positive integer range [1, 10]. Default is 10.
* @throws IllegalArgumentException
*/
public void setMaxSuggestions(int maxSuggestions) throws IllegalArgumentException{
if (maxSuggestions > 0 && maxSuggestions <= this.MAX_SUGGESTIONS_DEFAULT) {
this.maxSuggestions = maxSuggestions;
public void setMaxResults(int maxResults) throws IllegalArgumentException{
if (maxResults > 0 && maxResults <= this.MAX_RESULTS_DEFAULT) {
this.maxResults = maxResults;
} else {
throw new IllegalArgumentException("Max suggestions must be a positive integer no larger than 10.");
throw new IllegalArgumentException("Max results must be a positive integer no larger than 10.");
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.smartystreets.api.us_reverse_geo;

import com.fasterxml.jackson.annotation.JsonProperty;

import java.io.Serializable;

public class Address implements Serializable {
Expand All @@ -16,8 +18,10 @@ public class Address implements Serializable {

public String getCity() { return this.city; }

@JsonProperty("state_abbreviation")
public String getStateAbbreviation() { return this.stateAbbreviation; }

@JsonProperty("zipcode")
public String getZipCode() { return this.zipCode; }

}
16 changes: 13 additions & 3 deletions src/main/java/com/smartystreets/api/us_reverse_geo/Coordinate.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,17 @@ public class Coordinate implements Serializable {
private double longitude;
private int license;
private String zipcode;
private String accuracy;

//endregion

public double getLatitude() { return this.latitude; }
public double getLatitude() {
return this.latitude;
}

public double getLongitude() { return this.longitude; }
public double getLongitude() {
return this.longitude;
}

public String getLicense() {
switch (this.license) {
Expand All @@ -26,6 +31,11 @@ public String getLicense() {
}
}

public String getZipCode() { return this.zipcode; }
public String getZipCode() {
return this.zipcode;
}

public String getAccuracy() {
return this.accuracy;
}
}
5 changes: 2 additions & 3 deletions src/main/java/examples/UsAutocompleteProExample.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package examples;

import com.smartystreets.api.SharedCredentials;
import com.smartystreets.api.StaticCredentials;
import com.smartystreets.api.exceptions.SmartyException;
import com.smartystreets.api.us_autocomplete_pro.*;
import com.smartystreets.api.ClientBuilder;
Expand All @@ -23,7 +22,8 @@ public static void main(String[] args) {
licenses.add("us-autocomplete-pro-cloud");
Client client = new ClientBuilder(credentials).withLicenses(licenses).buildUsAutocompleteProApiClient();
Lookup lookup = new Lookup("1042 W Center");

lookup.setMaxResults(5);

try {
client.send(lookup);

Expand All @@ -40,7 +40,6 @@ public static void main(String[] args) {
lookup.addPreferState("UT");
lookup.addPreferState("CO");
lookup.setSelected("1042 W Center St Apt A (24) Orem UT 84057");
lookup.setMaxSuggestions(5);
lookup.setPreferRatio(33);
lookup.setSource("all");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void testSendingSingleFullyPopulatedLookup() throws Exception {
String expectedURL = "http://localhost/?search=1&max_results=2&include_only_cities=3&include_only_states=4&prefer_ratio=60&prefer_geolocation=state";
Lookup lookup = new Lookup();
lookup.setSearch("1");
lookup.setMaxSuggestions(2);
lookup.setMaxResults(2);
lookup.addCityFilter("3");
lookup.addStateFilter("4");
lookup.setPreferRatio(60);
Expand Down

0 comments on commit 8a148f0

Please sign in to comment.