Coretex
coretex.networking.network_manager.NetworkManager Class Reference

Inherits NetworkManagerBase.

Public Member Functions

NetworkResponse authenticate (self, str username, str password, bool storeCredentials=True)
 
NetworkResponse authenticateWithStoredCredentials (self)
 

Detailed Description

    Subclass of NetworkManagerBase intended to be used
    by a normal user. Contains functionality related to user
    and authenticating as a normal user.

Definition at line 25 of file network_manager.py.

Member Function Documentation

◆ authenticate()

NetworkResponse coretex.networking.network_manager.NetworkManager.authenticate (   self,
str  username,
str  password,
bool   storeCredentials = True 
)
    Authenticates user with provided credentials

    Parameters
    ----------
    username : str
Coretex.ai username
    password : str
Coretex.ai password
    storeCredentials : bool
If true credentials will be stored in User object for reuse

    Returns
    -------
    NetworkResponse -> NetworkResponse object containing the full response info

    Example
    -------
    >>> from coretex.networking import networkManager
    \b
    >>> response = networkManager.authenticate(username = "dummy@coretex.ai", password = "123456")
    >>> if response.hasFailed():
    print("Failed to authenticate")

Definition at line 58 of file network_manager.py.

58  def authenticate(self, username: str, password: str, storeCredentials: bool = True) -> NetworkResponse:
59  """
60  Authenticates user with provided credentials
61 
62  Parameters
63  ----------
64  username : str
65  Coretex.ai username
66  password : str
67  Coretex.ai password
68  storeCredentials : bool
69  If true credentials will be stored in User object for reuse
70 
71  Returns
72  -------
73  NetworkResponse -> NetworkResponse object containing the full response info
74 
75  Example
76  -------
77  >>> from coretex.networking import networkManager
78  \b
79  >>> response = networkManager.authenticate(username = "dummy@coretex.ai", password = "123456")
80  >>> if response.hasFailed():
81  print("Failed to authenticate")
82  """
83 
84  if storeCredentials:
85  self.__userData.username = username
86  self.__userData.password = password
87 
88  # authenticate using credentials stored in requests.Session.auth
89  return super().authenticate(username, password, storeCredentials)
90 

◆ authenticateWithStoredCredentials()

NetworkResponse coretex.networking.network_manager.NetworkManager.authenticateWithStoredCredentials (   self)
    Authenticates user with credentials stored inside User object

    Returns
    -------
    NetworkResponse -> NetworkResponse object containing the full response info

    Raises
    ------
    ValueError -> if credentials are not found

Definition at line 91 of file network_manager.py.

91  def authenticateWithStoredCredentials(self) -> NetworkResponse:
92  """
93  Authenticates user with credentials stored inside User object
94 
95  Returns
96  -------
97  NetworkResponse -> NetworkResponse object containing the full response info
98 
99  Raises
100  ------
101  ValueError -> if credentials are not found
102  """
103 
104  if self.__userData.username is None or self.__userData.password is None:
105  raise ValueError(">> [Coretex] Credentials not stored")
106 
107  return self.authenticate(self.__userData.username, self.__userData.password)
108 
109 
110 networkManager: NetworkManagerBase = NetworkManager()

The documentation for this class was generated from the following file: