Commit 044f7d31 authored by Luciano Cauzzi's avatar Luciano Cauzzi

added save

parent 65f8274a
......@@ -11,11 +11,14 @@ class AppPyramidManager:
def __init__(self, base_url, resource_url, api_key, network_manager):
self.__url__ = resource_url
self.__res_url__ = resource_url
self.__api_key__ = api_key
self.__base_url__ = base_url
self.__network_manager__ = network_manager
logger.debug("Initialization completed: \nBASE_URL= {} \nRESOURCE_URL= {}\nAPI_KEY= {}".format(base_url, resource_url, api_key))
self.__app_token__ = None
"Initialization completed: \nBASE_URL= {} \nRESOURCE_URL= {}\nAPI_KEY= {}".format(base_url, resource_url,
def login(self) -> Optional[AppToken]:
......@@ -27,7 +30,32 @@ class AppPyramidManager:
s = self.__network_manager__.get_session()
response =, data=payload, headers=headers, timeout=AppPyramidManager.TIMEOUT)
json_repr = json.loads(response.text)
return app_token_from_dict(json_repr)
self.__app_token__ = app_token_from_dict(json_repr)
return self.__app_token__
except Exception as e:
logger.error("\n[NETWORK]: Error while fetching police report list: {} \n".format(e))
return None
def save(self, doc) -> bool:
Saves a document inside pyramid
:param doc:
:return: True or False
url = "{}/{}".format(self.__base_url__, self.__res_url__)
headers = {
'AUTHORIZATION': self.__app_token__.token,
'Content-Type': "application/json"
s = self.__network_manager__.get_session()
payload = json.dumps(doc.to_dict())
response =, data=payload, headers=headers, timeout=AppPyramidManager.TIMEOUT)
if response.status_code != 200:
return False
except Exception as e:
logger.error("Error while uploading injunctions to server")
return False
return True
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment