diff --git a/src/examples/Program.cs b/src/examples/Program.cs index 938b489..5b1be8e 100644 --- a/src/examples/Program.cs +++ b/src/examples/Program.cs @@ -16,6 +16,7 @@ private static void Main() USReverseGeoExample.Run(); USEnrichmentPropertyExample.Run(); USEnrichmentGeoReferenceExample.Run(); + USEnrichmentSecondaryExample.Run(); USEnrichmentUniversalExample.Run(); } } diff --git a/src/examples/USEnrichmentSecondaryExample.cs b/src/examples/USEnrichmentSecondaryExample.cs new file mode 100644 index 0000000..e2ff451 --- /dev/null +++ b/src/examples/USEnrichmentSecondaryExample.cs @@ -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)}"); + } + } + } + } +} diff --git a/src/sdk/USEnrichmentApi/Client.cs b/src/sdk/USEnrichmentApi/Client.cs index 69ffb83..f676fe7 100644 --- a/src/sdk/USEnrichmentApi/Client.cs +++ b/src/sdk/USEnrichmentApi/Client.cs @@ -53,6 +53,32 @@ public GeoReference.Result[] SendGeoReferenceLookup(GeoReference.Lookup lookup) return lookup.GetResults(); } + public Secondary.Result[] SendSecondaryLookup(string smartyKey) + { + Secondary.Lookup lookup = new Secondary.Lookup(smartyKey); + Send(lookup); + return lookup.GetResults(); + } + + public Secondary.Result[] SendSecondaryLookup(Secondary.Lookup lookup) + { + Send(lookup); + return lookup.GetResults(); + } + + public Secondary.Count.Result[] SendSecondaryCountLookup(string smartyKey) + { + Secondary.Count.Lookup lookup = new Secondary.Count.Lookup(smartyKey); + Send(lookup); + return lookup.GetResults(); + } + + public Secondary.Count.Result[] SendSecondaryCountLookup(Secondary.Count.Lookup lookup) + { + Send(lookup); + return lookup.GetResults(); + } + public byte[] SendUniversalLookup(Universal.Lookup lookup) { Send(lookup); diff --git a/src/sdk/USEnrichmentApi/Secondary/Aliases.cs b/src/sdk/USEnrichmentApi/Secondary/Aliases.cs new file mode 100644 index 0000000..237e1b0 --- /dev/null +++ b/src/sdk/USEnrichmentApi/Secondary/Aliases.cs @@ -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; } + } +} \ No newline at end of file diff --git a/src/sdk/USEnrichmentApi/Secondary/Count/Lookup.cs b/src/sdk/USEnrichmentApi/Secondary/Count/Lookup.cs new file mode 100644 index 0000000..a0972c7 --- /dev/null +++ b/src/sdk/USEnrichmentApi/Secondary/Count/Lookup.cs @@ -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(payload); + this.results[0].Etag = this.GetEtag(); + } + } +} \ No newline at end of file diff --git a/src/sdk/USEnrichmentApi/Secondary/Count/Result.cs b/src/sdk/USEnrichmentApi/Secondary/Count/Result.cs new file mode 100644 index 0000000..87a778b --- /dev/null +++ b/src/sdk/USEnrichmentApi/Secondary/Count/Result.cs @@ -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; } + } +} \ No newline at end of file diff --git a/src/sdk/USEnrichmentApi/Secondary/Lookup.cs b/src/sdk/USEnrichmentApi/Secondary/Lookup.cs new file mode 100644 index 0000000..5747834 --- /dev/null +++ b/src/sdk/USEnrichmentApi/Secondary/Lookup.cs @@ -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(payload); + this.results[0].Etag = this.GetEtag(); + } + } +} \ No newline at end of file diff --git a/src/sdk/USEnrichmentApi/Secondary/Result.cs b/src/sdk/USEnrichmentApi/Secondary/Result.cs new file mode 100644 index 0000000..1b730b7 --- /dev/null +++ b/src/sdk/USEnrichmentApi/Secondary/Result.cs @@ -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; } + } +} \ No newline at end of file diff --git a/src/sdk/USEnrichmentApi/Secondary/RootAddress.cs b/src/sdk/USEnrichmentApi/Secondary/RootAddress.cs new file mode 100644 index 0000000..5e01333 --- /dev/null +++ b/src/sdk/USEnrichmentApi/Secondary/RootAddress.cs @@ -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; } + } +} \ No newline at end of file diff --git a/src/sdk/USEnrichmentApi/Secondary/Secondaries.cs b/src/sdk/USEnrichmentApi/Secondary/Secondaries.cs new file mode 100644 index 0000000..71e0ae2 --- /dev/null +++ b/src/sdk/USEnrichmentApi/Secondary/Secondaries.cs @@ -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; } + } +} \ No newline at end of file