-
Notifications
You must be signed in to change notification settings - Fork 20
/
InternationalStreetExample.cs
86 lines (75 loc) · 3.25 KB
/
InternationalStreetExample.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
namespace Examples
{
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using SmartyStreets;
using SmartyStreets.InternationalStreetApi;
internal static class InternationalStreetExample
{
public static void Run()
{
// specifies the TLS protocoll to use - this is TLS 1.2
const SecurityProtocolType tlsProtocol1_2 = (SecurityProtocolType)3072;
// We recommend storing your secret keys in environment variables.
var authId = Environment.GetEnvironmentVariable("SMARTY_AUTH_ID");
var authToken = Environment.GetEnvironmentVariable("SMARTY_AUTH_TOKEN");
ServicePointManager.SecurityProtocol = tlsProtocol1_2;
// The appropriate license values to be used for your subscriptions
// can be found on the Subscriptions page the account dashboard.
// https://www.smartystreets.com/docs/cloud/licensing
var client = new ClientBuilder(authId, authToken).WithLicense(new List<string>{"international-global-plus-cloud"})
.BuildInternationalStreetApiClient();
// Documentation for input fields can be found at:
// https://smartystreetscom/docs/cloud/international-street-api#http-input-fields
// Geocoding must be expressly set to get latitude and longitude.
var lookup = new Lookup("Rua Padre Antonio D'Angelo 121 Casa Verde, Sao Paulo", "Brazil")
{
InputId = "ID-8675309", // Optional ID from your system
Geocode = true,
Organization = "John Doe",
Address1 = "Rua Padre Antonio D'Angelo 121",
Address2 = "Casa Verde",
Locality = "Sao Paulo",
AdministrativeArea = "SP",
Country = "Brazil",
PostalCode = "02516-050"
};
//uncomment the line below to add a custom parameter
//lookup.AddCustomParameter("input_id", "ID-8675309");
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;
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");
Console.WriteLine("First Line: " + firstCandidate.Address1);
Console.WriteLine("Second Line: " + firstCandidate.Address2);
Console.WriteLine("Third Line: " + firstCandidate.Address3);
Console.WriteLine("Fourth Line: " + firstCandidate.Address4);
Console.WriteLine("Address Format: " + firstCandidate.Metadata.AddressFormat);
Console.WriteLine("Latitude: " + firstCandidate.Metadata.Latitude);
Console.WriteLine("Longitude: " + firstCandidate.Metadata.Longitude);
}
}
}