Skip to content

Commit

Permalink
Added Input ID to result
Browse files Browse the repository at this point in the history
  • Loading branch information
DuncanBeutler committed Sep 25, 2019
1 parent 1af528f commit 19eb19a
Show file tree
Hide file tree
Showing 15 changed files with 33 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public Candidate[] send(Lookup lookup) throws IOException, SmartyException {
private Request buildRequest(Lookup lookup) {
Request request = new Request();

request.putParameter("input_id", lookup.getInputId());
request.putParameter("country", lookup.getCountry());
request.putParameter("geocode", lookup.getGeocode());
if (lookup.getLanguage() != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ public class RootLevel {

//region [ Fields ]

@Key("input_id")
private String inputId;

@Key("organization")
private String organization;

Expand Down Expand Up @@ -50,6 +53,8 @@ public class RootLevel {

//region [ Getters ]

public String getInputId() { return inputId; }

public String getOrganization() {
return organization;
}
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/smartystreets/api/us_street/Candidate.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
public class Candidate {
//region [ Fields ]

@Key("input_id")
private String inputId;

@Key("input_index")
private int inputIndex;

Expand Down Expand Up @@ -68,6 +71,8 @@ public Analysis getAnalysis() {
return this.analysis;
}

public String getInputId() { return this.inputId; }

public int getInputIndex() {
return this.inputIndex;
}
Expand Down
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 @@ -54,6 +54,7 @@ public void send(Batch batch) throws SmartyException, IOException {
}

private void populateQueryString(Lookup address, Request request) {
request.putParameter("input_id", address.getInputId());
request.putParameter("street", address.getStreet());
request.putParameter("street2", address.getStreet2());
request.putParameter("secondary", address.getSecondary());
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/smartystreets/api/us_zipcode/Result.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ public class Result {
@Key("reason")
String reason;

@Key("input_id")
private String inputId;

@Key("input_index")
private int inputIndex;

Expand Down Expand Up @@ -46,6 +49,8 @@ public ZipCode getZipCode(int index) {
*
* @return Returns a status if there was no match
*/
public String getInputId() { return this.inputId; }

public String getStatus() {
return this.status;
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/examples/InternationalExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public static void main(String[] args) throws IOException, SmartyException {
Candidate[] candidates = client.send(lookup); // The candidates are also stored in the lookup's 'result' field.

Candidate firstCandidate = candidates[0];
System.out.println("Input ID: " + firstCandidate.getInputId());
System.out.println("Address is " + firstCandidate.getAnalysis().getVerificationStatus());
System.out.println("Address precision: " + firstCandidate.getAnalysis().getAddressPrecision() + "\n");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public static void main(String[] args) {
final Metadata metadata = candidate.getMetadata();

System.out.println("\nCandidate " + candidate.getCandidateIndex() + ":");
System.out.println("Input ID: " + candidate.getInputId());
System.out.println("Delivery line 1: " + candidate.getDeliveryLine1());
System.out.println("Last line: " + candidate.getLastLine());
System.out.println("ZIP Code: " + components.getZipCode() + "-" + components.getPlus4Code());
Expand Down
1 change: 1 addition & 0 deletions src/main/java/examples/UsStreetSingleAddressExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public static void main(String[] args) {
Candidate firstCandidate = results.get(0);

System.out.println("Address is valid. (There is at least one candidate)\n");
System.out.println("Input ID: " + firstCandidate.getInputId());
System.out.println("ZIP Code: " + firstCandidate.getComponents().getZipCode());
System.out.println("County: " + firstCandidate.getMetadata().getCountyName());
System.out.println("Latitude: " + firstCandidate.getMetadata().getLatitude());
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/examples/UsZipCodeMultipleLookupsExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ public static void main(String[] args) {
continue;
}

System.out.println("Input ID: " + result.getInputId());

City[] cities = result.getCities();
System.out.println(cities.length + " City and State match(es):");

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/examples/UsZipCodeSingleLookupExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public static void main(String[] args) {
ZipCode[] zipCodes = result.getZipCodes();
City[] cities = result.getCities();

System.out.println("Input ID: " + result.getInputId());

for (City city : cities) {
System.out.println("\nCity: " + city.getCity());
System.out.println("State: " + city.getState());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class CandidateTest {

@Test
public void testAllFieldsFilledCorrectly() throws IOException {
String responsePayload = "[{\"organization\":\"1\",\"address1\":\"2\",\"address2\":\"3\"," +
String responsePayload = "[{\"input_id\":\"1234\",\"organization\":\"1\",\"address1\":\"2\",\"address2\":\"3\"," +
"\"address3\":\"4\",\"address4\":\"5\",\"address5\":\"6\",\"address6\":\"7\",\"address7\":\"8\"," +
"\"address8\":\"9\",\"address9\":\"10\",\"address10\":\"11\",\"address11\":\"12\",\"address12\":\"13\"," +
"\"components\":{\"country_iso_3\":\"14\",\"super_administrative_area\":\"15\"," +
Expand Down Expand Up @@ -52,6 +52,7 @@ public void testAllFieldsFilledCorrectly() throws IOException {
Candidate candidate = googleSerializer.deserialize(responsePayload.getBytes(), Candidate[].class)[0];

//region [ Candidate ]
assertEquals("1234", candidate.getInputId());
assertEquals("1", candidate.getOrganization());
assertEquals("2", candidate.getAddress1());
assertEquals("3", candidate.getAddress2());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@ public void testSendingFreeformLookup() throws Exception {
public void testSendingSingleFullyPopulatedLookup() throws Exception {
RequestCapturingSender capturingSender = new RequestCapturingSender();
URLPrefixSender sender = new URLPrefixSender("http://localhost/", capturingSender);
String expectedUrl = "http://localhost/?country=0&geocode=true&language=native&freeform=1" +
String expectedUrl = "http://localhost/?input_id=1234&country=0&geocode=true&language=native&freeform=1" +
"&address1=2&address2=3&address3=4&address4=5&organization=6&locality=7&administrative_area=8&postal_code=9";
FakeSerializer serializer = new FakeSerializer(null);
Client client = new Client(sender, serializer);
Lookup lookup = new Lookup();
lookup.setInputId("1234");
lookup.setCountry("0");
lookup.setGeocode(true);
lookup.setLanguage(LanguageMode.NATIVE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ public void testFullJSONDeserialization() throws Exception {

assertEquals(0, candidates[0].getInputIndex());
assertEquals(4242, candidates[0].getCandidateIndex());
assertEquals("blah", candidates[0].getInputId());
assertEquals("John Smith", candidates[0].getAddressee());
assertEquals("3214 N University Ave # 409", candidates[0].getDeliveryLine1());
assertEquals("blah blah", candidates[0].getDeliveryLine2());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public void testSendingSingleFullyPopulatedLookup() throws Exception {
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");
Expand All @@ -56,7 +57,7 @@ public void testSendingSingleFullyPopulatedLookup() throws Exception {

client.send(lookup);

assertEquals("http://localhost/?street=1&street2=3" +
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=invalid&candidates=9", capturingSender.getRequest().getUrl());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,14 @@ public void testSendingSingleFullyPopulatedLookup() throws Exception {
FakeSerializer serializer = new FakeSerializer(null);
Client client = new Client(sender, serializer);
Lookup lookup = new Lookup();
lookup.setInputId("1234");
lookup.setCity("1");
lookup.setState("2");
lookup.setZipCode("3");

client.send(lookup);

assertEquals("http://localhost/?city=1&state=2&zipcode=3", capturingSender.getRequest().getUrl());
assertEquals("http://localhost/?input_id=1234&city=1&state=2&zipcode=3", capturingSender.getRequest().getUrl());
}

//endregion
Expand Down

0 comments on commit 19eb19a

Please sign in to comment.