From 9edffc365292802e35c62b424aefdc01e6db2197 Mon Sep 17 00:00:00 2001 From: smartyeric Date: Mon, 12 Aug 2024 22:02:26 +0000 Subject: [PATCH 1/4] Added Secondary Enpoint and Secondary Count Endpoint --- src/examples/Program.cs | 1 + src/examples/USEnrichmentSecondaryExample.cs | 116 ++++++++++++++++++ src/sdk/USEnrichmentApi/Client.cs | 26 ++++ src/sdk/USEnrichmentApi/Secondary/Aliases.cs | 38 ++++++ .../USEnrichmentApi/Secondary/Count/Lookup.cs | 31 +++++ .../USEnrichmentApi/Secondary/Count/Result.cs | 17 +++ src/sdk/USEnrichmentApi/Secondary/Lookup.cs | 31 +++++ src/sdk/USEnrichmentApi/Secondary/Result.cs | 23 ++++ .../USEnrichmentApi/Secondary/RootAddress.cs | 41 +++++++ .../USEnrichmentApi/Secondary/Secondaries.cs | 20 +++ 10 files changed, 344 insertions(+) create mode 100644 src/examples/USEnrichmentSecondaryExample.cs create mode 100644 src/sdk/USEnrichmentApi/Secondary/Aliases.cs create mode 100644 src/sdk/USEnrichmentApi/Secondary/Count/Lookup.cs create mode 100644 src/sdk/USEnrichmentApi/Secondary/Count/Result.cs create mode 100644 src/sdk/USEnrichmentApi/Secondary/Lookup.cs create mode 100644 src/sdk/USEnrichmentApi/Secondary/Result.cs create mode 100644 src/sdk/USEnrichmentApi/Secondary/RootAddress.cs create mode 100644 src/sdk/USEnrichmentApi/Secondary/Secondaries.cs 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..f870756 --- /dev/null +++ b/src/examples/USEnrichmentSecondaryExample.cs @@ -0,0 +1,116 @@ +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 != null) { + foreach (SmartyStreets.USEnrichmentApi.Secondary.Result result in results) { + PrintResult(result); + if (result.Aliases != null) { + Console.WriteLine("Aliases: {"); + foreach (SmartyStreets.USEnrichmentApi.Secondary.Aliases alias in result.Aliases) { + PrintResult(alias); + if (indexOf(result.Aliases, alias)) { + + } + Console.WriteLine(); + } + Console.WriteLine("}\n"); + } + Console.WriteLine("Secondaries: {"); + foreach (SmartyStreets.USEnrichmentApi.Secondary.Secondaries secondary in result.Secondaries) { + PrintResult(secondary); + if () + 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 != 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) != null && property.Name != "Aliases" && property.Name != "Secondaries") { + Console.WriteLine($"{property.Name}: {property.GetValue(obj, null)}"); + } + } + } + } +} \ No newline at end of file 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 From 339e120a76025e7555daf19e2f4076ac9d14721a Mon Sep 17 00:00:00 2001 From: Eric Devenport Date: Tue, 13 Aug 2024 10:37:41 -0600 Subject: [PATCH 2/4] Updated Secondary Endpoint example for readability --- src/examples/USEnrichmentSecondaryExample.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/examples/USEnrichmentSecondaryExample.cs b/src/examples/USEnrichmentSecondaryExample.cs index f870756..07fdc5e 100644 --- a/src/examples/USEnrichmentSecondaryExample.cs +++ b/src/examples/USEnrichmentSecondaryExample.cs @@ -43,7 +43,7 @@ public static void Run() Console.WriteLine(ex.Message + ex.StackTrace); } - if (results != null) { + if (results is not null) { foreach (SmartyStreets.USEnrichmentApi.Secondary.Result result in results) { PrintResult(result); if (result.Aliases != null) { @@ -60,7 +60,6 @@ public static void Run() Console.WriteLine("Secondaries: {"); foreach (SmartyStreets.USEnrichmentApi.Secondary.Secondaries secondary in result.Secondaries) { PrintResult(secondary); - if () Console.WriteLine(); } Console.WriteLine("}\n"); @@ -113,4 +112,4 @@ private static void PrintResult(object obj){ } } } -} \ No newline at end of file +} From b4bb8244b24799473bb176a1c60d3c67a3389304 Mon Sep 17 00:00:00 2001 From: Eric Devenport Date: Tue, 13 Aug 2024 11:58:17 -0600 Subject: [PATCH 3/4] Removed Development Artifact --- src/examples/USEnrichmentSecondaryExample.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/examples/USEnrichmentSecondaryExample.cs b/src/examples/USEnrichmentSecondaryExample.cs index 07fdc5e..acb0f5b 100644 --- a/src/examples/USEnrichmentSecondaryExample.cs +++ b/src/examples/USEnrichmentSecondaryExample.cs @@ -50,9 +50,6 @@ public static void Run() Console.WriteLine("Aliases: {"); foreach (SmartyStreets.USEnrichmentApi.Secondary.Aliases alias in result.Aliases) { PrintResult(alias); - if (indexOf(result.Aliases, alias)) { - - } Console.WriteLine(); } Console.WriteLine("}\n"); From 5ee1f13418d78c2332a3164605b25bebbaa66abc Mon Sep 17 00:00:00 2001 From: Eric Devenport Date: Tue, 13 Aug 2024 12:24:20 -0600 Subject: [PATCH 4/4] Enhanced readability in Secondary Example --- src/examples/USEnrichmentSecondaryExample.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/examples/USEnrichmentSecondaryExample.cs b/src/examples/USEnrichmentSecondaryExample.cs index acb0f5b..e2ff451 100644 --- a/src/examples/USEnrichmentSecondaryExample.cs +++ b/src/examples/USEnrichmentSecondaryExample.cs @@ -46,7 +46,7 @@ public static void Run() if (results is not null) { foreach (SmartyStreets.USEnrichmentApi.Secondary.Result result in results) { PrintResult(result); - if (result.Aliases != null) { + if (result.Aliases is not null) { Console.WriteLine("Aliases: {"); foreach (SmartyStreets.USEnrichmentApi.Secondary.Aliases alias in result.Aliases) { PrintResult(alias); @@ -81,7 +81,7 @@ public static void Run() Console.WriteLine(ex.Message + ex.StackTrace); } - if (countResults != null) { + if (countResults is not null) { Console.WriteLine("Count: {"); foreach (SmartyStreets.USEnrichmentApi.Secondary.Count.Result result in countResults) { PrintResult(result); @@ -103,7 +103,7 @@ private static void PrintResult(object obj){ PrintResult(property.GetValue(obj, null)); Console.WriteLine("}\n"); } - else if (property.GetValue(obj, null) != null && property.Name != "Aliases" && property.Name != "Secondaries") { + else if (property.GetValue(obj, null) is not null && property.Name != "Aliases" && property.Name != "Secondaries") { Console.WriteLine($"{property.Name}: {property.GetValue(obj, null)}"); } }