-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
18 changed files
with
929 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/main/java/com/smartystreets/api/us_enrichment/Client.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/main/java/com/smartystreets/api/us_enrichment/lookup_types/Lookup.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
...rtystreets/api/us_enrichment/lookup_types/property_financial/PropertyFinancialLookup.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...rtystreets/api/us_enrichment/lookup_types/property_principal/PropertyPrincipalLookup.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
src/main/java/com/smartystreets/api/us_enrichment/result_types/Attributes.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package com.smartystreets.api.us_enrichment.result_types; | ||
|
||
public class Attributes extends EnrichmentToStringer { | ||
} |
47 changes: 47 additions & 0 deletions
47
src/main/java/com/smartystreets/api/us_enrichment/result_types/EnrichmentToStringer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/com/smartystreets/api/us_enrichment/result_types/Result.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
|
||
} | ||
|
Oops, something went wrong.