Skip to content

Commit

Permalink
Added format field to lookup (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewjohnsonsmarty committed Oct 25, 2023
1 parent bf7aad4 commit 9f8a851
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/main/java/com/smartystreets/api/us_street/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ private void populateQueryString(Lookup address, Request request) {
request.putParameter("addressee", address.getAddressee());
request.putParameter("urbanization", address.getUrbanization());
request.putParameter("match", address.getMatch());
request.putParameter("format", address.getFormat());

if (address.getMaxCandidates() == 1 && address.getMatch() == "enhanced")
request.putParameter("candidates", "5");
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/com/smartystreets/api/us_street/Lookup.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class Lookup implements Serializable {
private String addressee;
private String urbanization;
private String match;
private String format;
private int candidates;

//endregion
Expand Down Expand Up @@ -132,6 +133,17 @@ public String getMatch() {
return null;
}

@JsonProperty("format")
public String getFormat(){
if (this.format == null)
return null;
if (this.format.equals("default"))
return "default";
if (this.format.equals("project-usa"))
return "project-usa";
return null;
}

@JsonProperty("candidates")
public int getMaxCandidates() {
return this.candidates;
Expand Down Expand Up @@ -202,6 +214,13 @@ public void setUrbanization(String urbanization) {
public void setMatch(MatchType match) {
this.match = match.getName();
}
/**
* Sets the format output for this lookup <br>
* @param format The format output
*/
public void setFormat(OutputFormat format) {
this.format = format.getName();
}

/**
* Sets the maximum number of valid addresses returned when the input is ambiguous.
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/com/smartystreets/api/us_street/OutputFormat.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.smartystreets.api.us_street;

public enum OutputFormat {
DEFAULT("default"), PROJECT_USA("project-usa");

private final String name;

OutputFormat(String name){
this.name = name;
}

public String getName(){
return name;
}
}
28 changes: 28 additions & 0 deletions src/test/java/com/smartystreets/api/us_street/ClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,34 @@ public void testSendingSingleFullyPopulatedLookup() throws Exception {

}

@Test
public void testSendingSingleFullyPopulatedLookupWithFormatOutput() throws Exception {
RequestCapturingSender capturingSender = new RequestCapturingSender();
URLPrefixSender sender = new URLPrefixSender("http://localhost/", capturingSender);
FakeSerializer serializer = new FakeSerializer(null);
Client client = new Client(sender, serializer);
Lookup lookup = new Lookup();
lookup.setInputId("1234");
lookup.setAddressee("0");
lookup.setStreet("1");
lookup.setSecondary("2");
lookup.setStreet2("3");
lookup.setUrbanization("4");
lookup.setCity("5");
lookup.setState("6");
lookup.setZipCode("7");
lookup.setLastline("8");
lookup.setMatch(MatchType.ENHANCED);
lookup.setFormat(OutputFormat.PROJECT_USA);

client.send(lookup);

assertEquals("http://localhost/?input_id=1234&street=1&street2=3" +
"&secondary=2&city=5&state=6&zipcode=7&lastline=8&addressee=0" +
"&urbanization=4&match=enhanced&format=project-usa&candidates=5", capturingSender.getRequest().getUrl());

}

//endregion

//region [ Batch Lookup ]
Expand Down

0 comments on commit 9f8a851

Please sign in to comment.