diff options
author | Roberto Hueso Gómez <rhueso@soleta.eu> | 2020-09-02 14:42:10 +0200 |
---|---|---|
committer | Roberto Hueso Gómez <rhueso@soleta.eu> | 2020-09-02 14:42:10 +0200 |
commit | 46b88fff0b73ceae83e2af08a6ba372bb7bf75a4 (patch) | |
tree | 833447d9128a74a5b38318135a4bb9bf7ab778f8 /ogcp | |
parent | a4957f2284014186eb242470ce2336f0247796cb (diff) |
Add requests functionality to the OGServer class
These functions will be used to make HTTP GET and POST requests to the
OGServer.
Diffstat (limited to 'ogcp')
-rw-r--r-- | ogcp/og_server.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/ogcp/og_server.py b/ogcp/og_server.py index 6242f02..08c9b08 100644 --- a/ogcp/og_server.py +++ b/ogcp/og_server.py @@ -1,3 +1,4 @@ +import requests import json class OGServer: @@ -5,6 +6,7 @@ class OGServer: self.ip = ip self.port = port self.api_token = api_token + self._prepare_requests() def load_config(self, path): with open(path, 'r') as f: @@ -13,3 +15,20 @@ class OGServer: self.ip = cfg['ip'] self.port = cfg['port'] self.api_token = cfg['api_token'] + self._prepare_requests() + + def _prepare_requests(self): + self.URL = f'http://{self.ip}:{self.port}' + self.HEADERS = {'Authorization' : self.api_token} + + def get(self, path, payload=None): + r = requests.get(f'{self.URL}{path}', + headers=self.HEADERS, + json=payload) + return r + + def post(self, path, payload): + r = requests.post(f'{self.URL}{path}', + headers=self.HEADERS, + json=payload) + return r |