-
Notifications
You must be signed in to change notification settings - Fork 156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature Us Census Bureau #118
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't had a chance to dig deep into this yet. But could you also update the README documentation to include this new geocoder, how it works, how to set it up. and any caveats?
sure i'll get back to you when I do. |
@chadly done, added to readme |
Also note, it doesnt support reverse geocoding & is US only... I added that to readme |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My team has been using this for a substantial period of time at this point with no issues. Can this get merged?
@RodneyRichardson can you take a look? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've not be able to test, but generally it looks like it might work, but there are a few improvements that could be made (such as not swallowing errors).
I don't have authority to approve merge requests.
private readonly string _format; | ||
private readonly HttpClient _client; | ||
|
||
public UsCensusBureauGeocoder(int benchmark = 4, string format = "json") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the magic number "4" (benchmark)? Can this be made into a (string) constant?
private readonly string _format; | ||
private readonly HttpClient _client; | ||
|
||
public UsCensusBureauGeocoder(int benchmark = 4, string format = "json") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the format parameter - the code only supports JSON, so hardcode it.
@@ -0,0 +1,98 @@ | |||
using System; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Formatting in this file could be improved - Visual Studio autoformat should be sufficient.
/// </summary> | ||
public class UsCensusBureauGeocoder : IGeocoder | ||
{ | ||
private readonly int _benchmark; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
API defines benchmark as a string, and the example use, for example, "Public_AR_Census2020". Should this be a string? It might be worth referencing https://geocoding.geo.census.gov/geocoder/benchmarks for the list of available benchmarks.
|
||
var errors = json[UsCensusBureauConstants.ErrorsKey]; | ||
if (errors != null) | ||
return new UsCensusBureauAddress[] {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't swallow errors. Create and throw a UsCensusBureauGeocodingException (wow, that's a long name - how about Ucb?) to wrap and expose the error.
/// - https://geocoding.geo.census.gov/ | ||
/// - https://geocoding.geo.census.gov/geocoder/Geocoding_Services_API.pdf | ||
/// </summary> | ||
public class UsCensusBureauGeocoder : IGeocoder |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding an IBatchGeocoder, as this looks to be supported by the API.
namespace Geocoding.Tests | ||
{ | ||
[Collection("Settings")] | ||
public class UsCensusBureauTest : GeocoderTest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add tests for other "benchmark" values.
using Geocoding.UsCensusBureau; | ||
using Xunit; | ||
|
||
namespace Geocoding.Tests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't skip tests. Assert that they behave as expected (such as throwing NotSupportedException, or returning/throwing an appropriate error).
sb.Append("street=").Append(WebUtility.UrlEncode(street)) | ||
.Append("&city=").Append(WebUtility.UrlEncode(city)) | ||
.Append("&state=").Append(WebUtility.UrlEncode(state)) | ||
.Append("&zip=").Append(WebUtility.UrlEncode(postalCode)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this work if any parameters are omitted? Perhaps add a test for partial address.
I'm obviously busy and neglecting things here. Do you want write access to the repo @RodneyRichardson. I would appreciate the help for this project. |
No description provided.