diff --git a/src/main/java/com/smartystreets/api/us_enrichment/Client.java b/src/main/java/com/smartystreets/api/us_enrichment/Client.java index dc857c8..05101bd 100644 --- a/src/main/java/com/smartystreets/api/us_enrichment/Client.java +++ b/src/main/java/com/smartystreets/api/us_enrichment/Client.java @@ -8,8 +8,12 @@ import com.smartystreets.api.us_enrichment.lookup_types.Lookup; import com.smartystreets.api.us_enrichment.lookup_types.property_financial.PropertyFinancialLookup; import com.smartystreets.api.us_enrichment.lookup_types.property_principal.PropertyPrincipalLookup; +import com.smartystreets.api.us_enrichment.lookup_types.secondary.SecondaryCountLookup; +import com.smartystreets.api.us_enrichment.lookup_types.secondary.SecondaryLookup; import com.smartystreets.api.us_enrichment.result_types.property_financial.FinancialResponse; import com.smartystreets.api.us_enrichment.result_types.property_principal.PrincipalResponse; +import com.smartystreets.api.us_enrichment.result_types.secondary.SecondaryCountResponse; +import com.smartystreets.api.us_enrichment.result_types.secondary.SecondaryResponse; import java.io.IOException; @@ -34,6 +38,18 @@ public PrincipalResponse[] sendPropertyPrincipalLookup(String smartyKey) throws return lookup.getResults(); } + public SecondaryResponse[] sendSecondaryLookup(String smartKey) throws SmartyException, IOException, InterruptedException { + SecondaryLookup lookup = new SecondaryLookup(smartKey); + send(lookup); + return lookup.getResults(); + } + + public SecondaryCountResponse[] sendSecondaryCountLookup(String smartKey) throws SmartyException, IOException, InterruptedException { + SecondaryCountLookup lookup = new SecondaryCountLookup(smartKey); + send(lookup); + return lookup.getResults(); + } + private void send(Lookup lookup) throws IOException, SmartyException, InterruptedException { if (lookup == null || lookup.getSmartyKey() == null || lookup.getSmartyKey().isEmpty()) throw new SmartyException("Client.send() requires a Lookup with the 'smartyKey' field set"); diff --git a/src/main/java/com/smartystreets/api/us_enrichment/lookup_types/secondary/SecondaryCountLookup.java b/src/main/java/com/smartystreets/api/us_enrichment/lookup_types/secondary/SecondaryCountLookup.java new file mode 100644 index 0000000..af2a0c3 --- /dev/null +++ b/src/main/java/com/smartystreets/api/us_enrichment/lookup_types/secondary/SecondaryCountLookup.java @@ -0,0 +1,29 @@ +package com.smartystreets.api.us_enrichment.lookup_types.secondary; + +import com.smartystreets.api.Serializer; +import com.smartystreets.api.us_enrichment.lookup_types.Lookup; +import com.smartystreets.api.us_enrichment.result_types.secondary.SecondaryCountResponse; + +import java.io.IOException; + +public class SecondaryCountLookup extends Lookup { + + private SecondaryCountResponse[] results; + + public SecondaryCountLookup(String smartyKey) { + super(smartyKey, "secondary", "count"); + } + + public SecondaryCountResponse[] getResults() { + return results; + } + + public void setResults(SecondaryCountResponse[] results) { + this.results = results; + } + + @Override + public void deserializeAndSetResults(Serializer serializer, byte[] payload) throws IOException { + this.results = serializer.deserialize(payload, SecondaryCountResponse[].class); + } +} diff --git a/src/main/java/com/smartystreets/api/us_enrichment/lookup_types/secondary/SecondaryLookup.java b/src/main/java/com/smartystreets/api/us_enrichment/lookup_types/secondary/SecondaryLookup.java new file mode 100644 index 0000000..6182c62 --- /dev/null +++ b/src/main/java/com/smartystreets/api/us_enrichment/lookup_types/secondary/SecondaryLookup.java @@ -0,0 +1,29 @@ +package com.smartystreets.api.us_enrichment.lookup_types.secondary; + +import com.smartystreets.api.Serializer; +import com.smartystreets.api.us_enrichment.lookup_types.Lookup; +import com.smartystreets.api.us_enrichment.result_types.secondary.SecondaryResponse; + +import java.io.IOException; + +public class SecondaryLookup extends Lookup { + + private SecondaryResponse[] results; + + public SecondaryLookup(String smartyKey) { + super(smartyKey, "secondary", ""); + } + + public SecondaryResponse[] getResults() { + return results; + } + + public void setResults(SecondaryResponse[] results) { + this.results = results; + } + + @Override + public void deserializeAndSetResults(Serializer serializer, byte[] payload) throws IOException { + this.results = serializer.deserialize(payload, SecondaryResponse[].class); + } +} diff --git a/src/main/java/com/smartystreets/api/us_enrichment/result_types/secondary/Alias.java b/src/main/java/com/smartystreets/api/us_enrichment/result_types/secondary/Alias.java new file mode 100644 index 0000000..f932b7b --- /dev/null +++ b/src/main/java/com/smartystreets/api/us_enrichment/result_types/secondary/Alias.java @@ -0,0 +1,92 @@ +package com.smartystreets.api.us_enrichment.result_types.secondary; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class Alias { + + private String smartyKey; + + private String primaryNumber; + + private String streetPredirection; + + private String streetName; + + private String streetSuffix; + + private String streetPostdirection; + + private String cityName; + + private String stateAbbreviation; + + private String zipcode; + + private String plus4Code; + + @JsonProperty("smarty_key") + public String getSmartyKey() { + return smartyKey; + } + + @JsonProperty("primary_number") + public String getPrimaryNumber() { + return primaryNumber; + } + + @JsonProperty("street_predirection") + public String getStreetPredirection() { + return streetPredirection; + } + + @JsonProperty("street_name") + public String getStreetName() { + return streetName; + } + + @JsonProperty("street_suffix") + public String getStreetSuffix() { + return streetSuffix; + } + + @JsonProperty("street_postdirection") + public String getStreetPostdirection() { + return streetPostdirection; + } + + @JsonProperty("city_name") + public String getCityName() { + return cityName; + } + + @JsonProperty("state_abbreviation") + public String getStateAbbreviation() { + return stateAbbreviation; + } + + @JsonProperty("zipcode") + public String getZipcode() { + return zipcode; + } + + @JsonProperty("plus4_code") + public String getPlus4Code() { + return plus4Code; + } + + @Override + public String toString() { + return "Alias{" + + "smarty_key='" + getSmartyKey() + '\'' + + ", primary_number='" + getPrimaryNumber() + '\'' + + ", street_predirection='" + getStreetPredirection() + '\'' + + ", street_name='" + getStreetName() + '\'' + + ", street_suffix='" + getStreetSuffix() + '\'' + + ", street_postdirection='" + getStreetPostdirection() + '\'' + + ", city_name='" + getCityName() + '\'' + + ", state_abbreviation='" + getStateAbbreviation() + '\'' + + ", zipcode='" + getZipcode() + '\'' + + ", plus4_code='" + getPlus4Code() + '\'' + + '}'; + } +} diff --git a/src/main/java/com/smartystreets/api/us_enrichment/result_types/secondary/RootAddress.java b/src/main/java/com/smartystreets/api/us_enrichment/result_types/secondary/RootAddress.java new file mode 100644 index 0000000..5e94712 --- /dev/null +++ b/src/main/java/com/smartystreets/api/us_enrichment/result_types/secondary/RootAddress.java @@ -0,0 +1,101 @@ +package com.smartystreets.api.us_enrichment.result_types.secondary; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class RootAddress { + + private int secondaryCount; + + private String smartyKey; + + private String primaryNumber; + + private String streetPredirection; + + private String streetName; + + private String streetSuffix; + + private String streetPostdirection; + + private String cityName; + + private String stateAbbreviation; + + private String zipcode; + + private String plus4Code; + + @JsonProperty("secondary_count") + public int getSecondaryCount() { + return secondaryCount; + } + + @JsonProperty("smarty_key") + public String getSmartyKey() { + return smartyKey; + } + + @JsonProperty("primary_number") + public String getPrimaryNumber() { + return primaryNumber; + } + + @JsonProperty("street_predirection") + public String getStreetPredirection() { + return streetPredirection; + } + + @JsonProperty("street_name") + public String getStreetName() { + return streetName; + } + + @JsonProperty("street_suffix") + public String getStreetSuffix() { + return streetSuffix; + } + + @JsonProperty("street_postdirection") + public String getStreetPostdirection() { + return streetPostdirection; + } + + @JsonProperty("city_name") + public String getCityName() { + return cityName; + } + + @JsonProperty("state_abbreviation") + public String getStateAbbreviation() { + return stateAbbreviation; + } + + @JsonProperty("zipcode") + public String getZipcode() { + return zipcode; + } + + @JsonProperty("plus4_code") + public String getPlus4Code() { + return plus4Code; + } + + @Override + public String toString() { + return "RootAddress{" + + "secondary_count=" + getSecondaryCount() + + ", smarty_key='" + getSmartyKey() + '\'' + + ", primary_number='" + getPrimaryNumber() + '\'' + + ", street_predirection='" + getStreetPredirection() + '\'' + + ", street_name='" + getStreetName() + '\'' + + ", street_suffix='" + getStreetSuffix() + '\'' + + ", street_postdirection='" + getStreetPostdirection() + '\'' + + ", city_name='" + getCityName() + '\'' + + ", state_abbreviation='" + getStateAbbreviation() + '\'' + + ", zipcode='" + getZipcode() + '\'' + + ", plus4_code='" + getPlus4Code() + '\'' + + '}'; + } +} + diff --git a/src/main/java/com/smartystreets/api/us_enrichment/result_types/secondary/Secondary.java b/src/main/java/com/smartystreets/api/us_enrichment/result_types/secondary/Secondary.java new file mode 100644 index 0000000..2983bfd --- /dev/null +++ b/src/main/java/com/smartystreets/api/us_enrichment/result_types/secondary/Secondary.java @@ -0,0 +1,44 @@ +package com.smartystreets.api.us_enrichment.result_types.secondary; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class Secondary { + + private String smartyKey; + + private String secondaryDesignator; + + private String secondaryNumber; + + private String plus4Code; + + @JsonProperty("smarty_key") + public String getSmartyKey() { + return smartyKey; + } + + @JsonProperty("secondary_designator") + public String getSecondaryDesignator() { + return secondaryDesignator; + } + + @JsonProperty("secondary_number") + public String getSecondaryNumber() { + return secondaryNumber; + } + + @JsonProperty("plus4_code") + public String getPlus4Code() { + return plus4Code; + } + + @Override + public String toString() { + return "Secondary{" + + "smarty_key='" + getSmartyKey() + '\'' + + ", secondary_designator='" + getSecondaryDesignator() + '\'' + + ", secondary_number='" + getSecondaryNumber() + '\'' + + ", plus4_code='" + getPlus4Code() + '\'' + + '}'; + } +} diff --git a/src/main/java/com/smartystreets/api/us_enrichment/result_types/secondary/SecondaryCountResponse.java b/src/main/java/com/smartystreets/api/us_enrichment/result_types/secondary/SecondaryCountResponse.java new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/src/main/java/com/smartystreets/api/us_enrichment/result_types/secondary/SecondaryCountResponse.java @@ -0,0 +1,28 @@ +package com.smartystreets.api.us_enrichment.result_types.secondary; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class SecondaryCountResponse { + + private String smartyKey; + + private int count; + + @JsonProperty("smarty_key") + public String getSmartyKey() { + return smartyKey; + } + + @JsonProperty("count") + public int getCount() { + return count; + } + + @Override + public String toString() { + return "SecondaryCountResponse{" + + "smartyKey='" + smartyKey + '\'' + + ", count=" + count + + '}'; + } +} diff --git a/src/main/java/com/smartystreets/api/us_enrichment/result_types/secondary/SecondaryResponse.java b/src/main/java/com/smartystreets/api/us_enrichment/result_types/secondary/SecondaryResponse.java new file mode 100644 index 0000000..a491039 --- /dev/null +++ b/src/main/java/com/smartystreets/api/us_enrichment/result_types/secondary/SecondaryResponse.java @@ -0,0 +1,47 @@ +package com.smartystreets.api.us_enrichment.result_types.secondary; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.util.ArrayList; + +public class SecondaryResponse { + + private String smartyKey; + + private RootAddress rootAddress; + + private ArrayList aliases; + + private ArrayList secondaries; + + @JsonProperty("smarty_key") + public String getSmartyKey() { + return smartyKey; + } + + @JsonProperty("root_address") + public RootAddress getRootAddress() { + return rootAddress; + } + + @JsonProperty("aliases") + public ArrayList getAliases() { + return aliases; + } + + @JsonProperty("secondaries") + public ArrayList getSecondaries() { + return secondaries; + } + + + @Override + public String toString() { + return "SecondaryResponse{" + + "smartyKey='" + getSmartyKey() + '\'' + + ", rootAddress=" + getRootAddress() + + ", aliases=" + getAliases() + + ", secondaries=" + getSecondaries() + + '}'; + } +} diff --git a/src/main/java/examples/UsEnrichmentExample.java b/src/main/java/examples/UsEnrichmentExample.java index 54d49b3..92094c2 100644 --- a/src/main/java/examples/UsEnrichmentExample.java +++ b/src/main/java/examples/UsEnrichmentExample.java @@ -7,9 +7,14 @@ import com.smartystreets.api.us_enrichment.result_types.Result; import com.smartystreets.api.us_enrichment.result_types.property_financial.FinancialResponse; import com.smartystreets.api.us_enrichment.result_types.property_principal.PrincipalResponse; +import com.smartystreets.api.us_enrichment.result_types.secondary.Secondary; +import com.smartystreets.api.us_enrichment.result_types.secondary.SecondaryCountResponse; +import com.smartystreets.api.us_enrichment.result_types.secondary.SecondaryResponse; import java.io.IOException; +import java.util.ArrayList; import java.util.Arrays; +import java.util.stream.Collectors; public class UsEnrichmentExample { public static void main(String[] args) { @@ -51,5 +56,33 @@ public static void main(String[] args) { } else { System.out.println("Result was null"); } + + SecondaryCountResponse[] secondaryCountResults = null; + try { + secondaryCountResults = client.sendSecondaryCountLookup("2001117307"); + } catch (SmartyException | IOException | InterruptedException ex) { + System.out.println(ex.getMessage()); + ex.printStackTrace(); + } + + if (secondaryCountResults != null){ + System.out.println(Arrays.toString(secondaryCountResults)); + } else { + System.out.println("Result was null"); + } + + SecondaryResponse[] secondaryResults = null; + try { + secondaryResults = client.sendSecondaryLookup("2001117307"); + } catch (SmartyException | IOException | InterruptedException ex) { + System.out.println(ex.getMessage()); + ex.printStackTrace(); + } + + if (secondaryResults != null){ + System.out.println(Arrays.stream(secondaryResults).flatMap(s -> s.getSecondaries().stream() ).map(Secondary::toString).collect(Collectors.joining("\n"))); + } else { + System.out.println("Result was null"); + } } } diff --git a/src/test/java/com/smartystreets/api/us_enrichment/ResponseTest.java b/src/test/java/com/smartystreets/api/us_enrichment/ResponseTest.java index 7b1285e..6b02043 100644 --- a/src/test/java/com/smartystreets/api/us_enrichment/ResponseTest.java +++ b/src/test/java/com/smartystreets/api/us_enrichment/ResponseTest.java @@ -6,9 +6,11 @@ import com.smartystreets.api.us_enrichment.result_types.property_financial.FinancialResponse; import com.smartystreets.api.us_enrichment.result_types.property_principal.PrincipalAttributes; import com.smartystreets.api.us_enrichment.result_types.property_principal.PrincipalResponse; +import com.smartystreets.api.us_enrichment.result_types.secondary.*; import org.junit.Test; import java.io.IOException; +import java.util.ArrayList; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -18,10 +20,12 @@ public class ResponseTest { private final SmartySerializer smartySerializer = new SmartySerializer(); private static final String validFinancialResponse = "[{\"smarty_key\":\"123\",\"data_set_name\":\"property\",\"data_subset_name\":\"financial\",\"attributes\":{\"assessed_improvement_percent\":\"Assessed_Improvement_Percent\",\"veteran_tax_exemption\":\"Veteran_Tax_Exemption\",\"widow_tax_exemption\":\"Widow_Tax_Exemption\",\"financial_history\":[{\"code_title_company\":\"Code_Title_Company\"}]}}]"; private static final String validPrincipalResponse = "[{\"smarty_key\":\"123\",\"data_set_name\":\"property\",\"data_subset_name\":\"principal\",\"attributes\":{\"1st_floor_sqft\":\"1st_Floor_Sqft\",\"lender_name_2\":\"Lender_Name_2\",\"lender_seller_carry_back\":\"Lender_Seller_Carry_Back\",\"year_built\":\"Year_Built\",\"zoning\":\"Zoning\"}}]"; + private static final String validSecondaryResponse = "[{\"smarty_key\":\"123\",\"root_address\":{\"secondary_count\":1,\"smarty_key\":\"root_smartykey\",\"primary_number\":\"root_primary\",\"street_predirection\":\"root_predirection\",\"street_name\":\"root_streetname\",\"street_suffix\":\"root_street_suffix\",\"street_postdirection\":\"root_postdirection\",\"city_name\":\"root_city\",\"state_abbreviation\":\"root_state\",\"zipcode\":\"root_zipcode\",\"plus4_code\":\"root_plus4\"},\"aliases\":[{\"smarty_key\":\"alias_smartykey\",\"primary_number\":\"alias_primary\",\"street_predirection\":\"alias_predirectional\",\"street_name\":\"alias_streetname\",\"street_suffix\":\"alias_streetsuffix\",\"street_postdirection\":\"alias_postdirection\",\"city_name\":\"alias_city\",\"state_abbreviation\":\"alias_state\",\"zipcode\":\"alias_zipcode\",\"plus4_code\":\"alias_plus4\"}],\"secondaries\":[{\"smarty_key\":\"secondary_smartykey\",\"secondary_designator\":\"secondary_designator\",\"secondary_number\":\"secondary_number\",\"plus4_code\":\"secondary_plus4\"}]}]"; + private static final String validSecondaryCountResponse = "[{\"smarty_key\":\"123\",\"count\":10}]"; @Test - public void testPrincipalFieldsGetFillledInCorrectly() throws IOException { + public void testPrincipalFieldValues() throws IOException { PrincipalResponse[] results = smartySerializer.deserialize(validPrincipalResponse.getBytes(), PrincipalResponse[].class); PrincipalResponse result = results[0]; @@ -38,7 +42,7 @@ public void testPrincipalFieldsGetFillledInCorrectly() throws IOException { } @Test - public void testFinancialFieldsGetFilledInCorrectly() throws IOException { + public void testFinancialFieldValues() throws IOException { FinancialResponse[] results = smartySerializer.deserialize(validFinancialResponse.getBytes(), FinancialResponse[].class); FinancialResponse result = results[0]; @@ -57,4 +61,60 @@ public void testFinancialFieldsGetFilledInCorrectly() throws IOException { assertEquals(1, financial_history.length); assertEquals("Code_Title_Company", financial_history[0].code_title_company); } + + @Test + public void testSecondaryFieldValues() throws IOException { + SecondaryResponse[] results = smartySerializer.deserialize(validSecondaryResponse.getBytes(), SecondaryResponse[].class); + + SecondaryResponse result = results[0]; + assertEquals("123", result.getSmartyKey()); + + assertNotNull(result.getRootAddress()); + RootAddress rootAddress = result.getRootAddress(); + assertEquals(1, rootAddress.getSecondaryCount()); + assertEquals("root_smartykey", rootAddress.getSmartyKey()); + assertEquals("root_primary", rootAddress.getPrimaryNumber()); + assertEquals("root_predirection", rootAddress.getStreetPredirection()); + assertEquals("root_streetname", rootAddress.getStreetName()); + assertEquals("root_street_suffix", rootAddress.getStreetSuffix()); + assertEquals("root_postdirection", rootAddress.getStreetPostdirection()); + assertEquals("root_city", rootAddress.getCityName()); + assertEquals("root_state", rootAddress.getStateAbbreviation()); + assertEquals("root_zipcode", rootAddress.getZipcode()); + assertEquals("root_plus4", rootAddress.getPlus4Code()); + + + assertNotNull(result.getAliases()); + ArrayList aliases = result.getAliases(); + assertEquals(1, aliases.size()); + Alias alias = aliases.get(0); + assertEquals("alias_smartykey", alias.getSmartyKey()); + assertEquals("alias_city", alias.getCityName()); + assertEquals("alias_plus4", alias.getPlus4Code()); + assertEquals("alias_primary", alias.getPrimaryNumber()); + assertEquals("alias_state", alias.getStateAbbreviation()); + assertEquals("alias_streetname", alias.getStreetName()); + assertEquals("alias_predirectional", alias.getStreetPredirection()); + assertEquals("alias_zipcode", alias.getZipcode()); + assertEquals("alias_postdirection", alias.getStreetPostdirection()); + assertEquals("alias_streetsuffix", alias.getStreetSuffix()); + + assertNotNull(result.getSecondaries()); + ArrayList secondaries = result.getSecondaries(); + assertEquals(1, secondaries.size()); + Secondary secondary = secondaries.get(0); + assertEquals("secondary_smartykey", secondary.getSmartyKey()); + assertEquals("secondary_designator", secondary.getSecondaryDesignator()); + assertEquals("secondary_number", secondary.getSecondaryNumber()); + assertEquals("secondary_plus4", secondary.getPlus4Code()); + } + + @Test + public void testSecondaryCountFiedlValues() throws IOException { + SecondaryCountResponse[] results = smartySerializer.deserialize(validSecondaryCountResponse.getBytes(), SecondaryCountResponse[].class); + SecondaryCountResponse result = results[0]; + + assertEquals("123", result.getSmartyKey()); + assertEquals(10, result.getCount()); + } }