@@ -11,11 +11,11 @@ namespace Rentler.SmartyStreets
11
11
/// Handles requests to SmartyStreets for street address
12
12
/// and city/state/zip lookups.
13
13
/// </summary>
14
- public class SmartyStreetsClient
14
+ public class SmartyStreetsClient : ISmartyStreetsClient
15
15
{
16
- ApiClient client ;
17
- string authId ;
18
- string authToken ;
16
+ private ApiClient _client ;
17
+ private string _authId ;
18
+ private string _authToken ;
19
19
20
20
/// <summary>
21
21
/// Initializes a new instance of the SmartyStreetsClient.
@@ -29,21 +29,21 @@ public class SmartyStreetsClient
29
29
/// </summary>
30
30
/// <param name="authId">Unique "auth-id" value provided by SmartyStreets.</param>
31
31
/// <param name="authToken">Unique "auth-token" value.</param>
32
- public SmartyStreetsClient (
33
- string authId = null ,
34
- string authToken = null )
32
+ public SmartyStreetsClient ( string authId = null , string authToken = null )
35
33
{
36
- client = ApiClient . Instance ;
37
- this . authId = authId ?? App . SmartyStreetsAuthId ;
38
- this . authToken = authToken ?? App . SmartyStreetsAuthToken ;
34
+ _client = ApiClient . Instance ;
35
+ this . _authId = authId ?? App . SmartyStreetsAuthId ;
36
+ this . _authToken = authToken ?? App . SmartyStreetsAuthToken ;
39
37
40
- if ( string . IsNullOrWhiteSpace ( this . authId ) || string . IsNullOrWhiteSpace ( this . authToken ) )
38
+ if ( string . IsNullOrWhiteSpace ( this . _authId ) || string . IsNullOrWhiteSpace ( this . _authToken ) )
41
39
throw new System . Configuration . ConfigurationErrorsException (
42
40
"Could not find one or either of the SmartyStreets auth keys.\n " +
43
41
"Set them in the constructor, or an app.config or web.config." ) ;
44
42
}
45
43
46
- /// <summary>
44
+
45
+ #region depricated
46
+ /// <summary>
47
47
/// Attempts to resolve a street address to a verified one.
48
48
/// Makes requests to https://api.smartystreets.com/street-address.
49
49
/// See http://smartystreets.com/kb/liveaddress-api/rest-endpoint for
@@ -56,28 +56,12 @@ public SmartyStreetsClient(
56
56
/// <returns>An enumerable list of possible addresses. Generally, one entry
57
57
/// will be returned, but results can include up to five possibles. If none are found,
58
58
/// the array will be empty.</returns>
59
- public async Task < IEnumerable < SmartyStreetsAddress > > GetStreetAddress (
59
+ [ Obsolete ( "Use async method instead" ) ]
60
+ public Task < IEnumerable < SmartyStreetsAddress > > GetStreetAddress (
60
61
string street = null , string city = null ,
61
62
string state = null , string zipcode = null )
62
63
{
63
- var args = SetAuth ( ) ;
64
- args [ "street" ] = street ;
65
- args [ "city" ] = city ;
66
- args [ "state" ] = state ;
67
- args [ "zipcode" ] = zipcode ;
68
- args [ "candidates" ] = "5" ;
69
-
70
- //var url = client.CreateAddress("street-address", args);
71
- var url = client . CreateAddress ( "street-address" , args ) ;
72
- var response = await client . Post ( url ) ;
73
-
74
- //special cases
75
- if ( response . Length == 3 )
76
- return new SmartyStreetsAddress [ 0 ] ;
77
-
78
- return JsonSerializer . DeserializeFromStream < SmartyStreetsAddress [ ] > ( response )
79
- ??
80
- new SmartyStreetsAddress [ 0 ] ;
64
+ return GetStreetAddressAsync ( street , city , state , zipcode ) ;
81
65
}
82
66
83
67
/// <summary>
@@ -93,40 +77,95 @@ public async Task<IEnumerable<SmartyStreetsAddress>> GetStreetAddress(
93
77
/// <returns>An object with lists of matching Cities and States, along
94
78
/// with any relevant zip codes that match the area. If SmartyStreets
95
79
/// cannot find anything, an empty array will be returned.</returns>
96
- public async Task < IEnumerable < SmartyStreetsCityStateZipLookup > > GetLookup (
80
+ [ Obsolete ( "Use async method instead" ) ]
81
+ public Task < IEnumerable < SmartyStreetsCityStateZipLookup > > GetLookup (
97
82
string city = null , string state = null ,
98
83
string zip = null )
99
84
{
100
- var args = SetAuth ( ) ;
101
- args [ "city" ] = city ;
102
- args [ "state" ] = state ;
103
- args [ "zip" ] = zip ;
104
-
105
- var url = client . CreateAddress ( "zipcode" , args ) ;
106
- var response = await client . Post ( url ) ;
107
- var obj = JsonSerializer . DeserializeFromStream < SmartyStreetsCityStateZipLookup [ ] > ( response )
108
- ??
109
- new SmartyStreetsCityStateZipLookup [ ] { } ;
110
-
111
- return obj ;
85
+ return GetLookupAsync ( city , state , zip ) ;
112
86
}
87
+ #endregion
113
88
114
- /// <summary>
115
- /// Handles assignment of the keys necessary to talk to SmartyStreets.
116
- /// </summary>
117
- /// <param name="dict">A dictionary with any arguments intended to be
118
- /// passed to SmartyStreets. If an existing dictionary is not supplied,
119
- /// it will instantiate and return a new one.</param>
120
- /// <returns>A dictionary with the necessary keys to talk to SmartyStreeets.</returns>
121
- Dictionary < string , string > SetAuth ( Dictionary < string , string > dict = null )
122
- {
123
- if ( dict == null )
124
- dict = new Dictionary < string , string > ( ) ;
89
+ /// <summary>
90
+ /// Attempts to resolve a street address to a verified one.
91
+ /// Makes requests to https://api.smartystreets.com/street-address.
92
+ /// See http://smartystreets.com/kb/liveaddress-api/rest-endpoint for
93
+ /// documentation on this endpoint.
94
+ /// </summary>
95
+ /// <param name="street">The street address, or a single-line (freeform) address.</param>
96
+ /// <param name="city">The city name.</param>
97
+ /// <param name="state">The state name.</param>
98
+ /// <param name="zipcode">The ZIP code.</param>
99
+ /// <returns>An enumerable list of possible addresses. Generally, one entry
100
+ /// will be returned, but results can include up to five possibles. If none are found,
101
+ /// the array will be empty.</returns>
102
+ public async Task < IEnumerable < SmartyStreetsAddress > > GetStreetAddressAsync ( string street = null , string city = null , string state = null , string zipcode = null )
103
+ {
104
+ var args = SetAuth ( ) ;
105
+ args [ "street" ] = street ;
106
+ args [ "city" ] = city ;
107
+ args [ "state" ] = state ;
108
+ args [ "zipcode" ] = zipcode ;
109
+ args [ "candidates" ] = "5" ;
125
110
126
- dict [ "auth-id" ] = authId ;
127
- dict [ "auth-token" ] = authToken ;
111
+ //var url = client.CreateAddress("street-address", args);
112
+ var url = _client . CreateAddress ( "street-address" , args ) ;
113
+ var response = await _client . PostAsync ( url ) ;
128
114
129
- return dict ;
130
- }
131
- }
115
+ //special cases
116
+ if ( response . Length == 3 )
117
+ return new SmartyStreetsAddress [ 0 ] ;
118
+
119
+ return JsonSerializer . DeserializeFromStream < SmartyStreetsAddress [ ] > ( response )
120
+ ??
121
+ new SmartyStreetsAddress [ 0 ] ;
122
+ }
123
+
124
+ /// <summary>
125
+ /// Allows you to identify cities with ZIP codes, and vice-versa.
126
+ /// It also provides approximate geo-coordinates (latitude/longitude).
127
+ /// This endpoint does not support street addresses as input. See
128
+ /// http://smartystreets.com/kb/liveaddress-api/zipcode-api for documentation
129
+ /// on this endpoint.
130
+ /// </summary>
131
+ /// <param name="city">The city name.</param>
132
+ /// <param name="state">The state name.</param>
133
+ /// <param name="zip">The ZIP code.</param>
134
+ /// <returns>An object with lists of matching Cities and States, along
135
+ /// with any relevant zip codes that match the area. If SmartyStreets
136
+ /// cannot find anything, an empty array will be returned.</returns>
137
+ public async Task < IEnumerable < SmartyStreetsCityStateZipLookup > > GetLookupAsync ( string city = null , string state = null , string zip = null )
138
+ {
139
+ var args = SetAuth ( ) ;
140
+ args [ "city" ] = city ;
141
+ args [ "state" ] = state ;
142
+ args [ "zip" ] = zip ;
143
+
144
+ var url = _client . CreateAddress ( "zipcode" , args ) ;
145
+ var response = await _client . PostAsync ( url ) ;
146
+ var obj = JsonSerializer . DeserializeFromStream < SmartyStreetsCityStateZipLookup [ ] > ( response )
147
+ ??
148
+ new SmartyStreetsCityStateZipLookup [ ] { } ;
149
+
150
+ return obj ;
151
+ }
152
+
153
+ /// <summary>
154
+ /// Handles assignment of the keys necessary to talk to SmartyStreets.
155
+ /// </summary>
156
+ /// <param name="dict">A dictionary with any arguments intended to be
157
+ /// passed to SmartyStreets. If an existing dictionary is not supplied,
158
+ /// it will instantiate and return a new one.</param>
159
+ /// <returns>A dictionary with the necessary keys to talk to SmartyStreeets.</returns>
160
+ private Dictionary < string , string > SetAuth ( Dictionary < string , string > dict = null )
161
+ {
162
+ if ( dict == null )
163
+ dict = new Dictionary < string , string > ( ) ;
164
+
165
+ dict [ "auth-id" ] = _authId ;
166
+ dict [ "auth-token" ] = _authToken ;
167
+
168
+ return dict ;
169
+ }
170
+ }
132
171
}
0 commit comments