From ddeddd229988264ff4c507f41b6de9179b59267c Mon Sep 17 00:00:00 2001 From: David Melamed Date: Thu, 9 Jul 2020 15:07:54 +0300 Subject: [PATCH 1/2] Add support for IPInfo API Keys --- geocoder/keys.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/geocoder/keys.py b/geocoder/keys.py index 6d42c2d9..4c71f348 100644 --- a/geocoder/keys.py +++ b/geocoder/keys.py @@ -25,7 +25,7 @@ geocodefarm_key = os.environ.get('GEOCODEFARM_API_KEY') tgos_key = os.environ.get('TGOS_API_KEY') locationiq_key = os.environ.get('LOCATIONIQ_API_KEY') - +ipinfo_key = os.environ.get('IPINFO_API_KEY') class CanadapostKeyLazySingleton(object): From 011958aa004c556765dbcbb2a6d0fcc643096378 Mon Sep 17 00:00:00 2001 From: David Melamed Date: Thu, 9 Jul 2020 15:15:12 +0300 Subject: [PATCH 2/2] Add support for API key --- geocoder/ipinfo.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/geocoder/ipinfo.py b/geocoder/ipinfo.py index 3cc50955..84e2eb2a 100644 --- a/geocoder/ipinfo.py +++ b/geocoder/ipinfo.py @@ -7,7 +7,7 @@ from geocoder.base import OneResult, MultipleResultsQuery from geocoder.location import Location - +from geocoder.keys import ipinfo_key class IpinfoResult(OneResult): @@ -74,8 +74,17 @@ class IpinfoQuery(MultipleResultsQuery): _URL = 'http://ipinfo.io/json' _RESULT_CLASS = IpinfoResult + _KEY = ipinfo_key _KEY_MANDATORY = False + def _build_headers(self, provider_key, **kwargs): + return { + 'Authorization': 'Bearer {}'.format(provider_key), + } + + def _build_params(self, location, provider_key, **kwargs): + return {} + def _before_initialize(self, location, **kwargs): if location.lower() == 'me' or location == '': self.url = 'http://ipinfo.io/json'