-
Notifications
You must be signed in to change notification settings - Fork 112
Add support for country code filtering #107
Conversation
@@ -84,6 +94,11 @@ def geojson(): | |||
return resp | |||
|
|||
@property | |||
def country_codes(self): | |||
"""A list of valid country codes""" | |||
return ('ad', 'ae', 'al', 'ao', 'ar', 'at', 'au', 'ba', 'be', 'bg', 'bh', 'bn', 'br', 'bw', 'by', 'ca', 'ch', 'cl', 'cn', 'co', 'cu', 'cy', 'cz', 'de', 'dk', 'dz', 'ee', 'eg', 'es', 'fi', 'fr', 'gb', 'gf', 'gp', 'gr', 'hr', 'hu', 'id', 'ie', 'in', 'is', 'it', 'jo', 'jp', 'ke', 'kw', 'lb', 'lt', 'lu', 'lv', 'ma', 'md', 'me', 'mk', 'mt', 'mx', 'my', 'nl', 'no', 'nz', 'pe', 'ph', 'pl', 'pt', 'ro', 'rs', 'ru', 'se', 'sg', 'si', 'sk', 'sm', 'th', 'tr', 'tw', 'ua', 'us', 'uy', 've', 'vn', 'za') |
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.
We might want to consider other ways for defining the country codes
- A separate text file that is read in by
country_codes
- A separate module or use the existing iso3166 module
At the very least we should reformat this tuple to be < 80 chars wide so we don't get wrapping.
@jlubawy This looks great. Thanks for the contribution! Aside from the note above, the only issue is the failing tests on travis which appears to be related to access_tokens and is unrelated to your commits. I'll look into it... |
Re: failing doctests on travis
still investigating... |
The mapbox access token is set up as an encrypted environment variable and
@sgillies Do you know of any way around this so that doctests can pass on pull requests from forked repos? Otherwise, we can test locally and just ignore travis. It's might be a bit off-putting for contributors though. |
* Make more consistent with existing code * Use iso3166 package for country code validation
Thanks for the suggestions @perrygeo, I chose to use iso3166's country code list for validation. One thing that's worth mentioning is that the Mapbox API doesn't support every country in this list so there may be cases where the API will return an error message such as this:
This error message is actually where I had gotten the original validation tuple from ('zw' is CC for Zimbabwe BTW). My thoughts are that it's probably best to use the iso3166 package for a quick sanity check and then if the user provides a country code not supported by Mapbox they will have to handle the API error like any other they might receive. In my opinion this is better than having to maintain a separate country code list that could easily get out-of-date. |
@jlubawy I think we'll deal with travis encrypted variables issue in a different PR. This looks great, doctests pass locally, happy with using the iso3166 module for now. Let's merge it. |
Add support for country code filtering
Added support for country code filtering in geocoding forward requests, all tests pass and documentation was updated to reflect new feature.