Update API to keep backwards compatibility for geoip lookup

This commit is contained in:
JonnyWong16 2020-04-27 17:29:48 -07:00
parent 82ab732144
commit 1ab407eb38
No known key found for this signature in database
GPG key ID: B1F1F9807184697A
3 changed files with 8 additions and 8 deletions

5
API.md
View file

@ -683,7 +683,7 @@ Optional parameters:
Returns: Returns:
json: json:
{"continent": "North America", {"code": 'US",
"country": "United States", "country": "United States",
"region": "California", "region": "California",
"city": "Mountain View", "city": "Mountain View",
@ -693,9 +693,6 @@ Returns:
"longitude": -122.0838, "longitude": -122.0838,
"accuracy": 1000 "accuracy": 1000
} }
json:
{"error": "The address 127.0.0.1 is not in the database."
}
``` ```

View file

@ -615,6 +615,12 @@ General optional parameters:
cherrypy.response.headers['Content-Type'] = 'image/jpeg' cherrypy.response.headers['Content-Type'] = 'image/jpeg'
return out['response']['data'] return out['response']['data']
elif self._api_cmd == 'get_geoip_lookup':
# Remove nested data and put error message inside data for backwards compatibility
out['response']['data'] = out['response']['data'].get('data')
if not out['response']['data']:
out['response']['data'] = {'error': out['response']['message']}
if self._api_out_type == 'json': if self._api_out_type == 'json':
cherrypy.response.headers['Content-Type'] = 'application/json;charset=UTF-8' cherrypy.response.headers['Content-Type'] = 'application/json;charset=UTF-8'
try: try:

View file

@ -5736,7 +5736,7 @@ class WebInterface(object):
Returns: Returns:
json: json:
{"continent": "North America", {"code": 'US",
"country": "United States", "country": "United States",
"region": "California", "region": "California",
"city": "Mountain View", "city": "Mountain View",
@ -5746,9 +5746,6 @@ class WebInterface(object):
"longitude": -122.0838, "longitude": -122.0838,
"accuracy": 1000 "accuracy": 1000
} }
json:
{"error": "The address 127.0.0.1 is not in the database."
}
``` ```
""" """
message = '' message = ''