Compare commits

...

2 Commits

Author SHA1 Message Date
Pedro de Oliveira Guedes
eacb9635c0 Developing the only method. 2022-01-21 11:37:15 -03:00
Pedro de Oliveira Guedes
0371ae9175 Starting the development process. 2022-01-21 11:25:13 -03:00
3 changed files with 48 additions and 0 deletions

48
api/datasync/cli.py Normal file
View File

@ -0,0 +1,48 @@
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
def new (self, data_sync_report: dict):
"""
???
"""
return self.__request_json_post__("/ipc/datasyncreportmgr/new", data_sync_report)

View File

View File