Skip to content

Commit 45b3378

Browse files
authored
Merge pull request #81 from ipinfo/awais/be-837
Added link to country's flag image
2 parents f591515 + 569584f commit 45b3378

File tree

6 files changed

+16
-2
lines changed

6 files changed

+16
-2
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# IPInfo Changelog
22

3+
## 4.4.3
4+
5+
- Added `CountryFlagURL` to the details object.
6+
- Allowed custom headers
7+
38
## 4.4.2
49

510
- Patch fix for empty `ip_address` crash.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ You can add custom headers or modify default headers by setting the `headers` ke
240240

241241
### Internationalization
242242

243-
When looking up an IP address, the response object includes a `details.country_name`, `details.isEU`, `details.country_flag` and `details.country_currency` attributes which includes the country based on American English. It is possible to return the country name in other languages by setting the `countries_file`, remove or add EU countries by setting the keyword argument `eu_countries_file`, change the country flag emoji or unicode by setting the keyword argument `countries_flags_file` or change country's currency code or currency symbol by setting the `countries_currencies` when creating the `IPinfo` object. Moreover the response object includes a `details.continent` which includes continent code and name of IP. The default file can be changed by setting the `continent_file` while creating the `IPinfo` object.
243+
When looking up an IP address, the response object includes a `details.country_name`, `details.isEU`, `details.country_flag`, `details.country_flag_url` and `details.country_currency` attributes which includes the country based on American English. It is possible to return the country name in other languages by setting the `countries_file`, remove or add EU countries by setting the keyword argument `eu_countries_file`, change the country flag emoji or unicode by setting the keyword argument `countries_flags_file` or change country's currency code or currency symbol by setting the `countries_currencies` when creating the `IPinfo` object. Moreover the response object includes a `details.continent` which includes continent code and name of IP. The default file can be changed by setting the `continent_file` while creating the `IPinfo` object.
244244

245245
The file must be a `.json` file with the following structure:
246246

ipinfo/handler_utils.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
# Base URL to make requests against.
1313
API_URL = "https://ipinfo.io"
1414

15+
# Base URL to get country flag image link.
16+
# "PK" -> "https://cdn.ipinfo.io/static/images/countries-flags/PK.svg"
17+
COUNTRY_FLAGS_URL = "https://cdn.ipinfo.io/static/images/countries-flags/"
18+
1519
# Used to transform incoming responses with country abbreviations into the full
1620
# expanded country name, e.g. "PK" -> "Pakistan".
1721
COUNTRY_FILE_DEFAULT = "countries.json"
@@ -75,6 +79,7 @@ def format_details(
7579
"""
7680
details["country_name"] = countries.get(details.get("country"))
7781
details["isEU"] = details.get("country") in eu_countries
82+
details["country_flag_url"] = COUNTRY_FLAGS_URL + details.get("country") + ".svg"
7883
details["country_flag"] = copy.deepcopy(
7984
countries_flags.get(details.get("country"))
8085
)

ipinfo/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
SDK_VERSION = "4.4.2"
1+
SDK_VERSION = "4.4.3"

tests/handler_async_test.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ async def test_get_details():
4747
country_flag = details.country_flag
4848
assert country_flag["emoji"] == "🇺🇸"
4949
assert country_flag["unicode"] == "U+1F1FA U+1F1F8"
50+
country_flag_url = details.country_flag_url
51+
assert country_flag_url == "https://cdn.ipinfo.io/static/images/countries-flags/US.svg"
5052
country_currency = details.country_currency
5153
assert country_currency["code"] == "USD"
5254
assert country_currency["symbol"] == "$"

tests/handler_test.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ def test_get_details():
4444
country_flag = details.country_flag
4545
assert country_flag["emoji"] == "🇺🇸"
4646
assert country_flag["unicode"] == "U+1F1FA U+1F1F8"
47+
country_flag_url = details.country_flag_url
48+
assert country_flag_url == "https://cdn.ipinfo.io/static/images/countries-flags/US.svg"
4749
country_currency = details.country_currency
4850
assert country_currency["code"] == "USD"
4951
assert country_currency["symbol"] == "$"

0 commit comments

Comments
 (0)