Skip to content

Commit

Permalink
Merge branch 'master' into eric/add-custom-parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
smartyeric authored Nov 5, 2024
2 parents 118f620 + 157d785 commit 5df0877
Show file tree
Hide file tree
Showing 10 changed files with 161 additions and 17 deletions.
29 changes: 26 additions & 3 deletions src/examples/InternationalAutocompleteExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ namespace Examples
{
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using SmartyStreets;
using SmartyStreets.InternationalAutocompleteApi;
Expand Down Expand Up @@ -37,10 +39,31 @@ public static void Run()
//uncomment the line below to add a custom parameter
//lookup.AddCustomParameter("max_results", "3");

client.Send(lookup);
try
{
client.Send(lookup);
}
catch (SmartyException ex)
{
Console.WriteLine(ex.Message);
Console.WriteLine(ex.StackTrace);
return;
}
catch (IOException ex)
{
Console.WriteLine(ex.StackTrace);
return;
}

var candidates = lookup.Result;
Console.WriteLine();
var candidates = lookup.Result;

if (candidates == null)
{
Console.WriteLine("No candidates. This means the address is not valid.");
return;
}

Console.WriteLine();
Console.WriteLine("*** Results ***");
foreach (var candidate in candidates)
{
Expand Down
28 changes: 25 additions & 3 deletions src/examples/InternationalStreetExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using SmartyStreets;
using SmartyStreets.InternationalStreetApi;
Expand Down Expand Up @@ -44,10 +45,31 @@ public static void Run()
//uncomment the line below to add a custom parameter
//lookup.AddCustomParameter("input_id", "ID-8675309");

client.Send(lookup);
try
{
client.Send(lookup);
}
catch (SmartyException ex)
{
Console.WriteLine(ex.Message);
Console.WriteLine(ex.StackTrace);
return;
}
catch (IOException ex)
{
Console.WriteLine(ex.StackTrace);
return;
}

var candidates = lookup.Result;
var firstCandidate = candidates[0];
var candidates = lookup.Result;

if (candidates.Count == 0)
{
Console.WriteLine("No candidates. This means the address is not valid.");
return;
}

var firstCandidate = candidates[0];
Console.WriteLine("Input ID: " + firstCandidate.InputId);
Console.WriteLine("Address is " + firstCandidate.Analysis.VerificationStatus);
Console.WriteLine("Address precision: " + firstCandidate.Analysis.AddressPrecision + "\n");
Expand Down
54 changes: 49 additions & 5 deletions src/examples/USAutocompleteProExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
{
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using SmartyStreets;
using SmartyStreets.USAutocompleteProApi;
Expand Down Expand Up @@ -32,9 +34,31 @@ public static void Run()
var lookup = new Lookup("1042 W Center");
lookup.PreferGeolocation = "none";

client.Send(lookup);
try
{
client.Send(lookup);
}
catch (SmartyException ex)
{
Console.WriteLine(ex.Message);
Console.WriteLine(ex.StackTrace);
return;
}
catch (IOException ex)
{
Console.WriteLine(ex.StackTrace);
return;
}

Console.WriteLine("*** Result with no filter ***");
var suggestions = lookup.Result;

if (suggestions == null)
{
Console.WriteLine("No suggestions.");
return;
}

Console.WriteLine("*** Result with no filter ***");
Console.WriteLine();
foreach (var suggestion in lookup.Result)
Console.WriteLine(suggestion.Street, suggestion.City, ", ", suggestion.State);
Expand All @@ -57,11 +81,31 @@ public static void Run()
//uncomment the below line to add a custom parameter
//lookup.AddCustomParameter("source", "all");

client.Send(lookup);
try
{
client.Send(lookup);
}
catch (SmartyException ex)
{
Console.WriteLine(ex.Message);
Console.WriteLine(ex.StackTrace);
//return;
}
catch (IOException ex)
{
Console.WriteLine(ex.StackTrace);
return;
}

var suggestions = lookup.Result;
suggestions = lookup.Result;

Console.WriteLine();
if (suggestions == null)
{
Console.WriteLine("No suggestions.");
return;
}

Console.WriteLine();
Console.WriteLine("*** Result with some filters ***");
foreach (var suggestion in suggestions)
Console.WriteLine(suggestion.Street + " " + suggestion.City + ", " + suggestion.State);
Expand Down
28 changes: 25 additions & 3 deletions src/examples/USExtractExample.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace Examples
{
using System;
using System.IO;
using System.Net;
using SmartyStreets;
using SmartyStreets.USExtractApi;
Expand Down Expand Up @@ -34,11 +35,32 @@ public static void Run()

//uncomment the line below to add a custom parameter
//lookup.AddCustomParameter("addr_line_breaks", "false");

client.Send(lookup);

try
{
client.Send(lookup);
}
catch (SmartyException ex)
{
Console.WriteLine(ex.Message);
Console.WriteLine(ex.StackTrace);
return;
}
catch (IOException ex)
{
Console.WriteLine(ex.StackTrace);
return;
}

var result = lookup.Result;
var metadata = result.Metadata;

if (result.Metadata == null)
{
Console.WriteLine("No candidates. This means the address is not valid.");
return;
}

var metadata = result.Metadata;
Console.WriteLine("Found " + metadata.AddressCount + " addresses.");
Console.WriteLine(metadata.VerifiedCount + " of them were valid.");
Console.WriteLine();
Expand Down
8 changes: 8 additions & 0 deletions src/examples/USReverseGeoExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,18 @@ public static void Run()
{
Console.WriteLine(ex.Message);
Console.WriteLine(ex.StackTrace);
return;
}
catch (IOException ex)
{
Console.WriteLine(ex.StackTrace);
return;
}

if (lookup.SmartyResponse == null)
{
Console.WriteLine("No candidates.");
return;
}

var results = lookup.SmartyResponse.Results;
Expand Down
3 changes: 3 additions & 0 deletions src/examples/USStreetLookupsWithMatchStrategyExamples.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,18 @@ public static void Run()
catch (BatchFullException)
{
Console.WriteLine("Error. The batch is already full.");
return;
}
catch (SmartyException ex)
{
Console.WriteLine(ex.Message);
Console.WriteLine(ex.StackTrace);
return;
}
catch (IOException ex)
{
Console.WriteLine(ex.StackTrace);
return;
}

for (var i = 0; i < batch.Count; i++)
Expand Down
3 changes: 3 additions & 0 deletions src/examples/USStreetMultipleAddressesExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,18 @@ public static void Run()
catch (BatchFullException)
{
Console.WriteLine("Error. The batch is already full.");
return;
}
catch (SmartyException ex)
{
Console.WriteLine(ex.Message);
Console.WriteLine(ex.StackTrace);
return;
}
catch (IOException ex)
{
Console.WriteLine(ex.StackTrace);
return;
}

for (var i = 0; i < batch.Count; i++)
Expand Down
2 changes: 2 additions & 0 deletions src/examples/USStreetSingleAddressExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,12 @@ public static void Run()
{
Console.WriteLine(ex.Message);
Console.WriteLine(ex.StackTrace);
return;
}
catch (IOException ex)
{
Console.WriteLine(ex.StackTrace);
return;
}

var candidates = lookup.Result;
Expand Down
16 changes: 13 additions & 3 deletions src/examples/USZipCodeMultipleLookupsExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,18 @@ public static void Run()
catch (BatchFullException)
{
Console.WriteLine("Error. The batch is already full.");
return;
}
catch (SmartyException ex)
{
Console.WriteLine(ex.Message);
Console.WriteLine(ex.StackTrace);
return;
}
catch (IOException ex)
{
Console.WriteLine(ex.StackTrace);
return;
}

for (var i = 0; i < batch.Count; i++)
Expand All @@ -79,8 +82,16 @@ public static void Run()

Console.WriteLine("Input ID: " + result.InputId);

var cityStates = result.CityStates;
Console.WriteLine(cityStates.Length + " City and State match" + (cityStates.Length == 1 ? ":" : "es:"));
var cityStates = result.CityStates;
var zipCodes = result.ZipCodes;

if (cityStates == null || zipCodes == null)
{
Console.WriteLine("Lookup " + i + " is invalid.\n");
continue;
}

Console.WriteLine(cityStates.Length + " City and State match" + (cityStates.Length == 1 ? ":" : "es:"));

foreach (var cityState in cityStates)
{
Expand All @@ -90,7 +101,6 @@ public static void Run()
Console.WriteLine();
}

var zipCodes = result.ZipCodes;
Console.WriteLine(zipCodes.Length + " ZIP Code match" + (cityStates.Length == 1 ? ":" : "es:"));

foreach (var zipCode in zipCodes)
Expand Down
7 changes: 7 additions & 0 deletions src/examples/USZipCodeSingleLookupExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,23 @@ public static void Run()
{
Console.WriteLine(ex.Message);
Console.WriteLine(ex.StackTrace);
return;
}
catch (IOException ex)
{
Console.WriteLine(ex.StackTrace);
return;
}

var result = lookup.Result;
var cities = result.CityStates;
var zipCodes = result.ZipCodes;

if (cities == null || zipCodes == null) {
Console.WriteLine("No results.");
return;
}

Console.WriteLine("Input ID: " + result.InputId);

foreach (var city in cities)
Expand Down

0 comments on commit 5df0877

Please sign in to comment.