Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ipinfo/details.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def __getattr__(self, attr):
if attr in self.details:
return self.details[attr]
else:
raise AttributeError('{attr} is not a valid attribute of Details'.format(attr))
raise AttributeError('{} is not a valid attribute of Details'.format(attr))

@property
def all(self):
Expand Down
17 changes: 9 additions & 8 deletions ipinfo/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,7 @@ def getDetails(self, ip_address=None):
raw_details = self._requestDetails(ip_address)
raw_details['country_name'] = self.countries.get(raw_details.get('country'))
raw_details['ip_address'] = ipaddress.ip_address(raw_details.get('ip'))

lat, lon = None, None
coords = tuple(raw_details.get('loc', '').split(','))
if coords:
lat, lon = coords[0], coords[1]
raw_details['latitude'], raw_details['longitude'] = lat, lon

raw_details['latitude'], raw_details['longitude'] = self._read_coords(raw_details.get('loc'))
return Details(raw_details)

def _requestDetails(self, ip_address=None):
Expand All @@ -75,13 +69,20 @@ def _get_headers(self):
headers = {
'user-agent': 'IPinfoClient/Python{version}/1.0'.format(version=sys.version_info[0]),
'accept': 'application/json'
}
}

if self.access_token:
headers['authorization'] = 'Bearer {}'.format(self.access_token)

return headers

def _read_coords(self, location):
lat, lon = None, None
coords = tuple(location.split(',')) if location else ''
if len(coords) == 2 and coords[0] and coords[1]:
lat, lon = coords[0], coords[1]
return lat, lon

def _read_country_names(self, countries_file=None):
"""Read list of countries from specified country file or default file."""
if not countries_file:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"""

setup(name='ipinfo',
version='1.1.0',
version='1.1.1',
description='Official Python library for IPInfo',
long_description=long_description,
url='https://github.com/ipinfo/python',
Expand Down