-
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.
Showing
15 changed files
with
1,902 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,78 @@ | ||
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; | ||
|
||
internal static class USEnrichmentExample | ||
{ | ||
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(); | ||
|
||
SmartyStreets.USEnrichmentApi.Property.Principal.Result[] results = null; | ||
try { | ||
results = client.SendPropertyPrincipalLookup("1682393594"); | ||
} | ||
catch (Exception ex) { | ||
Console.WriteLine(ex.Message + ex.StackTrace); | ||
} | ||
|
||
if (results != null) { | ||
foreach (SmartyStreets.USEnrichmentApi.Property.Principal.Result result in results) { | ||
PrintResult(result); | ||
} | ||
} | ||
else { | ||
Console.WriteLine("Result was null"); | ||
} | ||
|
||
|
||
SmartyStreets.USEnrichmentApi.Property.Financial.Result[] financialResults = null; | ||
try { | ||
financialResults = client.SendPropertyFinancialLookup("1682393594"); | ||
} | ||
catch (Exception ex) { | ||
Console.WriteLine(ex.Message + ex.StackTrace); | ||
} | ||
|
||
if (financialResults != null) { | ||
foreach (SmartyStreets.USEnrichmentApi.Property.Financial.Result result in financialResults) { | ||
PrintResult(result); | ||
} | ||
} | ||
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 == "Attributes" ){ | ||
PrintResult(property.GetValue(obj, null)); | ||
} | ||
if (property.GetValue(obj, null) != null) { | ||
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
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,51 @@ | ||
namespace SmartyStreets.USEnrichmentApi | ||
{ | ||
using System; | ||
using System.IO; | ||
|
||
public class Client //: IUSEnrichmentClient | ||
{ | ||
private readonly ISender sender; | ||
private readonly ISerializer serializer; | ||
|
||
public Client(ISender sender, ISerializer serializer) | ||
{ | ||
this.sender = sender; | ||
this.serializer = serializer; | ||
} | ||
|
||
public Property.Financial.Result[] SendPropertyFinancialLookup(string smartyKey) | ||
{ | ||
Property.Financial.Lookup lookup = new Property.Financial.Lookup(smartyKey); | ||
Send(lookup); | ||
return lookup.GetResults(); | ||
} | ||
|
||
public Property.Principal.Result[] SendPropertyPrincipalLookup(string smartyKey) | ||
{ | ||
Property.Principal.Lookup lookup = new Property.Principal.Lookup(smartyKey); | ||
Send(lookup); | ||
return lookup.GetResults(); | ||
} | ||
|
||
private void Send(Lookup lookup) | ||
{ | ||
if (lookup == null || string.IsNullOrEmpty(lookup.GetSmartyKey())) | ||
throw new SmartyStreets.SmartyException("Client.Send() requires a Lookup with the 'smartyKey' field set"); | ||
Request request = BuildRequest(lookup); | ||
Response response = this.sender.Send(request); | ||
if (response.Payload != null){ | ||
using (var payloadStream = new MemoryStream(response.Payload)){ | ||
lookup.DeserializeAndSetResults(serializer, payloadStream); | ||
} | ||
} | ||
} | ||
|
||
private SmartyStreets.Request BuildRequest(Lookup lookup) | ||
{ | ||
SmartyStreets.Request request = new SmartyStreets.Request(); | ||
request.SetUrlPrefix("/" + lookup.GetSmartyKey() + "/" + lookup.GetDatasetName() + "/" + lookup.GetDataSubsetName()); | ||
return request; | ||
} | ||
} | ||
} |
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,9 @@ | ||
namespace SmartyStreets.USEnrichmentApi | ||
{ | ||
// marker interface for easy dependency injection and unit test mocking | ||
public interface IUSEnrichmentClient | ||
{ | ||
SmartyStreets.USEnrichmentApi.Property.Principal.Result[] sendPropertyPrincipalLookup(string smartyKey); | ||
SmartyStreets.USEnrichmentApi.Property.Financial.Result[] sendPropertyFinancialLookup(string smartyKey); | ||
} | ||
} |
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,36 @@ | ||
namespace SmartyStreets.USEnrichmentApi | ||
{ | ||
using System; | ||
using System.IO; | ||
|
||
public abstract class Lookup | ||
{ | ||
private readonly string smartyKey; | ||
private readonly string datasetName; | ||
private readonly 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(SmartyStreets.ISerializer serializer, Stream payload); | ||
} | ||
} |
Oops, something went wrong.