From 46b88fff0b73ceae83e2af08a6ba372bb7bf75a4 Mon Sep 17 00:00:00 2001 From: Roberto Hueso Gómez Date: Wed, 2 Sep 2020 14:42:10 +0200 Subject: Add requests functionality to the OGServer class These functions will be used to make HTTP GET and POST requests to the OGServer. --- ogcp/og_server.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) 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 -- cgit v1.2.3-18-g5258