From 0371ae917558ecdceaac8aab91cab303ae6c750a Mon Sep 17 00:00:00 2001 From: Pedro de Oliveira Guedes Date: Fri, 21 Jan 2022 11:25:13 -0300 Subject: [PATCH] Starting the development process. --- api/datasync/cli.py | 39 +++++++++++++++++++++++++ api/datasync/features/data_sync.feature | 0 api/datasync/features/steps/steps.py | 0 3 files changed, 39 insertions(+) create mode 100644 api/datasync/cli.py create mode 100644 api/datasync/features/data_sync.feature create mode 100644 api/datasync/features/steps/steps.py diff --git a/api/datasync/cli.py b/api/datasync/cli.py new file mode 100644 index 0000000..147de6d --- /dev/null +++ b/api/datasync/cli.py @@ -0,0 +1,39 @@ +import json +import os +import requests + +class Data_sync: + """ + ## Data Sync + --- + ? + """ + + ep: str = "" + + def __init__ (self): + self.ep = "https://localhost:8443" + + def __request_json_post__ (self, path: str, object: dict): + + """ + ## HTTP JSON POST + --- + Este método é responsável por realizar requisições HTTP do tipo POST para objetos JSON. + + Ele retorna o corpo de resposta da requisição, ou uma mensagem de erro, que indica qual foi a irregularidade ocorrida ao chamar a API. + """ + + url = self.ep + path + print("Calling: " + url) + + apikey = os.environ.get('REPLAY_APIKEY') + headers = {"X-API-KEY": apikey} + res = requests.post(url, json = object, headers = headers, verify = False) + + if res.status_code >= 400: + raise Exception(f"HTTP ERROR: {str(res.status_code)} - {res.text}") + if res.headers.get("Content-Type") != None and res.headers.get("Content-Type").find("json") != -1: + return json.loads(res.text) + else: + return res.text \ No newline at end of file diff --git a/api/datasync/features/data_sync.feature b/api/datasync/features/data_sync.feature new file mode 100644 index 0000000..e69de29 diff --git a/api/datasync/features/steps/steps.py b/api/datasync/features/steps/steps.py new file mode 100644 index 0000000..e69de29