From 1ab407eb383b60ab03fdfd333cc71e135f7ff956 Mon Sep 17 00:00:00 2001 From: JonnyWong16 <9099342+JonnyWong16@users.noreply.github.com> Date: Mon, 27 Apr 2020 17:29:48 -0700 Subject: [PATCH] Update API to keep backwards compatibility for geoip lookup --- API.md | 5 +---- plexpy/api2.py | 6 ++++++ plexpy/webserve.py | 5 +---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/API.md b/API.md index a84647db..64ffd813 100644 --- a/API.md +++ b/API.md @@ -683,7 +683,7 @@ Optional parameters: Returns: json: - {"continent": "North America", + {"code": 'US", "country": "United States", "region": "California", "city": "Mountain View", @@ -693,9 +693,6 @@ Returns: "longitude": -122.0838, "accuracy": 1000 } - json: - {"error": "The address 127.0.0.1 is not in the database." - } ``` diff --git a/plexpy/api2.py b/plexpy/api2.py index 4b561774..c040c36e 100644 --- a/plexpy/api2.py +++ b/plexpy/api2.py @@ -615,6 +615,12 @@ General optional parameters: cherrypy.response.headers['Content-Type'] = 'image/jpeg' 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': cherrypy.response.headers['Content-Type'] = 'application/json;charset=UTF-8' try: diff --git a/plexpy/webserve.py b/plexpy/webserve.py index bcd37a4d..870c5187 100644 --- a/plexpy/webserve.py +++ b/plexpy/webserve.py @@ -5736,7 +5736,7 @@ class WebInterface(object): Returns: json: - {"continent": "North America", + {"code": 'US", "country": "United States", "region": "California", "city": "Mountain View", @@ -5746,9 +5746,6 @@ class WebInterface(object): "longitude": -122.0838, "accuracy": 1000 } - json: - {"error": "The address 127.0.0.1 is not in the database." - } ``` """ message = ''