Repository: ramonsaraiva/pubg-python

Issue:
New telemetry exceptions
@ramonsaraiva
In official PUBG API discord server i've found that there is undocumented 403 status code if telemetry was not found on servers or no longer available. Should i make a new exception (ex. `OldTelemetryError`) or just return `NotFoundError` for 403 status code?

Examples:
https://telemetry-cdn.playbattlegrounds.com/bluehole-pubg/steam/2019/08/28/21/18/5a9cc5e2-c9d9-11e9-8db7-0a586468ab66-telemetry.json
https://telemetry-cdn.playbattlegrounds.com/bluehole-pubg/steam/2019/08/30/18/00/0fb4b2b6-cb50-11e9-a981-0a5864687231-telemetry.json

P.S. Should we limit telemetry URL only for official PUBG host `telemetry-cdn.playbattlegrounds.com` otherwise `TelemetryURLError`?

Comments:

Patch:
diff --git a/pubg_python/clients.py b/pubg_python/clients.py
index dcf7edf..04f3a21 100644
--- a/pubg_python/clients.py
+++ b/pubg_python/clients.py
@@ -13,6 +13,7 @@ class Client:
     API_OK = 200
     API_ERRORS_MAPPING = {
         401: exceptions.UnauthorizedError,
+        403: exceptions.OldTelemetryError,
         404: exceptions.NotFoundError,
         415: exceptions.InvalidContentTypeError,
         429: exceptions.RateLimitError,
@@ -45,4 +46,12 @@ class APIClient(Client):
 
 
 class TelemetryClient(Client):
-    pass
+
+    TELEMETRY_HOSTS = [
+        'telemetry-cdn.playbattlegrounds.com'
+    ]
+
+    def request(self, endpoint):
+        if furl.furl(endpoint).host not in self.TELEMETRY_HOSTS:
+            raise exceptions.TelemetryURLError
+        return super().request(endpoint)
diff --git a/pubg_python/exceptions.py b/pubg_python/exceptions.py
index 9a96ba8..aebfc2b 100644
--- a/pubg_python/exceptions.py
+++ b/pubg_python/exceptions.py
@@ -51,3 +51,15 @@ class RateLimitError(APIError):
                 int(self.response_headers.get('X-Ratelimit-Reset')))
         super().__init__('Too many requests. Limit: {} Reset: {}'.format(
            self.rl_limit, self.rl_reset))
+
+
+class OldTelemetryError(APIError):
+
+    def __init__(self, *args, **kwargs):
+        super().__init__('Telemetry was not found or no longer available')
+
+
+class TelemetryURLError(APIError):
+
+    def __init__(self, *args, **kwargs):
+        super().__init__('Telemetry host differs from official')


Test patch:
diff --git a/tests/test_exceptions.py b/tests/test_exceptions.py
index 68ff363..73effb6 100644
--- a/tests/test_exceptions.py
+++ b/tests/test_exceptions.py
@@ -9,7 +9,9 @@ from pubg_python.exceptions import (
     UnauthorizedError,
     NotFoundError,
     InvalidContentTypeError,
-    RateLimitError
+    RateLimitError,
+    OldTelemetryError,
+    TelemetryURLError
 )
 api = PUBG('apikey', Shard.STEAM)
 BASE_URL = APIClient.BASE_URL
@@ -90,3 +92,23 @@ def test_client_ratelimit_error(mock):
         assert False
     except RateLimitError:
         assert True
+
+
+def test_old_telemetry_error(mock):
+    url = 'https://telemetry-cdn.playbattlegrounds.com/missed_path.json'
+    mock.get(url, status_code=403)
+    try:
+        api.telemetry(url)
+        assert False
+    except OldTelemetryError:
+        assert True
+
+
+def test_telemetry_url_error(mock):
+    url = 'https://different-host.com/telemetry.json'
+    mock.get(url, status_code=200)
+    try:
+        api.telemetry(url)
+        assert False
+    except TelemetryURLError:
+        assert True
diff --git a/tests/test_telemetry.py b/tests/test_telemetry.py
index 4c63489..40929c0 100644
--- a/tests/test_telemetry.py
+++ b/tests/test_telemetry.py
@@ -6,7 +6,7 @@ from pubg_python.domain.telemetry.events import LogMatchDefinition
 
 api = PUBG('apikey', Shard.STEAM)
 BASE_URL = APIClient.BASE_URL
-TELEMETRY_URL = 'http://telemetry.pubg'
+TELEMETRY_URL = 'http://telemetry-cdn.playbattlegrounds.com/telemetry.json'
 TELEMETRY_JSON = json.load(open('tests/telemetry_response.json'))