From d4088b6bade3f3c4c052292d2e1ce3bc22c69ca4 Mon Sep 17 00:00:00 2001 From: Landon Fackrell <128620767+LandonSmarty@users.noreply.github.com> Date: Mon, 27 Nov 2023 12:00:33 -0700 Subject: [PATCH] Add Enrichment SDK (#43) Add the Enrichment api to the Java SDK. --- .../com/smartystreets/api/ClientBuilder.java | 22 +- .../java/com/smartystreets/api/Request.java | 4 + .../smartystreets/api/URLPrefixSender.java | 1 - .../api/us_enrichment/Client.java | 52 +++ .../us_enrichment/lookup_types/Lookup.java | 32 ++ .../PropertyFinancialLookup.java | 27 ++ .../PropertyPrincipalLookup.java | 27 ++ .../result_types/Attributes.java | 4 + .../result_types/EnrichmentToStringer.java | 47 +++ .../us_enrichment/result_types/Result.java | 26 ++ .../FinancialAttributes.java | 105 +++++ .../FinancialHistoryEntry.java | 50 +++ .../property_financial/FinancialResponse.java | 11 + .../PrincipalAttributes.java | 369 ++++++++++++++++++ .../property_principal/PrincipalResponse.java | 11 + .../java/examples/UsEnrichmentExample.java | 55 +++ .../api/us_enrichment/ClientTest.java | 35 ++ .../api/us_enrichment/ResponseTest.java | 60 +++ 18 files changed, 929 insertions(+), 9 deletions(-) create mode 100644 src/main/java/com/smartystreets/api/us_enrichment/Client.java create mode 100644 src/main/java/com/smartystreets/api/us_enrichment/lookup_types/Lookup.java create mode 100644 src/main/java/com/smartystreets/api/us_enrichment/lookup_types/property_financial/PropertyFinancialLookup.java create mode 100644 src/main/java/com/smartystreets/api/us_enrichment/lookup_types/property_principal/PropertyPrincipalLookup.java create mode 100644 src/main/java/com/smartystreets/api/us_enrichment/result_types/Attributes.java create mode 100644 src/main/java/com/smartystreets/api/us_enrichment/result_types/EnrichmentToStringer.java create mode 100644 src/main/java/com/smartystreets/api/us_enrichment/result_types/Result.java create mode 100644 src/main/java/com/smartystreets/api/us_enrichment/result_types/property_financial/FinancialAttributes.java create mode 100644 src/main/java/com/smartystreets/api/us_enrichment/result_types/property_financial/FinancialHistoryEntry.java create mode 100644 src/main/java/com/smartystreets/api/us_enrichment/result_types/property_financial/FinancialResponse.java create mode 100644 src/main/java/com/smartystreets/api/us_enrichment/result_types/property_principal/PrincipalAttributes.java create mode 100644 src/main/java/com/smartystreets/api/us_enrichment/result_types/property_principal/PrincipalResponse.java create mode 100644 src/main/java/examples/UsEnrichmentExample.java create mode 100644 src/test/java/com/smartystreets/api/us_enrichment/ClientTest.java create mode 100644 src/test/java/com/smartystreets/api/us_enrichment/ResponseTest.java diff --git a/src/main/java/com/smartystreets/api/ClientBuilder.java b/src/main/java/com/smartystreets/api/ClientBuilder.java index f50cec6..949187f 100644 --- a/src/main/java/com/smartystreets/api/ClientBuilder.java +++ b/src/main/java/com/smartystreets/api/ClientBuilder.java @@ -20,6 +20,7 @@ public class ClientBuilder { private final static String US_STREET_API_URL = "https://us-street.api.smarty.com/street-address"; private final static String US_ZIP_CODE_API_URL = "https://us-zipcode.api.smarty.com/lookup"; private final static String US_REVERSE_GEO_API_URL = "https://us-reverse-geo.api.smarty.com/lookup"; + private static final String US_ENRICHMENT_API_URL = "https://us-enrichment.api.smarty.com/lookup"; private Credentials signer; private Serializer serializer; private Sender httpSender; @@ -134,45 +135,50 @@ public ClientBuilder withLicenses(List licenses) { } public com.smartystreets.api.international_street.Client buildInternationalStreetApiClient() { - this.ensureURLPrefixNotNull(this.INTERNATIONAL_STREET_API_URL); + this.ensureURLPrefixNotNull(INTERNATIONAL_STREET_API_URL); return new com.smartystreets.api.international_street.Client(this.buildSender(), this.serializer); } public com.smartystreets.api.international_autocomplete.Client buildInternationalAutcompleteApiClient() { - this.ensureURLPrefixNotNull(this.INTERNATIONAL_AUTOCOMPLETE_API_URL); + this.ensureURLPrefixNotNull(INTERNATIONAL_AUTOCOMPLETE_API_URL); return new com.smartystreets.api.international_autocomplete.Client(this.buildSender(), this.serializer); } public com.smartystreets.api.us_autocomplete.Client buildUsAutocompleteApiClient() { - this.ensureURLPrefixNotNull(this.US_AUTOCOMPLETE_API_URL); + this.ensureURLPrefixNotNull(US_AUTOCOMPLETE_API_URL); return new com.smartystreets.api.us_autocomplete.Client(this.buildSender(), this.serializer); } public com.smartystreets.api.us_autocomplete_pro.Client buildUsAutocompleteProApiClient() { - this.ensureURLPrefixNotNull(this.US_AUTOCOMPLETE_API_PRO_URL); + this.ensureURLPrefixNotNull(US_AUTOCOMPLETE_API_PRO_URL); return new com.smartystreets.api.us_autocomplete_pro.Client(this.buildSender(), this.serializer); } public com.smartystreets.api.us_extract.Client buildUsExtractApiClient() { - this.ensureURLPrefixNotNull(this.US_EXTRACT_API_URL); + this.ensureURLPrefixNotNull(US_EXTRACT_API_URL); return new com.smartystreets.api.us_extract.Client(this.buildSender(), this.serializer); } public com.smartystreets.api.us_street.Client buildUsStreetApiClient() { - this.ensureURLPrefixNotNull(this.US_STREET_API_URL); + this.ensureURLPrefixNotNull(US_STREET_API_URL); return new com.smartystreets.api.us_street.Client(this.buildSender(), this.serializer); } public com.smartystreets.api.us_zipcode.Client buildUsZipCodeApiClient() { - this.ensureURLPrefixNotNull(this.US_ZIP_CODE_API_URL); + this.ensureURLPrefixNotNull(US_ZIP_CODE_API_URL); return new com.smartystreets.api.us_zipcode.Client(this.buildSender(), this.serializer); } public com.smartystreets.api.us_reverse_geo.Client buildUsReverseGeoClient() { - this.ensureURLPrefixNotNull(this.US_REVERSE_GEO_API_URL); + this.ensureURLPrefixNotNull(US_REVERSE_GEO_API_URL); return new com.smartystreets.api.us_reverse_geo.Client(this.buildSender(), this.serializer); } + public com.smartystreets.api.us_enrichment.Client buildUsEnrichmentClient() { + this.ensureURLPrefixNotNull(US_ENRICHMENT_API_URL); + return new com.smartystreets.api.us_enrichment.Client(this.buildSender(), this.serializer); + } + private Sender buildSender() { if (this.httpSender != null) return this.httpSender; diff --git a/src/main/java/com/smartystreets/api/Request.java b/src/main/java/com/smartystreets/api/Request.java index b5fc3fd..86bd927 100644 --- a/src/main/java/com/smartystreets/api/Request.java +++ b/src/main/java/com/smartystreets/api/Request.java @@ -96,6 +96,10 @@ public void setUrlPrefix(String urlPrefix) { this.urlPrefix = urlPrefix; } + public String getUrlPrefix() { + return urlPrefix; + } + public void setContentType(String contentType) { this.contentType = contentType; } diff --git a/src/main/java/com/smartystreets/api/URLPrefixSender.java b/src/main/java/com/smartystreets/api/URLPrefixSender.java index ed2d741..b74f787 100644 --- a/src/main/java/com/smartystreets/api/URLPrefixSender.java +++ b/src/main/java/com/smartystreets/api/URLPrefixSender.java @@ -20,7 +20,6 @@ public Response send(Request request) throws IOException, SmartyException, Inter } else { request.setUrlPrefix(this.urlPrefix); } - return this.inner.send(request); } } diff --git a/src/main/java/com/smartystreets/api/us_enrichment/Client.java b/src/main/java/com/smartystreets/api/us_enrichment/Client.java new file mode 100644 index 0000000..50f6334 --- /dev/null +++ b/src/main/java/com/smartystreets/api/us_enrichment/Client.java @@ -0,0 +1,52 @@ +package com.smartystreets.api.us_enrichment; + +import com.smartystreets.api.Request; +import com.smartystreets.api.Response; +import com.smartystreets.api.Sender; +import com.smartystreets.api.Serializer; +import com.smartystreets.api.exceptions.SmartyException; +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.result_types.property_financial.FinancialResponse; +import com.smartystreets.api.us_enrichment.result_types.property_principal.PrincipalResponse; + +import java.io.IOException; + +public class Client { + private Sender sender; + private Serializer serializer; + + public Client(Sender sender, Serializer serializer) { + this.sender = sender; + this.serializer = serializer; + } + + public FinancialResponse[] sendPropertyFinancialLookup(String smartyKey) throws SmartyException, IOException, InterruptedException { + PropertyFinancialLookup lookup = new PropertyFinancialLookup(smartyKey); + send(lookup); + return lookup.getResults(); + } + + public PrincipalResponse[] sendPropertyPrincipalLookup(String smartyKey) throws SmartyException, IOException, InterruptedException { + PropertyPrincipalLookup lookup = new PropertyPrincipalLookup(smartyKey); + 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"); + + Request request = this.buildRequest(lookup); + Response response = this.sender.send(request); + + lookup.deserializeAndSetResults(serializer, response.getPayload()); + } + + private Request buildRequest(Lookup lookup) { + Request request = new Request(); + request.setUrlPrefix("/" + lookup.getSmartyKey() + "/" + lookup.getDatasetName() + "/" + lookup.getDataSubsetName()); + return request; + } +} diff --git a/src/main/java/com/smartystreets/api/us_enrichment/lookup_types/Lookup.java b/src/main/java/com/smartystreets/api/us_enrichment/lookup_types/Lookup.java new file mode 100644 index 0000000..ebd8366 --- /dev/null +++ b/src/main/java/com/smartystreets/api/us_enrichment/lookup_types/Lookup.java @@ -0,0 +1,32 @@ +package com.smartystreets.api.us_enrichment.lookup_types; + +import com.smartystreets.api.Serializer; + +import java.io.IOException; + +public abstract class Lookup { + private final String smartyKey; + private final String datasetName; + private final String dataSubsetName; + + public Lookup(String smartyKey, String datasetName, String dataSubsetName) { + this.smartyKey = smartyKey; + this.datasetName = datasetName; + this.dataSubsetName = dataSubsetName; + } + + public String getSmartyKey() { + return smartyKey; + } + + public String getDatasetName() { + return datasetName; + } + + public String getDataSubsetName() { + return dataSubsetName; + } + + public abstract void deserializeAndSetResults(Serializer serializer, byte[] payload) throws IOException; + +} diff --git a/src/main/java/com/smartystreets/api/us_enrichment/lookup_types/property_financial/PropertyFinancialLookup.java b/src/main/java/com/smartystreets/api/us_enrichment/lookup_types/property_financial/PropertyFinancialLookup.java new file mode 100644 index 0000000..8db1bf9 --- /dev/null +++ b/src/main/java/com/smartystreets/api/us_enrichment/lookup_types/property_financial/PropertyFinancialLookup.java @@ -0,0 +1,27 @@ +package com.smartystreets.api.us_enrichment.lookup_types.property_financial; + +import com.smartystreets.api.Serializer; +import com.smartystreets.api.us_enrichment.lookup_types.Lookup; +import com.smartystreets.api.us_enrichment.result_types.property_financial.FinancialResponse; + +import java.io.IOException; + +public class PropertyFinancialLookup extends Lookup { + private FinancialResponse[] results; + public PropertyFinancialLookup(String smartyKey) { + super(smartyKey, "property", "financial"); + } + + public FinancialResponse[] getResults() { + return results; + } + + public void setResults(FinancialResponse[] results) { + this.results = results; + } + + @Override + public void deserializeAndSetResults(Serializer serializer, byte[] payload) throws IOException { + this.results = serializer.deserialize(payload, FinancialResponse[].class); + } +} diff --git a/src/main/java/com/smartystreets/api/us_enrichment/lookup_types/property_principal/PropertyPrincipalLookup.java b/src/main/java/com/smartystreets/api/us_enrichment/lookup_types/property_principal/PropertyPrincipalLookup.java new file mode 100644 index 0000000..aad34cb --- /dev/null +++ b/src/main/java/com/smartystreets/api/us_enrichment/lookup_types/property_principal/PropertyPrincipalLookup.java @@ -0,0 +1,27 @@ +package com.smartystreets.api.us_enrichment.lookup_types.property_principal; + +import com.smartystreets.api.Serializer; +import com.smartystreets.api.us_enrichment.lookup_types.Lookup; +import com.smartystreets.api.us_enrichment.result_types.property_principal.PrincipalResponse; + +import java.io.IOException; + +public class PropertyPrincipalLookup extends Lookup { + private PrincipalResponse[] results; + public PropertyPrincipalLookup(String smartyKey) { + super(smartyKey, "property", "principal"); + } + + public PrincipalResponse[] getResults() { + return results; + } + + public void setResults(PrincipalResponse[] results) { + this.results = results; + } + + @Override + public void deserializeAndSetResults(Serializer serializer, byte[] payload) throws IOException { + this.results = serializer.deserialize(payload, PrincipalResponse[].class); + } +} diff --git a/src/main/java/com/smartystreets/api/us_enrichment/result_types/Attributes.java b/src/main/java/com/smartystreets/api/us_enrichment/result_types/Attributes.java new file mode 100644 index 0000000..d4dcadd --- /dev/null +++ b/src/main/java/com/smartystreets/api/us_enrichment/result_types/Attributes.java @@ -0,0 +1,4 @@ +package com.smartystreets.api.us_enrichment.result_types; + +public class Attributes extends EnrichmentToStringer { +} diff --git a/src/main/java/com/smartystreets/api/us_enrichment/result_types/EnrichmentToStringer.java b/src/main/java/com/smartystreets/api/us_enrichment/result_types/EnrichmentToStringer.java new file mode 100644 index 0000000..27177dd --- /dev/null +++ b/src/main/java/com/smartystreets/api/us_enrichment/result_types/EnrichmentToStringer.java @@ -0,0 +1,47 @@ +package com.smartystreets.api.us_enrichment.result_types; + +import java.lang.reflect.Array; +import java.lang.reflect.Field; + +public class EnrichmentToStringer { + @Override + public String toString() { + Class clazz = getClass(); + StringBuilder sb = new StringBuilder(); + sb.append(clazz.getSimpleName()).append(":\n"); + + while (clazz != null) { + for (Field field : clazz.getDeclaredFields()) { + field.setAccessible(true); + try { + Object value = field.get(this); + if (value != null) { + if (value.getClass().isArray()) { + value = arrayToString(value); + } + sb.append(field.getName()).append(": ").append(value).append("\n"); + } + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + } + clazz = clazz.getSuperclass(); + } + + return sb.toString(); + } + + private String arrayToString(Object array) { + int length = Array.getLength(array); + StringBuilder sb = new StringBuilder("["); + for (int i = 0; i < length; i++) { + Object element = Array.get(array, i); + sb.append(element); + if (i < length - 1) { + sb.append(", "); + } + } + sb.append("]"); + return sb.toString(); + } +} diff --git a/src/main/java/com/smartystreets/api/us_enrichment/result_types/Result.java b/src/main/java/com/smartystreets/api/us_enrichment/result_types/Result.java new file mode 100644 index 0000000..8cc793c --- /dev/null +++ b/src/main/java/com/smartystreets/api/us_enrichment/result_types/Result.java @@ -0,0 +1,26 @@ +package com.smartystreets.api.us_enrichment.result_types; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class Result extends EnrichmentToStringer { + @JsonProperty("smarty_key") + private String smartyKey; + @JsonProperty("data_set_name") + private String datasetName; + @JsonProperty("data_subset_name") + private String dataSubsetName; + + public String getSmartyKey() { + return smartyKey; + } + + public String getDatasetName() { + return datasetName; + } + + public String getDataSubsetName() { + return dataSubsetName; + } + +} + diff --git a/src/main/java/com/smartystreets/api/us_enrichment/result_types/property_financial/FinancialAttributes.java b/src/main/java/com/smartystreets/api/us_enrichment/result_types/property_financial/FinancialAttributes.java new file mode 100644 index 0000000..1a5be33 --- /dev/null +++ b/src/main/java/com/smartystreets/api/us_enrichment/result_types/property_financial/FinancialAttributes.java @@ -0,0 +1,105 @@ +package com.smartystreets.api.us_enrichment.result_types.property_financial; + +import com.smartystreets.api.us_enrichment.result_types.Attributes; + +public class FinancialAttributes extends Attributes { + public String assessed_improvement_percent; + public String assessed_improvement_value; + public String assessed_land_value; + public String assessed_value; + public String assessor_last_update; + public String assessor_taxroll_update; + public String contact_city; + public String contact_crrt; + public String contact_full_address; + public String contact_house_number; + public String contact_mail_info_format; + public String contact_mail_info_privacy; + public String contact_mailing_county; + public String contact_mailing_fips; + public String contact_post_direction; + public String contact_pre_direction; + public String contact_state; + public String contact_street_name; + public String contact_suffix; + public String contact_unit_designator; + public String contact_value; + public String contact_zip; + public String contact_zip4; + public String deed_document_book; + public String deed_document_number; + public String deed_document_page; + public String deed_owner_first_name; + public String deed_owner_first_name2; + public String deed_owner_first_name3; + public String deed_owner_first_name4; + public String deed_owner_full_name; + public String deed_owner_full_name2; + public String deed_owner_full_name3; + public String deed_owner_full_name4; + public String deed_owner_last_name; + public String deed_owner_last_name2; + public String deed_owner_last_name3; + public String deed_owner_last_name4; + public String deed_owner_middle_name; + public String deed_owner_middle_name2; + public String deed_owner_middle_name3; + public String deed_owner_middle_name4; + public String deed_owner_suffix; + public String deed_owner_suffix2; + public String deed_owner_suffix3; + public String deed_owner_suffix4; + public String deed_sale_date; + public String deed_sale_price; + public String deed_transaction_id; + public String disabled_tax_exemption; + public FinancialHistoryEntry[] financial_history; + public String first_name; + public String first_name_2; + public String first_name_3; + public String first_name_4; + public String homeowner_tax_exemption; + public String last_name; + public String last_name_2; + public String last_name_3; + public String last_name_4; + public String market_improvement_percent; + public String market_improvement_value; + public String market_land_value; + public String market_value_year; + public String match_type; + public String middle_name; + public String middle_name_2; + public String middle_name_3; + public String middle_name_4; + public String other_tax_exemption; + public String owner_full_name; + public String owner_full_name_2; + public String owner_full_name_3; + public String owner_full_name_4; + public String ownership_transfer_date; + public String ownership_transfer_doc_number; + public String ownership_transfer_transaction_id; + public String ownership_type; + public String ownership_type_2; + public String previous_assessed_value; + public String prior_sale_amount; + public String prior_sale_date; + public String sale_amount; + public String sale_date; + public String senior_tax_exemption; + public String suffix; + public String suffix_2; + public String suffix_3; + public String suffix_4; + public String tax_assess_year; + public String tax_billed_amount; + public String tax_delinquent_year; + public String tax_fiscal_year; + public String tax_rate_area; + public String total_market_value; + public String trust_description; + public String veteran_tax_exemption; + public String widow_tax_exemption; +} + diff --git a/src/main/java/com/smartystreets/api/us_enrichment/result_types/property_financial/FinancialHistoryEntry.java b/src/main/java/com/smartystreets/api/us_enrichment/result_types/property_financial/FinancialHistoryEntry.java new file mode 100644 index 0000000..531c6a0 --- /dev/null +++ b/src/main/java/com/smartystreets/api/us_enrichment/result_types/property_financial/FinancialHistoryEntry.java @@ -0,0 +1,50 @@ +package com.smartystreets.api.us_enrichment.result_types.property_financial; + +import com.smartystreets.api.us_enrichment.result_types.EnrichmentToStringer; + +public class FinancialHistoryEntry extends EnrichmentToStringer { + + public String code_title_company; + public String document_type_description; + public String instrument_date; + public String interest_rate_type_2; + public String lender_address; + public String lender_address_2; + public String lender_city; + public String lender_city_2; + public String lender_code_2; + public String lender_first_name; + public String lender_first_name_2; + public String lender_last_name; + public String lender_last_name_2; + public String lender_name; + public String lender_name_2; + public String lender_seller_carry_back; + public String lender_seller_carry_back_2; + public String lender_state; + public String lender_state_2; + public String lender_zip; + public String lender_zip_2; + public String lender_zip_extended; + public String lender_zip_extended_2; + public String mortgage_amount; + public String mortgage_amount_2; + public String mortgage_due_date; + public String mortgage_due_date_2; + public String mortgage_interest_rate; + public String mortgage_interest_rate_type; + public String mortgage_lender_code; + public String mortgage_rate_2; + public String mortgage_recording_date; + public String mortgage_recording_date_2; + public String mortgage_term; + public String mortgage_term_2; + public String mortgage_term_type; + public String mortgage_term_type_2; + public String mortgage_type; + public String mortgage_type_2; + public String multi_parcel_flag; + public String name_title_company; + public String recording_date; + public String transfer_amount; +} diff --git a/src/main/java/com/smartystreets/api/us_enrichment/result_types/property_financial/FinancialResponse.java b/src/main/java/com/smartystreets/api/us_enrichment/result_types/property_financial/FinancialResponse.java new file mode 100644 index 0000000..0aaae06 --- /dev/null +++ b/src/main/java/com/smartystreets/api/us_enrichment/result_types/property_financial/FinancialResponse.java @@ -0,0 +1,11 @@ +package com.smartystreets.api.us_enrichment.result_types.property_financial; + +import com.smartystreets.api.us_enrichment.result_types.Result; + +public class FinancialResponse extends Result { + private FinancialAttributes attributes; + + public FinancialAttributes getAttributes() { + return attributes; + } +} diff --git a/src/main/java/com/smartystreets/api/us_enrichment/result_types/property_principal/PrincipalAttributes.java b/src/main/java/com/smartystreets/api/us_enrichment/result_types/property_principal/PrincipalAttributes.java new file mode 100644 index 0000000..a381a16 --- /dev/null +++ b/src/main/java/com/smartystreets/api/us_enrichment/result_types/property_principal/PrincipalAttributes.java @@ -0,0 +1,369 @@ +package com.smartystreets.api.us_enrichment.result_types.property_principal; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.smartystreets.api.us_enrichment.result_types.Attributes; + +public class PrincipalAttributes extends Attributes { + @JsonProperty("1st_floor_sqft") + public String first_floor_sqft; + @JsonProperty("2nd_floor_sqft") + public String second_floor_sqft; + public String acres; + public String air_conditioner; + public String arbor_pergola; + public String assessed_improvement_percent; + public String assessed_improvement_value; + public String assessed_land_value; + public String assessed_value; + public String assessor_last_update; + public String assessor_taxroll_update; + public String attic_area; + public String attic_flag; + public String balcony; + public String balcony_area; + public String basement_sqft; + public String basement_sqft_finished; + public String basement_sqft_unfinished; + public String bath_house; + public String bath_house_sqft; + public String bathrooms_partial; + public String bathrooms_total; + public String bedrooms; + public String block1; + public String block2; + public String boat_access; + public String boat_house; + public String boat_house_sqft; + public String boat_lift; + public String bonus_room; + public String breakfast_nook; + public String breezeway; + public String building_definition_code; + public String building_sqft; + public String cabin; + public String cabin_sqft; + public String canopy; + public String canopy_sqft; + public String carport; + public String carport_sqft; + public String cbsa_code; + public String cbsa_name; + public String cellar; + public String census_block; + public String census_block_group; + public String census_fips_place_code; + public String census_tract; + public String central_vacuum; + public String code_title_company; + public String combined_statistical_area; + public String community_rec; + public String company_flag; + public String congressional_district; + public String construction_type; + public String contact_city; + public String contact_crrt; + public String contact_full_address; + public String contact_house_number; + public String contact_mail_info_format; + public String contact_mail_info_privacy; + public String contact_mailing_county; + public String contact_mailing_fips; + public String contact_post_direction; + public String contact_pre_direction; + public String contact_state; + public String contact_street_name; + public String contact_suffix; + public String contact_unit_designator; + public String contact_value; + public String contact_zip; + public String contact_zip4; + public String courtyard; + public String courtyard_area; + public String deck; + public String deck_area; + public String deed_document_book; + public String deed_document_number; + public String deed_document_page; + public String deed_owner_first_name; + public String deed_owner_first_name2; + public String deed_owner_first_name3; + public String deed_owner_first_name4; + public String deed_owner_full_name; + public String deed_owner_full_name2; + public String deed_owner_full_name3; + public String deed_owner_full_name4; + public String deed_owner_last_name; + public String deed_owner_last_name2; + public String deed_owner_last_name3; + public String deed_owner_last_name4; + public String deed_owner_middle_name; + public String deed_owner_middle_name2; + public String deed_owner_middle_name3; + public String deed_owner_middle_name4; + public String deed_owner_suffix; + public String deed_owner_suffix2; + public String deed_owner_suffix3; + public String deed_owner_suffix4; + public String deed_sale_date; + public String deed_sale_price; + public String deed_transaction_id; + public String depth_linear_footage; + public String disabled_tax_exemption; + public String document_type_description; + public String driveway_sqft; + public String driveway_type; + public String effective_year_built; + public String elevation_feet; + public String elevator; + public String equestrian_arena; + public String escalator; + public String exercise_room; + public String exterior_walls; + public String family_room; + public String fence; + public String fence_area; + public String fips_code; + public String fire_resistance_code; + public String fire_sprinklers_flag; + public String fireplace; + public String fireplace_number; + public String first_name; + public String first_name_2; + public String first_name_3; + public String first_name_4; + public String flooring; + public String foundation; + public String game_room; + public String garage; + public String garage_sqft; + public String gazebo; + public String gazebo_sqft; + public String golf_course; + public String grainery; + public String grainery_sqft; + public String great_room; + public String greenhouse; + public String greenhouse_sqft; + public String gross_sqft; + public String guesthouse; + public String guesthouse_sqft; + public String handicap_accessibility; + public String heat; + public String heat_fuel_type; + public String hobby_room; + public String homeowner_tax_exemption; + public String instrument_date; + public String intercom_system; + public String interest_rate_type_2; + public String interior_structure; + public String kennel; + public String kennel_sqft; + public String land_use_code; + public String land_use_group; + public String land_use_standard; + public String last_name; + public String last_name_2; + public String last_name_3; + public String last_name_4; + public String latitude; + public String laundry; + public String lean_to; + public String lean_to_sqft; + public String legal_description; + public String legal_unit; + public String lender_address; + public String lender_address_2; + public String lender_city; + public String lender_city_2; + public String lender_code_2; + public String lender_first_name; + public String lender_first_name_2; + public String lender_last_name; + public String lender_last_name_2; + public String lender_name; + public String lender_name_2; + public String lender_seller_carry_back; + public String lender_seller_carry_back_2; + public String lender_state; + public String lender_state_2; + public String lender_zip; + public String lender_zip_2; + public String lender_zip_extended; + public String lender_zip_extended_2; + public String loading_platform; + public String loading_platform_sqft; + public String longitude; + public String lot_1; + public String lot_2; + public String lot_3; + public String lot_sqft; + public String market_improvement_percent; + public String market_improvement_value; + public String market_land_value; + public String market_value_year; + public String match_type; + public String media_room; + public String metro_division; + public String middle_name; + public String middle_name_2; + public String middle_name_3; + public String middle_name_4; + public String milkhouse; + public String milkhouse_sqft; + public String minor_civil_division_code; + public String minor_civil_division_name; + public String mobile_home_hookup; + public String mortgage_amount; + public String mortgage_amount_2; + public String mortgage_due_date; + public String mortgage_due_date_2; + public String mortgage_interest_rate; + public String mortgage_interest_rate_type; + public String mortgage_lender_code; + public String mortgage_rate_2; + public String mortgage_recording_date; + public String mortgage_recording_date_2; + public String mortgage_term; + public String mortgage_term_2; + public String mortgage_term_type; + public String mortgage_term_type_2; + public String mortgage_type; + public String mortgage_type_2; + public String msa_code; + public String msa_name; + public String mud_room; + public String multi_parcel_flag; + public String name_title_company; + public String neighborhood_code; + public String number_of_buildings; + public String office; + public String office_sqft; + public String other_tax_exemption; + public String outdoor_kitchen_fireplace; + public String overhead_door; + public String owner_full_name; + public String owner_full_name_2; + public String owner_full_name_3; + public String owner_full_name_4; + public String owner_occupancy_status; + public String ownership_transfer_date; + public String ownership_transfer_doc_number; + public String ownership_transfer_transaction_id; + public String ownership_type; + public String ownership_type_2; + public String ownership_vesting_relation_code; + public String parcel_account_number; + public String parcel_map_book; + public String parcel_map_page; + public String parcel_number_alternate; + public String parcel_number_formatted; + public String parcel_number_previous; + public String parcel_number_year_added; + public String parcel_number_year_change; + public String parcel_raw_number; + public String parcel_shell_record; + public String parking_spaces; + public String patio_area; + public String phase_name; + public String plumbing_fixtures_count; + public String pole_struct; + public String pole_struct_sqft; + public String pond; + public String pool; + public String pool_area; + public String poolhouse; + public String poolhouse_sqft; + public String porch; + public String porch_area; + public String poultry_house; + public String poultry_house_sqft; + public String previous_assessed_value; + public String prior_sale_amount; + public String prior_sale_date; + public String property_address_carrier_route_code; + public String property_address_city; + public String property_address_full; + public String property_address_house_number; + public String property_address_post_direction; + public String property_address_pre_direction; + public String property_address_state; + public String property_address_street_name; + public String property_address_street_suffix; + public String property_address_unit_designator; + public String property_address_unit_value; + public String property_address_zip_4; + public String property_address_zipcode; + public String publication_date; + public String quarter; + public String quarter_quarter; + public String quonset; + public String quonset_sqft; + public String range; + public String recording_date; + public String roof_cover; + public String roof_frame; + public String rooms; + public String rv_parking; + public String safe_room; + public String sale_amount; + public String sale_date; + public String sauna; + public String section; + public String security_alarm; + public String senior_tax_exemption; + public String sewer_type; + public String shed; + public String shed_sqft; + public String silo; + public String silo_sqft; + public String sitting_room; + public String situs_county; + public String situs_state; + public String sound_system; + public String sports_court; + public String sprinklers; + public String stable; + public String stable_sqft; + public String storage_building; + public String storage_building_sqft; + public String stories_number; + public String storm_shelter; + public String storm_shutter; + public String structure_style; + public String study; + public String subdivision; + public String suffix; + public String suffix_2; + public String suffix_3; + public String suffix_4; + public String sunroom; + public String tax_assess_year; + public String tax_billed_amount; + public String tax_delinquent_year; + public String tax_fiscal_year; + public String tax_jurisdiction; + public String tax_rate_area; + public String tennis_court; + public String topography_code; + public String total_market_value; + public String township; + public String tract_number; + public String transfer_amount; + public String trust_description; + public String unit_count; + public String upper_floors_sqft; + public String utility; + public String utility_building; + public String utility_building_sqft; + public String utility_sqft; + public String veteran_tax_exemption; + public String view_description; + public String water_feature; + public String water_service_type; + public String wet_bar; + public String widow_tax_exemption; + public String width_linear_footage; + public String wine_cellar; + public String year_built; + public String zoning; +} diff --git a/src/main/java/com/smartystreets/api/us_enrichment/result_types/property_principal/PrincipalResponse.java b/src/main/java/com/smartystreets/api/us_enrichment/result_types/property_principal/PrincipalResponse.java new file mode 100644 index 0000000..5b679c7 --- /dev/null +++ b/src/main/java/com/smartystreets/api/us_enrichment/result_types/property_principal/PrincipalResponse.java @@ -0,0 +1,11 @@ +package com.smartystreets.api.us_enrichment.result_types.property_principal; + +import com.smartystreets.api.us_enrichment.result_types.Result; + +public class PrincipalResponse extends Result { + private PrincipalAttributes attributes; + + public PrincipalAttributes getAttributes() { + return attributes; + } +} diff --git a/src/main/java/examples/UsEnrichmentExample.java b/src/main/java/examples/UsEnrichmentExample.java new file mode 100644 index 0000000..54d49b3 --- /dev/null +++ b/src/main/java/examples/UsEnrichmentExample.java @@ -0,0 +1,55 @@ +package examples; + +import com.smartystreets.api.ClientBuilder; +import com.smartystreets.api.StaticCredentials; +import com.smartystreets.api.exceptions.SmartyException; +import com.smartystreets.api.us_enrichment.*; +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 java.io.IOException; +import java.util.Arrays; + +public class UsEnrichmentExample { + public static void main(String[] args) { + // We recommend storing your authentication credentials in environment variables. + // for server-to-server requests, use this code: + StaticCredentials credentials = new StaticCredentials(System.getenv("SMARTY_AUTH_ID"), System.getenv("SMARTY_AUTH_TOKEN")); + + // for client-side requests (browser/mobile), use this code: +// SharedCredentials credentials = new SharedCredentials(System.getenv("SMARTY_AUTH_WEB"), System.getenv("SMARTY_AUTH_REFERER")); + + Client client = new ClientBuilder(credentials).buildUsEnrichmentClient(); + + PrincipalResponse[] results = null; + try { + results = client.sendPropertyPrincipalLookup("1682393594"); + } + catch (SmartyException | IOException | InterruptedException ex) { + System.out.println(ex.getMessage()); + ex.printStackTrace(); + } + + if(results != null){ + System.out.println(Arrays.toString(results)); + } else { + System.out.println("Result was null"); + } + + FinancialResponse[] financialResults = null; + try { + financialResults = client.sendPropertyFinancialLookup("1682393594"); + } + catch (SmartyException | IOException | InterruptedException ex) { + System.out.println(ex.getMessage()); + ex.printStackTrace(); + } + + if(results != null){ + System.out.println(Arrays.toString(financialResults)); + } else { + System.out.println("Result was null"); + } + } +} diff --git a/src/test/java/com/smartystreets/api/us_enrichment/ClientTest.java b/src/test/java/com/smartystreets/api/us_enrichment/ClientTest.java new file mode 100644 index 0000000..03e6aa3 --- /dev/null +++ b/src/test/java/com/smartystreets/api/us_enrichment/ClientTest.java @@ -0,0 +1,35 @@ +package com.smartystreets.api.us_enrichment; + +import com.smartystreets.api.URLPrefixSender; +import com.smartystreets.api.mocks.FakeSerializer; +import com.smartystreets.api.mocks.RequestCapturingSender; +import com.smartystreets.api.us_enrichment.result_types.property_financial.FinancialResponse; +import com.smartystreets.api.us_enrichment.result_types.property_principal.PrincipalResponse; +import org.junit.Assert; +import org.junit.Test; + +public class ClientTest { + @Test + public void testSendingPrincipalLookup() throws Exception { + RequestCapturingSender capturingSender = new RequestCapturingSender(); + URLPrefixSender sender = new URLPrefixSender("http://localhost:8080", capturingSender); + FakeSerializer serializer = new FakeSerializer(new PrincipalResponse[]{new PrincipalResponse()}); + Client client = new Client(sender, serializer); + + client.sendPropertyPrincipalLookup("123"); + + Assert.assertEquals("http://localhost:8080/123/property/principal?", capturingSender.getRequest().getUrl()); + } + + @Test + public void testSendingFinancialLookup() throws Exception { + RequestCapturingSender capturingSender = new RequestCapturingSender(); + URLPrefixSender sender = new URLPrefixSender("http://localhost:8080", capturingSender); + FakeSerializer serializer = new FakeSerializer(new FinancialResponse[]{new FinancialResponse()}); + Client client = new Client(sender, serializer); + + client.sendPropertyFinancialLookup("123"); + + Assert.assertEquals("http://localhost:8080/123/property/financial?", capturingSender.getRequest().getUrl()); + } +} diff --git a/src/test/java/com/smartystreets/api/us_enrichment/ResponseTest.java b/src/test/java/com/smartystreets/api/us_enrichment/ResponseTest.java new file mode 100644 index 0000000..7b1285e --- /dev/null +++ b/src/test/java/com/smartystreets/api/us_enrichment/ResponseTest.java @@ -0,0 +1,60 @@ +package com.smartystreets.api.us_enrichment; + +import com.smartystreets.api.SmartySerializer; +import com.smartystreets.api.us_enrichment.result_types.property_financial.FinancialAttributes; +import com.smartystreets.api.us_enrichment.result_types.property_financial.FinancialHistoryEntry; +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 org.junit.Test; + +import java.io.IOException; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +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\"}}]"; + + + @Test + public void testPrincipalFieldsGetFillledInCorrectly() throws IOException { + PrincipalResponse[] results = smartySerializer.deserialize(validPrincipalResponse.getBytes(), PrincipalResponse[].class); + + PrincipalResponse result = results[0]; + assertEquals("123", result.getSmartyKey()); + assertEquals("property", result.getDatasetName()); + assertEquals("principal", result.getDataSubsetName()); + + assertNotNull(result.getAttributes()); + PrincipalAttributes attributes = result.getAttributes(); + + assertEquals("1st_Floor_Sqft", attributes.first_floor_sqft); + assertEquals("Lender_Name_2", attributes.lender_name_2); + assertEquals("Zoning", attributes.zoning); + } + + @Test + public void testFinancialFieldsGetFilledInCorrectly() throws IOException { + FinancialResponse[] results = smartySerializer.deserialize(validFinancialResponse.getBytes(), FinancialResponse[].class); + + FinancialResponse result = results[0]; + assertEquals("123", result.getSmartyKey()); + assertEquals("property", result.getDatasetName()); + assertEquals("financial", result.getDataSubsetName()); + + assertNotNull(result.getAttributes()); + FinancialAttributes attributes = result.getAttributes(); + + assertEquals("Assessed_Improvement_Percent", attributes.assessed_improvement_percent); + assertEquals("Veteran_Tax_Exemption", attributes.veteran_tax_exemption); + assertEquals("Widow_Tax_Exemption", attributes.widow_tax_exemption); + + FinancialHistoryEntry[] financial_history = attributes.financial_history; + assertEquals(1, financial_history.length); + assertEquals("Code_Title_Company", financial_history[0].code_title_company); + } +}