Skip to content

Commit c495ede

Browse files
authored
Merge pull request #44 from smartystreets/eric/enrichment-address-search
Added Address Search Feature
2 parents 41fdf64 + d5aa054 commit c495ede

File tree

13 files changed

+452
-35
lines changed

13 files changed

+452
-35
lines changed

src/examples/USEnrichmentGeoReferenceExample.cs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,29 @@ public static void Run()
2727
var client = new ClientBuilder(authId, authToken).BuildUsEnrichmentApiClient();
2828

2929
SmartyStreets.USEnrichmentApi.GeoReference.Result[] results = null;
30-
var lookup = new SmartyStreets.USEnrichmentApi.GeoReference.Lookup("1682393594");
30+
31+
32+
// Create a lookup with a smarty key using the line below
33+
var lookup = new SmartyStreets.USEnrichmentApi.GeoReference.Lookup("325023201");
34+
35+
// Create a lookup with address components using the lines below
36+
var componentsLookup = new SmartyStreets.USEnrichmentApi.GeoReference.Lookup();
37+
componentsLookup.SetStreet("56 Union Ave");
38+
componentsLookup.SetCity("Somerville");
39+
componentsLookup.SetState("NJ");
40+
componentsLookup.SetZipcode("08876");
41+
42+
// Create a lookup with a single line address using the line below
43+
var freeformLookup = new SmartyStreets.USEnrichmentApi.GeoReference.Lookup();
44+
freeformLookup.SetFreeform("56 Union Ave Somerville NJ 08876");
45+
3146
// Options available for the GeoReference Lookup
32-
// lookup.SetEtag("GEZTSMZYHE3DMNA");
47+
// lookup.SetEtag("GEZDSNBUHE3DEMQ");
48+
3349
try {
34-
// results = client.SendGeoReferenceLookup("1682393594"); // simple call with just a SmartyKey
50+
// results = client.SendGeoReferenceLookup("325023201"); // simple call with just a SmartyKey
51+
52+
// Send a lookup using the line below
3553
results = client.SendGeoReferenceLookup(lookup); // more flexible call to set other lookup options
3654
}
3755
catch (NotModifiedException ex) {

src/examples/USEnrichmentPropertyExample.cs

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,31 @@ public static void Run()
2828

2929

3030
SmartyStreets.USEnrichmentApi.Property.Principal.Result[] results = null;
31-
var lookup = new SmartyStreets.USEnrichmentApi.Property.Principal.Lookup("1682393594");
31+
32+
// Create a lookup with a smarty key using the line below
33+
var lookup = new SmartyStreets.USEnrichmentApi.Property.Principal.Lookup("325023201");
34+
35+
// Create a lookup with address components using the lines below
36+
var componentsLookup = new SmartyStreets.USEnrichmentApi.Property.Principal.Lookup();
37+
componentsLookup.SetStreet("56 Union Ave");
38+
componentsLookup.SetCity("Somerville");
39+
componentsLookup.SetState("NJ");
40+
componentsLookup.SetZipcode("08876");
41+
42+
// Create a lookup with a single line address using the line below
43+
var freeformLookup = new SmartyStreets.USEnrichmentApi.Property.Principal.Lookup();
44+
freeformLookup.SetFreeform("56 Union Ave Somerville NJ 08876");
45+
3246
// See the US Enrichment API documenation for available lookup properties https://www.smarty.com/docs/cloud/us-address-enrichment-api#http-request-input-fields
3347
// Options available for the Property Lookup
34-
// lookup.SetEtag("GU4TINZRHA4TQMY");
48+
// lookup.SetEtag("AIDAIAQCAIEQKAIC");
3549
// lookup.SetIncludeFields("assessed_value,assessor_last_update");
3650
// lookup.SetExcludeFields("tax_fiscal_year,tax_jurisdiction");
51+
3752
try {
38-
// results = client.SendPropertyPrincipalLookup("1682393594"); // simple call with just a SmartyKey
53+
// results = client.SendPropertyPrincipalLookup("325023201"); // simple call with just a SmartyKey
54+
55+
// Send a lookup using the line below
3956
results = client.SendPropertyPrincipalLookup(lookup); // more flexible call to set other lookup options
4057
}
4158
catch (NotModifiedException ex) {
@@ -55,13 +72,29 @@ public static void Run()
5572
}
5673

5774
SmartyStreets.USEnrichmentApi.Property.Financial.Result[] financialResults = null;
58-
var financialLookup = new SmartyStreets.USEnrichmentApi.Property.Financial.Lookup("1682393594");
75+
76+
// Create a lookup with a smarty key using the line below
77+
var financialLookup = new SmartyStreets.USEnrichmentApi.Property.Financial.Lookup("325023201");
78+
79+
// Create a lookup with address components using the lines below
80+
var financialComponentsLookup = new SmartyStreets.USEnrichmentApi.Property.Financial.Lookup();
81+
financialComponentsLookup.SetStreet("56 Union Ave");
82+
financialComponentsLookup.SetCity("Somerville");
83+
financialComponentsLookup.SetState("NJ");
84+
financialComponentsLookup.SetZipcode("08876");
85+
86+
// Create a lookup with a single line address using the line below
87+
var financialFreeformLookup = new SmartyStreets.USEnrichmentApi.Property.Financial.Lookup();
88+
financialFreeformLookup.SetFreeform("56 Union Ave Somerville NJ 08876");
89+
5990
// Options available for the Property Lookup
60-
// financialLookup.SetEtag("GU4TINZRHA4TQMY");
91+
// financialLookup.SetEtag("AIDAIAQCAIEQKAIC");
6192
// financialLookup.SetIncludeFields("assessed_value,assessor_last_update");
6293
// financialLookup.SetExcludeFields("tax_fiscal_year,tax_jurisdiction");
6394
try {
64-
// financialResults = client.SendPropertyFinancialLookup("1682393594"); // simple call with just a SmartyKey
95+
// financialResults = client.SendPropertyFinancialLookup("325023201"); // simple call with just a SmartyKey
96+
97+
// Send a lookup using the line below
6598
financialResults = client.SendPropertyFinancialLookup(financialLookup); // more flexible call to set other lookup options
6699
}
67100
catch (NotModifiedException ex) {

src/examples/USEnrichmentSecondaryExample.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,28 @@ public static void Run()
2929

3030
// See the US Enrichment API documenation for all available datasets and data subsets https://www.smarty.com/docs/cloud/us-address-enrichment-api#data-sets
3131
SmartyStreets.USEnrichmentApi.Secondary.Result[] results = null;
32+
33+
// Create a lookup with a smarty key using the line below
3234
var lookup = new SmartyStreets.USEnrichmentApi.Secondary.Lookup("325023201");
35+
36+
// Create a lookup with address components using the lines below
37+
var componentsLookup = new SmartyStreets.USEnrichmentApi.Secondary.Lookup();
38+
componentsLookup.SetStreet("56 Union Ave");
39+
componentsLookup.SetCity("Somerville");
40+
componentsLookup.SetState("NJ");
41+
componentsLookup.SetZipcode("08876");
42+
43+
// Create a lookup with a single line address using the line below
44+
var freeformLookup = new SmartyStreets.USEnrichmentApi.Secondary.Lookup();
45+
freeformLookup.SetFreeform("56 Union Ave Somerville NJ 08876");
46+
3347
// Options available for Lookup
3448
// lookup.SetEtag("HAYDKMJXHA4DKNA");
3549

3650
try {
51+
// results = client.SendSecondaryLookup("325023201"); // simple call with just a SmartyKey
52+
53+
// Send a lookup using the line below
3754
results = client.SendSecondaryLookup(lookup);
3855
}
3956
catch (NotModifiedException ex) {
@@ -67,11 +84,28 @@ public static void Run()
6784
}
6885

6986
SmartyStreets.USEnrichmentApi.Secondary.Count.Result[] countResults = null;
87+
88+
// Create a lookup with a smarty key using the line below
7089
var countLookup = new SmartyStreets.USEnrichmentApi.Secondary.Count.Lookup("325023201");
90+
91+
// Create a lookup with address components using the lines below
92+
var countComponentsLookup = new SmartyStreets.USEnrichmentApi.Secondary.Lookup();
93+
countComponentsLookup.SetStreet("56 Union Ave");
94+
countComponentsLookup.SetCity("Somerville");
95+
countComponentsLookup.SetState("NJ");
96+
countComponentsLookup.SetZipcode("08876");
97+
98+
// Create a lookup with a single line address using the line below
99+
var countFreeformLookup = new SmartyStreets.USEnrichmentApi.Secondary.Count.Lookup();
100+
countFreeformLookup.SetFreeform("56 Union Ave Somerville NJ 08876");
101+
71102
// Options available for Lookup
72103
// lookup.SetEtag("HAYDKMJXHA4DKNA");
73104

74105
try {
106+
// results = client.SendSecondaryCountLookup("325023201"); // simple call with just a SmartyKey
107+
108+
// Send a lookup using the line below
75109
countResults = client.SendSecondaryCountLookup(countLookup);
76110
}
77111
catch (NotModifiedException ex) {

src/examples/USEnrichmentUniversalExample.cs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,37 @@ public static void Run()
2626
ServicePointManager.SecurityProtocol = tlsProtocol1_2;
2727

2828
var client = new ClientBuilder(authId, authToken).BuildUsEnrichmentApiClient();
29-
29+
3030
byte[] results = null;
3131
// See the US Enrichment API documenation for all available datasets and data subsets https://www.smarty.com/docs/cloud/us-address-enrichment-api#data-sets
32-
var lookup = new SmartyStreets.USEnrichmentApi.Universal.Lookup("1682393594","property","principal");
32+
33+
// Create a lookup with a smarty key using the line below
34+
var lookup = new SmartyStreets.USEnrichmentApi.Universal.Lookup("325023201","property","principal");
35+
36+
// Create a lookup with address components using the lines below
37+
var componentsLookup = new SmartyStreets.USEnrichmentApi.Universal.Lookup();
38+
componentsLookup.SetDatasetName("property");
39+
componentsLookup.SetDataSubsetName("principal");
40+
componentsLookup.SetStreet("56 Union Ave");
41+
componentsLookup.SetCity("Somerville");
42+
componentsLookup.SetState("NJ");
43+
componentsLookup.SetZipcode("08876");
44+
45+
// Create a lookup with a single line address using the lines below
46+
var freeformLookup = new SmartyStreets.USEnrichmentApi.Universal.Lookup();
47+
freeformLookup.SetDatasetName("property");
48+
freeformLookup.SetDataSubsetName("principal");
49+
freeformLookup.SetFreeform("56 Union Ave Somerville NJ 08876");
50+
3351
// Options available for Lookup
34-
// lookup.SetEtag("GU4TINZRHA4TQMY");
52+
// lookup.SetEtag("AIDAIAQCAIEQKAIC");
3553
// lookup.SetIncludeFields("assessed_value,assessor_last_update"); // applicable to Property lookups only
3654
// lookup.SetExcludeFields("tax_fiscal_year,tax_jurisdiction"); // applicable to Property lookups only
3755

3856
try {
57+
// results = client.SendUniversalLookup("325023201", "property", "principal"); // simple call with just a SmartyKey and Dataset info
58+
59+
// Send a lookup using the line below
3960
results = client.SendUniversalLookup(lookup);
4061
}
4162
catch (NotModifiedException ex) {

src/sdk/USEnrichmentApi/Client.cs

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ public byte[] SendUniversalLookup(Universal.Lookup lookup)
8787

8888
private void Send(Lookup lookup)
8989
{
90-
if (lookup == null || string.IsNullOrEmpty(lookup.GetSmartyKey()))
91-
throw new SmartyStreets.SmartyException("Client.Send() requires a Lookup with the 'smartyKey' field set");
90+
if (lookup == null || (string.IsNullOrEmpty(lookup.GetSmartyKey()) && string.IsNullOrEmpty(lookup.GetStreet()) && string.IsNullOrEmpty(lookup.GetFreeform())))
91+
throw new SmartyStreets.SmartyException("Client.Send() requires a Lookup with the 'smartyKey', 'street', or 'freeform' field set");
9292
Request request = BuildRequest(lookup);
9393
Response response = this.sender.Send(request);
9494
foreach(var entry in response.HeaderInfo) {
@@ -98,6 +98,9 @@ private void Send(Lookup lookup)
9898
}
9999
if (response.Payload != null){
100100
using (var payloadStream = new MemoryStream(response.Payload)){
101+
if (serializer == null) {
102+
Console.WriteLine("true");
103+
}
101104
lookup.DeserializeAndSetResults(serializer, payloadStream);
102105
}
103106
}
@@ -108,10 +111,18 @@ private SmartyStreets.Request BuildRequest(Lookup lookup)
108111
SmartyStreets.Request request = new SmartyStreets.Request();
109112

110113
// some datasets have no data subset
111-
if (lookup.GetDataSubsetName() == "") {
112-
request.SetUrlComponents("/" + lookup.GetSmartyKey() + "/" + lookup.GetDatasetName());
114+
if (string.IsNullOrEmpty(lookup.GetSmartyKey())) {
115+
if (lookup.GetDataSubsetName() == "") {
116+
request.SetUrlComponents("/search/" + lookup.GetDatasetName());
117+
} else {
118+
request.SetUrlComponents("/search/" + lookup.GetDatasetName() + "/" + lookup.GetDataSubsetName());
119+
}
113120
} else {
121+
if (lookup.GetDataSubsetName() == "") {
122+
request.SetUrlComponents("/" + lookup.GetSmartyKey() + "/" + lookup.GetDatasetName());
123+
} else {
114124
request.SetUrlComponents("/" + lookup.GetSmartyKey() + "/" + lookup.GetDatasetName() + "/" + lookup.GetDataSubsetName());
125+
}
115126
}
116127

117128
if (lookup.GetIncludeFields() != null) {
@@ -120,7 +131,21 @@ private SmartyStreets.Request BuildRequest(Lookup lookup)
120131
if (lookup.GetExcludeFields() != null) {
121132
request.SetParameter("exclude", lookup.GetExcludeFields());
122133
}
123-
134+
if (lookup.GetFreeform() != null) {
135+
request.SetParameter("freeform", lookup.GetFreeform());
136+
}
137+
if (lookup.GetStreet() != null) {
138+
request.SetParameter("street", lookup.GetStreet());
139+
}
140+
if (lookup.GetCity() != null) {
141+
request.SetParameter("city", lookup.GetCity());
142+
}
143+
if (lookup.GetState() != null) {
144+
request.SetParameter("state", lookup.GetState());
145+
}
146+
if (lookup.GetZipcode() != null) {
147+
request.SetParameter("zipcode", lookup.GetZipcode());
148+
}
124149
if (lookup.GetEtag() != null) {
125150
request.SetHeader("Etag", lookup.GetEtag());
126151
}

src/sdk/USEnrichmentApi/GeoReference/Lookup.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public class Lookup : SmartyStreets.USEnrichmentApi.Lookup
88
{
99
private Result[] results;
1010

11-
public Lookup(string smartyKey) : base(smartyKey, "geo-reference", "")
11+
public Lookup(string smartyKey = null) : base(smartyKey, "geo-reference", "")
1212
{
1313
}
1414

@@ -25,7 +25,9 @@ public void SetResults(Result[] results)
2525
public override void DeserializeAndSetResults(SmartyStreets.ISerializer serializer, Stream payload)
2626
{
2727
this.results = serializer.Deserialize<Result[]>(payload);
28-
this.results[0].Etag = this.GetEtag();
28+
if (this.results != null) {
29+
this.results[0].Etag = this.GetEtag();
30+
}
2931
}
3032
}
3133
}

src/sdk/USEnrichmentApi/Lookup.cs

Lines changed: 80 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,29 @@ namespace SmartyStreets.USEnrichmentApi
55

66
public abstract class Lookup
77
{
8-
private readonly string smartyKey;
9-
private readonly string datasetName;
10-
private readonly string dataSubsetName;
8+
private string smartyKey;
9+
private string datasetName;
10+
private string dataSubsetName;
11+
private string freeform;
12+
private string street;
13+
private string city;
14+
private string state;
15+
private string zipcode;
1116
private string includeFields;
1217
private string excludeFields;
1318
private string eTag;
1419

15-
public Lookup(string smartyKey, string datasetName, string dataSubsetName)
20+
public Lookup(string smartyKey = null, string datasetName = null, string dataSubsetName = null, string freeform = null, string street = null,
21+
string city = null, string state = null, string zipcode = null)
1622
{
1723
this.smartyKey = smartyKey;
1824
this.datasetName = datasetName;
1925
this.dataSubsetName = dataSubsetName;
26+
this.freeform = freeform;
27+
this.street = street;
28+
this.city = city;
29+
this.state = state;
30+
this.zipcode = zipcode;
2031
}
2132

2233
public string GetSmartyKey()
@@ -34,6 +45,31 @@ public string GetDataSubsetName()
3445
return dataSubsetName;
3546
}
3647

48+
public string GetFreeform()
49+
{
50+
return freeform;
51+
}
52+
53+
public string GetStreet()
54+
{
55+
return street;
56+
}
57+
58+
public string GetCity()
59+
{
60+
return city;
61+
}
62+
63+
public string GetState()
64+
{
65+
return state;
66+
}
67+
68+
public string GetZipcode()
69+
{
70+
return zipcode;
71+
}
72+
3773
public string GetIncludeFields()
3874
{
3975
return includeFields;
@@ -64,6 +100,46 @@ public void SetEtag(string eTag)
64100
this.eTag = eTag;
65101
}
66102

103+
public void SetSmartyKey(string smartyKey)
104+
{
105+
this.smartyKey = smartyKey;
106+
}
107+
108+
public void SetDatasetName(string datasetName)
109+
{
110+
this.datasetName = datasetName;
111+
}
112+
113+
public void SetDataSubsetName(string dataSubsetName)
114+
{
115+
this.dataSubsetName = dataSubsetName;
116+
}
117+
118+
public void SetFreeform(string freeform)
119+
{
120+
this.freeform = freeform;
121+
}
122+
123+
public void SetStreet(string street)
124+
{
125+
this.street = street;
126+
}
127+
128+
public void SetCity(string city)
129+
{
130+
this.city = city;
131+
}
132+
133+
public void SetState(string state)
134+
{
135+
this.state = state;
136+
}
137+
138+
public void SetZipcode(string zipcode)
139+
{
140+
this.zipcode = zipcode;
141+
}
142+
67143
public abstract void DeserializeAndSetResults(SmartyStreets.ISerializer serializer, Stream payload);
68144
}
69145

0 commit comments

Comments
 (0)