Skip to content

Commit efbff4e

Browse files
authored
Merge pull request #54 from fredashiii/master
Migrate from HttpWebRequest to HttpClient (and remove net40 as a target framework). Add a WithDebug mode to ClientBuilder.
2 parents 32edbd6 + 83410ca commit efbff4e

File tree

59 files changed

+830
-403
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+830
-403
lines changed

src/examples/InternationalAutocompleteExample.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
namespace Examples
22
{
33
using System;
4-
using System.Collections.Generic;
54
using System.IO;
6-
using System.Linq;
75
using System.Net;
86
using SmartyStreets;
97
using SmartyStreets.InternationalAutocompleteApi;
@@ -20,7 +18,7 @@ public static void Run()
2018
var authToken = Environment.GetEnvironmentVariable("SMARTY_AUTH_TOKEN");
2119
ServicePointManager.SecurityProtocol = tlsProtocol1_2;
2220

23-
var client = new ClientBuilder(authId, authToken).BuildInternationalAutocompleteApiClient();
21+
using var client = new ClientBuilder(authId, authToken).BuildInternationalAutocompleteApiClient();
2422

2523
// Documentation for input fields can be found at:
2624
// https://smartystreetscom/docs/cloud/international-street-api#http-input-fields
@@ -36,8 +34,8 @@ public static void Run()
3634
//lookup.AddCustomParameter("max_results", "3");
3735

3836
try
39-
{
40-
client.Send(lookup);
37+
{
38+
client.Send(lookup);
4139
}
4240
catch (SmartyException ex)
4341
{

src/examples/InternationalStreetExample.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
namespace Examples
22
{
33
using System;
4-
using System.Collections.Generic;
54
using System.IO;
65
using System.Net;
76
using SmartyStreets;
@@ -19,7 +18,7 @@ public static void Run()
1918
var authToken = Environment.GetEnvironmentVariable("SMARTY_AUTH_TOKEN");
2019
ServicePointManager.SecurityProtocol = tlsProtocol1_2;
2120

22-
var client = new ClientBuilder(authId, authToken).BuildInternationalStreetApiClient();
21+
using var client = new ClientBuilder(authId, authToken).BuildInternationalStreetApiClient();
2322

2423
// Documentation for input fields can be found at:
2524
// https://smartystreetscom/docs/cloud/international-street-api#http-input-fields
@@ -43,7 +42,7 @@ public static void Run()
4342

4443
try
4544
{
46-
client.Send(lookup);
45+
client.Send(lookup);
4746
}
4847
catch (SmartyException ex)
4948
{

src/examples/Program.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
namespace Examples
1+
using System.Threading.Tasks;
2+
3+
namespace Examples
24
{
35
internal static class Program
46
{
@@ -48,8 +50,6 @@ private static void Main(string[] args)
4850
USEnrichmentSecondaryExample.Run();
4951
USEnrichmentUniversalExample.Run();
5052
break;
51-
default:
52-
break;
5353
}
5454
}
5555
}

src/examples/USAutocompleteProExample.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
namespace Examples
22
{
33
using System;
4-
using System.Collections.Generic;
54
using System.IO;
6-
using System.Linq;
75
using System.Net;
86
using SmartyStreets;
97
using SmartyStreets.USAutocompleteProApi;
@@ -12,6 +10,7 @@ internal static class USAutocompleteProExample
1210
{
1311
public static void Run()
1412
{
13+
1514
// specifies the TLS protocoll to use - this is TLS 1.2
1615
const SecurityProtocolType tlsProtocol1_2 = (SecurityProtocolType)3072;
1716

@@ -25,14 +24,14 @@ public static void Run()
2524
var credentials = new StaticCredentials(id, token);
2625
ServicePointManager.SecurityProtocol = tlsProtocol1_2;
2726

28-
var client = new ClientBuilder(credentials).BuildUsAutocompleteProApiClient();
27+
using var client = new ClientBuilder(credentials).BuildUsAutocompleteProApiClient();
2928

3029
var lookup = new Lookup("1042 W Center");
3130
lookup.PreferGeolocation = "none";
3231

3332
try
34-
{
35-
client.Send(lookup);
33+
{
34+
client.Send(lookup);
3635
}
3736
catch (SmartyException ex)
3837
{

src/examples/USEnrichmentGeoReferenceExample.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,11 @@ namespace Examples
22
{
33
using System;
44
using System.Net;
5-
using System.Collections.Generic;
6-
using System.IO;
7-
using System.Linq;
85
using SmartyStreets;
9-
using SmartyStreets.USEnrichmentApi;
106
using System.Reflection;
7+
using System.Threading.Tasks;
118

12-
internal static class USEnrichmentGeoReferenceExample
9+
internal static class USEnrichmentGeoReferenceExample
1310
{
1411
public static void Run()
1512
{
@@ -24,11 +21,10 @@ public static void Run()
2421
var authToken = Environment.GetEnvironmentVariable("SMARTY_AUTH_TOKEN");
2522
ServicePointManager.SecurityProtocol = tlsProtocol1_2;
2623

27-
var client = new ClientBuilder(authId, authToken).BuildUsEnrichmentApiClient();
24+
using var client = new ClientBuilder(authId, authToken).BuildUsEnrichmentApiClient();
2825

2926
SmartyStreets.USEnrichmentApi.GeoReference.Result[] results = null;
3027

31-
3228
// Create a lookup with a smarty key using the line below
3329
var lookup = new SmartyStreets.USEnrichmentApi.GeoReference.Lookup("325023201");
3430

src/examples/USEnrichmentPropertyExample.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,10 @@ namespace Examples
22
{
33
using System;
44
using System.Net;
5-
using System.Collections.Generic;
6-
using System.IO;
7-
using System.Linq;
85
using SmartyStreets;
9-
using SmartyStreets.USEnrichmentApi;
106
using System.Reflection;
117

12-
internal static class USEnrichmentPropertyExample
8+
internal static class USEnrichmentPropertyExample
139
{
1410
public static void Run()
1511
{
@@ -24,7 +20,7 @@ public static void Run()
2420
var authToken = Environment.GetEnvironmentVariable("SMARTY_AUTH_TOKEN");
2521
ServicePointManager.SecurityProtocol = tlsProtocol1_2;
2622

27-
var client = new ClientBuilder(authId, authToken).BuildUsEnrichmentApiClient();
23+
using var client = new ClientBuilder(authId, authToken).BuildUsEnrichmentApiClient();
2824

2925

3026
SmartyStreets.USEnrichmentApi.Property.Principal.Result[] results = null;

src/examples/USEnrichmentSecondaryExample.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,11 @@ namespace Examples
22
{
33
using System;
44
using System.Net;
5-
using System.Collections.Generic;
6-
using System.IO;
7-
using System.Linq;
85
using SmartyStreets;
9-
using SmartyStreets.USEnrichmentApi;
106
using System.Reflection;
11-
using System.Text;
7+
using System.Threading.Tasks;
128

13-
internal static class USEnrichmentSecondaryExample
9+
internal static class USEnrichmentSecondaryExample
1410
{
1511
public static void Run()
1612
{
@@ -25,7 +21,7 @@ public static void Run()
2521
var authToken = Environment.GetEnvironmentVariable("SMARTY_AUTH_TOKEN");
2622
ServicePointManager.SecurityProtocol = tlsProtocol1_2;
2723

28-
var client = new ClientBuilder(authId, authToken).BuildUsEnrichmentApiClient();
24+
using var client = new ClientBuilder(authId, authToken).BuildUsEnrichmentApiClient();
2925

3026
// 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
3127
SmartyStreets.USEnrichmentApi.Secondary.Result[] results = null;

src/examples/USEnrichmentUniversalExample.cs

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,14 @@ namespace Examples
22
{
33
using System;
44
using System.Net;
5-
using System.Collections.Generic;
6-
using System.IO;
7-
using System.Linq;
85
using SmartyStreets;
9-
using SmartyStreets.USEnrichmentApi;
10-
using System.Reflection;
116
using System.Text;
7+
using System.Threading.Tasks;
128

139
internal static class USEnrichmentUniversalExample
14-
{
15-
public static void Run()
16-
{
10+
{
11+
public static void Run()
12+
{
1713
// specifies the TLS protocoll to use - this is TLS 1.2
1814
const SecurityProtocolType tlsProtocol1_2 = (SecurityProtocolType)3072;
1915

@@ -22,16 +18,16 @@ public static void Run()
2218

2319
// We recommend storing your keys in environment variables instead---it's safer!
2420
var authId = Environment.GetEnvironmentVariable("SMARTY_AUTH_ID");
25-
var authToken = Environment.GetEnvironmentVariable("SMARTY_AUTH_TOKEN");
26-
ServicePointManager.SecurityProtocol = tlsProtocol1_2;
21+
var authToken = Environment.GetEnvironmentVariable("SMARTY_AUTH_TOKEN");
22+
ServicePointManager.SecurityProtocol = tlsProtocol1_2;
2723

28-
var client = new ClientBuilder(authId, authToken).BuildUsEnrichmentApiClient();
24+
using var client = new ClientBuilder(authId, authToken).BuildUsEnrichmentApiClient();
2925

30-
byte[] results = null;
26+
byte[] results = null;
3127
// 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
3228

3329
// Create a lookup with a smarty key using the line below
34-
var lookup = new SmartyStreets.USEnrichmentApi.Universal.Lookup("325023201","property","principal");
30+
var lookup = new SmartyStreets.USEnrichmentApi.Universal.Lookup("325023201", "property", "principal");
3531

3632
// Create a lookup with address components using the lines below
3733
var componentsLookup = new SmartyStreets.USEnrichmentApi.Universal.Lookup();
@@ -56,26 +52,31 @@ public static void Run()
5652
// lookup.SetIncludeFields("assessed_value,assessor_last_update"); // applicable to Property lookups only
5753
// lookup.SetExcludeFields("tax_fiscal_year,tax_jurisdiction"); // applicable to Property lookups only
5854

59-
try {
55+
try
56+
{
6057
// results = client.SendUniversalLookup("325023201", "property", "principal"); // simple call with just a SmartyKey and Dataset info
6158

6259
// Send a lookup using the line below
6360
results = client.SendUniversalLookup(lookup);
6461
}
65-
catch (NotModifiedException ex) {
62+
catch (NotModifiedException ex)
63+
{
6664
Console.WriteLine(ex.Message); // The Etag value provided represents the latest version of the requested record
6765
}
68-
catch (Exception ex) {
66+
catch (Exception ex)
67+
{
6968
Console.WriteLine(ex.Message + ex.StackTrace);
7069
}
71-
72-
if (results != null) {
70+
71+
if (results != null)
72+
{
7373
// results is the JSON response from the API
7474
Console.WriteLine(Encoding.UTF8.GetString(results));
7575
}
76-
else {
76+
else
77+
{
7778
Console.WriteLine("Result was null");
7879
}
7980
}
80-
}
81+
}
8182
}

src/examples/USExtractExample.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
internal static class USExtractExample
1010
{
11-
public static void Run()
11+
public static void Run()
1212
{
1313
// specifies the TLS protocoll to use - this is TLS 1.2
1414
const SecurityProtocolType tlsProtocol1_2 = (SecurityProtocolType)3072;
@@ -18,7 +18,7 @@ public static void Run()
1818
var authToken = Environment.GetEnvironmentVariable("SMARTY_AUTH_TOKEN");
1919
ServicePointManager.SecurityProtocol = tlsProtocol1_2;
2020

21-
var client = new ClientBuilder(authId, authToken).BuildUsExtractApiClient();
21+
using var client = new ClientBuilder(authId, authToken).BuildUsExtractApiClient();
2222
var text = "Here is some text.\r\nMy address is 3785 Las Vegs Av." +
2323
"\r\nLos Vegas, Nevada." +
2424
"\r\nMeet me at 1 Rosedale Baltimore Maryland, not at 123 Phony Street, Boise Idaho.";

src/examples/USReverseGeoExample.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
namespace Examples
22
{
33
using System;
4-
using System.Collections.Generic;
54
using System.IO;
65
using System.Net;
76
using SmartyStreets;
@@ -22,7 +21,7 @@ public static void Run()
2221
var authToken = Environment.GetEnvironmentVariable("SMARTY_AUTH_TOKEN");
2322
ServicePointManager.SecurityProtocol = tlsProtocol1_2;
2423

25-
var client = new ClientBuilder(authId, authToken)
24+
using var client = new ClientBuilder(authId, authToken)
2625
//.WithCustomBaseUrl("us-street-reverse-geo.api.smarty.com")
2726
//.ViaProxy("http://localhost:8080", "username", "password") // uncomment this line to point to the specified proxy.
2827
.BuildUsReverseGeoApiClient();

0 commit comments

Comments
 (0)