Skip to content

Commit d20a71c

Browse files
authored
Merge pull request #22 from dmelamedcl/master
Support API key for IPINFO
2 parents 2a0beb9 + c5d0cd7 commit d20a71c

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

geocoder/ipinfo.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from geocoder.base import OneResult, MultipleResultsQuery
99
from geocoder.location import Location
10-
10+
from geocoder.keys import ipinfo_key
1111

1212
class IpinfoResult(OneResult):
1313

@@ -74,8 +74,17 @@ class IpinfoQuery(MultipleResultsQuery):
7474

7575
_URL = 'http://ipinfo.io/json'
7676
_RESULT_CLASS = IpinfoResult
77+
_KEY = ipinfo_key
7778
_KEY_MANDATORY = False
7879

80+
def _build_headers(self, provider_key, **kwargs):
81+
return {
82+
'Authorization': 'Bearer {}'.format(provider_key),
83+
}
84+
85+
def _build_params(self, location, provider_key, **kwargs):
86+
return {}
87+
7988
def _before_initialize(self, location, **kwargs):
8089
if location.lower() == 'me' or location == '':
8190
self.url = 'http://ipinfo.io/json'

geocoder/keys.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
geocodefarm_key = os.environ.get('GEOCODEFARM_API_KEY')
2626
tgos_key = os.environ.get('TGOS_API_KEY')
2727
locationiq_key = os.environ.get('LOCATIONIQ_API_KEY')
28-
28+
ipinfo_key = os.environ.get('IPINFO_API_KEY')
2929

3030
class CanadapostKeyLazySingleton(object):
3131

0 commit comments

Comments
 (0)