-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from smartystreets/eric/add-secondary-endpoint
Added Secondary Endpoint and Secondary Count Endpoint
- Loading branch information
Showing
10 changed files
with
340 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
namespace Examples | ||
{ | ||
using System; | ||
using System.Net; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using SmartyStreets; | ||
using SmartyStreets.USEnrichmentApi; | ||
using System.Reflection; | ||
using System.Text; | ||
|
||
internal static class USEnrichmentSecondaryExample | ||
{ | ||
public static void Run() | ||
{ | ||
// specifies the TLS protocoll to use - this is TLS 1.2 | ||
const SecurityProtocolType tlsProtocol1_2 = (SecurityProtocolType)3072; | ||
|
||
// var authId = "Your SmartyStreets Auth ID here"; | ||
// var authToken = "Your SmartyStreets Auth Token here"; | ||
|
||
// We recommend storing your keys in environment variables instead---it's safer! | ||
var authId = Environment.GetEnvironmentVariable("SMARTY_AUTH_ID"); | ||
var authToken = Environment.GetEnvironmentVariable("SMARTY_AUTH_TOKEN"); | ||
ServicePointManager.SecurityProtocol = tlsProtocol1_2; | ||
|
||
var client = new ClientBuilder(authId, authToken).BuildUsEnrichmentApiClient(); | ||
|
||
// 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 | ||
SmartyStreets.USEnrichmentApi.Secondary.Result[] results = null; | ||
var lookup = new SmartyStreets.USEnrichmentApi.Secondary.Lookup("325023201"); | ||
// Options available for Lookup | ||
// lookup.SetEtag("HAYDKMJXHA4DKNA"); | ||
|
||
try { | ||
results = client.SendSecondaryLookup(lookup); | ||
} | ||
catch (NotModifiedException ex) { | ||
Console.WriteLine(ex.Message); // The Etag value provided represents the latest version of the requested record | ||
} | ||
catch (Exception ex) { | ||
Console.WriteLine(ex.Message + ex.StackTrace); | ||
} | ||
|
||
if (results is not null) { | ||
foreach (SmartyStreets.USEnrichmentApi.Secondary.Result result in results) { | ||
PrintResult(result); | ||
if (result.Aliases is not null) { | ||
Console.WriteLine("Aliases: {"); | ||
foreach (SmartyStreets.USEnrichmentApi.Secondary.Aliases alias in result.Aliases) { | ||
PrintResult(alias); | ||
Console.WriteLine(); | ||
} | ||
Console.WriteLine("}\n"); | ||
} | ||
Console.WriteLine("Secondaries: {"); | ||
foreach (SmartyStreets.USEnrichmentApi.Secondary.Secondaries secondary in result.Secondaries) { | ||
PrintResult(secondary); | ||
Console.WriteLine(); | ||
} | ||
Console.WriteLine("}\n"); | ||
} | ||
} | ||
else { | ||
Console.WriteLine("Result was null"); | ||
} | ||
|
||
SmartyStreets.USEnrichmentApi.Secondary.Count.Result[] countResults = null; | ||
var countLookup = new SmartyStreets.USEnrichmentApi.Secondary.Count.Lookup("325023201"); | ||
// Options available for Lookup | ||
// lookup.SetEtag("HAYDKMJXHA4DKNA"); | ||
|
||
try { | ||
countResults = client.SendSecondaryCountLookup(countLookup); | ||
} | ||
catch (NotModifiedException ex) { | ||
Console.WriteLine(ex.Message); // The Etag value provided represents the latest version of the requested record | ||
} | ||
catch (Exception ex) { | ||
Console.WriteLine(ex.Message + ex.StackTrace); | ||
} | ||
|
||
if (countResults is not null) { | ||
Console.WriteLine("Count: {"); | ||
foreach (SmartyStreets.USEnrichmentApi.Secondary.Count.Result result in countResults) { | ||
PrintResult(result); | ||
} | ||
Console.WriteLine("}"); | ||
} | ||
else { | ||
Console.WriteLine("Result was null"); | ||
} | ||
} | ||
|
||
|
||
private static void PrintResult(object obj){ | ||
Type type = obj.GetType(); | ||
|
||
foreach (PropertyInfo property in type.GetProperties()) { | ||
if (property.Name == "RootAddress") { | ||
Console.WriteLine("Root Address: {"); | ||
PrintResult(property.GetValue(obj, null)); | ||
Console.WriteLine("}\n"); | ||
} | ||
else if (property.GetValue(obj, null) is not null && property.Name != "Aliases" && property.Name != "Secondaries") { | ||
Console.WriteLine($"{property.Name}: {property.GetValue(obj, null)}"); | ||
} | ||
} | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
namespace SmartyStreets.USEnrichmentApi.Secondary | ||
{ | ||
using System.Runtime.Serialization; | ||
|
||
[DataContract] | ||
public class Aliases | ||
{ | ||
[DataMember(Name = "smarty_key")] | ||
public string SmartyKey { get; set; } | ||
|
||
[DataMember(Name = "primary_number")] | ||
public string PrimaryNumber { get; set; } | ||
|
||
[DataMember(Name = "street_predirection")] | ||
public string StreetPredirection { get; set; } | ||
|
||
[DataMember(Name = "street_name")] | ||
public string StreetName { get; set; } | ||
|
||
[DataMember(Name = "street_suffix")] | ||
public string StreetSuffix { get; set; } | ||
|
||
[DataMember(Name = "street_postdirection")] | ||
public string StreetPostdirection { get; set; } | ||
|
||
[DataMember(Name = "city_name")] | ||
public string CityName { get; set; } | ||
|
||
[DataMember(Name = "state_abbreviation")] | ||
public string StateAbbreviation { get; set; } | ||
|
||
[DataMember(Name = "zipcode")] | ||
public string Zipcode { get; set; } | ||
|
||
[DataMember(Name = "plus4_code")] | ||
public string Plus4Code { get; set; } | ||
} | ||
} |
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,31 @@ | ||
namespace SmartyStreets.USEnrichmentApi.Secondary.Count | ||
{ | ||
using System; | ||
using System.IO; | ||
using SmartyStreets.USEnrichmentApi.Secondary; | ||
|
||
public class Lookup : SmartyStreets.USEnrichmentApi.Lookup | ||
{ | ||
private Result[] results; | ||
|
||
public Lookup(string smartyKey) : base(smartyKey, "secondary", "count") | ||
{ | ||
} | ||
|
||
public Result[] GetResults() | ||
{ | ||
return results; | ||
} | ||
|
||
public void SetResults(Result[] results) | ||
{ | ||
this.results = results; | ||
} | ||
|
||
public override void DeserializeAndSetResults(SmartyStreets.ISerializer serializer, Stream payload) | ||
{ | ||
this.results = serializer.Deserialize<Result[]>(payload); | ||
this.results[0].Etag = this.GetEtag(); | ||
} | ||
} | ||
} |
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,17 @@ | ||
namespace SmartyStreets.USEnrichmentApi.Secondary.Count | ||
{ | ||
using System.Runtime.Serialization; | ||
|
||
[DataContract] | ||
public class Result | ||
{ | ||
[DataMember(Name = "smarty_key")] | ||
public string SmartyKey { get; set; } | ||
|
||
[DataMember(Name = "etag")] | ||
public string Etag { get; set; } | ||
|
||
[DataMember(Name = "count")] | ||
public string count { get; set; } | ||
} | ||
} |
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,31 @@ | ||
namespace SmartyStreets.USEnrichmentApi.Secondary | ||
{ | ||
using System; | ||
using System.IO; | ||
using SmartyStreets.USEnrichmentApi.Secondary; | ||
|
||
public class Lookup : SmartyStreets.USEnrichmentApi.Lookup | ||
{ | ||
private Result[] results; | ||
|
||
public Lookup(string smartyKey) : base(smartyKey, "secondary", "") | ||
{ | ||
} | ||
|
||
public Result[] GetResults() | ||
{ | ||
return results; | ||
} | ||
|
||
public void SetResults(Result[] results) | ||
{ | ||
this.results = results; | ||
} | ||
|
||
public override void DeserializeAndSetResults(SmartyStreets.ISerializer serializer, Stream payload) | ||
{ | ||
this.results = serializer.Deserialize<Result[]>(payload); | ||
this.results[0].Etag = this.GetEtag(); | ||
} | ||
} | ||
} |
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,23 @@ | ||
namespace SmartyStreets.USEnrichmentApi.Secondary | ||
{ | ||
using System.Runtime.Serialization; | ||
|
||
[DataContract] | ||
public class Result | ||
{ | ||
[DataMember(Name = "smarty_key")] | ||
public string SmartyKey { get; set; } | ||
|
||
[DataMember(Name = "etag")] | ||
public string Etag { get; set; } | ||
|
||
[DataMember(Name = "root_address")] | ||
public RootAddress RootAddress { get; set; } | ||
|
||
[DataMember(Name = "aliases")] | ||
public Aliases[] Aliases { get; set; } | ||
|
||
[DataMember(Name = "secondaries")] | ||
public Secondaries[] Secondaries { get; set; } | ||
} | ||
} |
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,41 @@ | ||
namespace SmartyStreets.USEnrichmentApi.Secondary | ||
{ | ||
using System.Runtime.Serialization; | ||
|
||
[DataContract] | ||
public class RootAddress | ||
{ | ||
[DataMember(Name = "secondary_count")] | ||
public string SecondaryCount { get; set; } | ||
|
||
[DataMember(Name = "smarty_key")] | ||
public string SmartyKey { get; set; } | ||
|
||
[DataMember(Name = "primary_number")] | ||
public string PrimaryNumber { get; set; } | ||
|
||
[DataMember(Name = "street_predirection")] | ||
public string StreetPredirection { get; set; } | ||
|
||
[DataMember(Name = "street_name")] | ||
public string StreetName { get; set; } | ||
|
||
[DataMember(Name = "street_suffix")] | ||
public string StreetSuffix { get; set; } | ||
|
||
[DataMember(Name = "street_postdirection")] | ||
public string StreetPostdirection { get; set; } | ||
|
||
[DataMember(Name = "city_name")] | ||
public string CityName { get; set; } | ||
|
||
[DataMember(Name = "state_abbreviation")] | ||
public string StateAbbreviation { get; set; } | ||
|
||
[DataMember(Name = "zipcode")] | ||
public string Zipcode { get; set; } | ||
|
||
[DataMember(Name = "plus4_code")] | ||
public string Plus4Code { get; set; } | ||
} | ||
} |
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,20 @@ | ||
namespace SmartyStreets.USEnrichmentApi.Secondary | ||
{ | ||
using System.Runtime.Serialization; | ||
|
||
[DataContract] | ||
public class Secondaries | ||
{ | ||
[DataMember(Name = "smarty_key")] | ||
public string SmartyKey { get; set; } | ||
|
||
[DataMember(Name = "secondary_designator")] | ||
public string SecondaryDesignator { get; set; } | ||
|
||
[DataMember(Name = "secondary_number")] | ||
public string SecondaryNumber { get; set; } | ||
|
||
[DataMember(Name = "plus4_code")] | ||
public string Plus4Code { get; set; } | ||
} | ||
} |