Skip to content

Commit 9f8a851

Browse files
Added format field to lookup (#42)
1 parent bf7aad4 commit 9f8a851

File tree

4 files changed

+63
-0
lines changed

4 files changed

+63
-0
lines changed

src/main/java/com/smartystreets/api/us_street/Client.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ private void populateQueryString(Lookup address, Request request) {
6666
request.putParameter("addressee", address.getAddressee());
6767
request.putParameter("urbanization", address.getUrbanization());
6868
request.putParameter("match", address.getMatch());
69+
request.putParameter("format", address.getFormat());
6970

7071
if (address.getMaxCandidates() == 1 && address.getMatch() == "enhanced")
7172
request.putParameter("candidates", "5");

src/main/java/com/smartystreets/api/us_street/Lookup.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public class Lookup implements Serializable {
2626
private String addressee;
2727
private String urbanization;
2828
private String match;
29+
private String format;
2930
private int candidates;
3031

3132
//endregion
@@ -132,6 +133,17 @@ public String getMatch() {
132133
return null;
133134
}
134135

136+
@JsonProperty("format")
137+
public String getFormat(){
138+
if (this.format == null)
139+
return null;
140+
if (this.format.equals("default"))
141+
return "default";
142+
if (this.format.equals("project-usa"))
143+
return "project-usa";
144+
return null;
145+
}
146+
135147
@JsonProperty("candidates")
136148
public int getMaxCandidates() {
137149
return this.candidates;
@@ -202,6 +214,13 @@ public void setUrbanization(String urbanization) {
202214
public void setMatch(MatchType match) {
203215
this.match = match.getName();
204216
}
217+
/**
218+
* Sets the format output for this lookup <br>
219+
* @param format The format output
220+
*/
221+
public void setFormat(OutputFormat format) {
222+
this.format = format.getName();
223+
}
205224

206225
/**
207226
* Sets the maximum number of valid addresses returned when the input is ambiguous.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.smartystreets.api.us_street;
2+
3+
public enum OutputFormat {
4+
DEFAULT("default"), PROJECT_USA("project-usa");
5+
6+
private final String name;
7+
8+
OutputFormat(String name){
9+
this.name = name;
10+
}
11+
12+
public String getName(){
13+
return name;
14+
}
15+
}

src/test/java/com/smartystreets/api/us_street/ClientTest.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,34 @@ public void testSendingSingleFullyPopulatedLookup() throws Exception {
5555

5656
}
5757

58+
@Test
59+
public void testSendingSingleFullyPopulatedLookupWithFormatOutput() throws Exception {
60+
RequestCapturingSender capturingSender = new RequestCapturingSender();
61+
URLPrefixSender sender = new URLPrefixSender("http://localhost/", capturingSender);
62+
FakeSerializer serializer = new FakeSerializer(null);
63+
Client client = new Client(sender, serializer);
64+
Lookup lookup = new Lookup();
65+
lookup.setInputId("1234");
66+
lookup.setAddressee("0");
67+
lookup.setStreet("1");
68+
lookup.setSecondary("2");
69+
lookup.setStreet2("3");
70+
lookup.setUrbanization("4");
71+
lookup.setCity("5");
72+
lookup.setState("6");
73+
lookup.setZipCode("7");
74+
lookup.setLastline("8");
75+
lookup.setMatch(MatchType.ENHANCED);
76+
lookup.setFormat(OutputFormat.PROJECT_USA);
77+
78+
client.send(lookup);
79+
80+
assertEquals("http://localhost/?input_id=1234&street=1&street2=3" +
81+
"&secondary=2&city=5&state=6&zipcode=7&lastline=8&addressee=0" +
82+
"&urbanization=4&match=enhanced&format=project-usa&candidates=5", capturingSender.getRequest().getUrl());
83+
84+
}
85+
5886
//endregion
5987

6088
//region [ Batch Lookup ]

0 commit comments

Comments
 (0)