瀏覽代碼

Working on middleware

JoostSijm 4 年之前
父節點
當前提交
4590cbf459
共有 2 個文件被更改,包括 19 次插入4 次删除
  1. 2 2
      __init__.py
  2. 17 2
      middleware/middleware.py

+ 2 - 2
__init__.py

@@ -6,5 +6,5 @@ This unofficial API wrapper is an implementation
 of some Rival Regions functionalities.
 """
 
-from authentication_handler.authentication_handler import AuthenticationHandler
-from middleware.middleware import LocalAuthentication, RemoteAuthentication
+# from .authentication_handler.authentication_handler import AuthenticationHandler
+from .middleware.middleware import LocalAuthentication, RemoteAuthentication

+ 17 - 2
middleware/middleware.py

@@ -2,7 +2,9 @@
 
 from abc import ABC, abstractmethod
 
-from authentication_handler import AuthenticationHandeler
+import requests
+
+# from authentication_handler import AuthenticationHandler
 
 
 class MiddlewareBase(ABC):
@@ -38,11 +40,24 @@ class RemoteAuthentication(MiddlewareBase):
 
     def __init__(self, api_url, authentication_key):
         self.api_url = api_url
-        self.authentication_key = authentication_key
+        self.headers = {
+            'Authorization': authentication_key
+        }
         super().__init__()
 
     def get(self, path, add_c_var=False):
         """Send get requests"""
+        try:
+            response = requests.get(
+                '{}{}'.format(self.api_url, path), headers=self.headers
+            )
+            return response.text
+        except requests.exceptions.Timeout:
+            print('timeout')
+        except requests.exceptions.RequestException as exception:
+            print('request exception')
+            raise SystemExit(exception)
+        return None
 
     def post(self, path, data=None):
         """Send post request"""