Package: unirio-api
Python module for the API provided by the Universidade Federal do Estado
do Rio de Janeiro (UNIRIO) Please visithttp://sistemas.unirio.br/apifor futher information.Installingpip install unirio-apiFile Structureapi/
├── MANIFEST.in
├── README.md
├── README.rst
├── __init__.py
├── requirements.txt
├── setup.cfg
├── setup.py
├── tests
│   ├── __init__.py
│   ├── config.py
│   ├── delete.py
│   ├── get.py
│   ├── post.py
│   ├── procedures.py
│   ├── put.py
│   ├── request.py
├── unirio
    ├── __init__.py
    └── api
        ├── __init__.py
        ├── exceptions.py
        ├── request.py
        ├── request.pyi
        ├── result.pyTestspython -m unittest -v testsUNIRIOAPIRequestUNIRIOAPIRequest takes 2 arguments:A valid APIKey that will be used for future requestsAn APIServer that identify the server used to perform the requestsAn integer identifier for the server used to perform requests.
Default:APIServer.LOCAL(Local Server)The MethodsThe public module interface for interacting with the API methods is as
follows:defget(self,path:str,params:Dict[str:Any],fields:list,cache_time:int)->APIResultObject:path: The API endpoint to use for the request, for example ‘ALUNOS’params: The parameters for the request. A value of None sends the
automatic API parametersfields: The return fields for the request. A value of None is equal
do requesting ALL the fieldsdefpost(self,path:str,params:Dict[str:Any])->APIPOSTResponse:path: The API endpoint to use for the request, for example ‘ALUNOS’params: The parameters for the request. Should contain all the
not-null attributes.defdelete(self,path:str,params:Dict[str:int])->APIDELETEResponse:path: The API endpoint to use for the request, for example ‘ALUNOS’params: The parameters for the request. Should contain the endpoint
unique identifier. e.g.:{'ID_ALUNO': 235}defput(self,path:str,params:Dict[str:Any])->APIPUTResponse:path: The API endpoint to use for the request, for example ‘ALUNOS’params: The parameters for the request. Should contain all the
attributes that should be updated as well as the endpoint unique
identifier.UsageOn your models, importUNIRIOAPIRequestand the enumAPIServerand create an api object using your APIKey provided byhttp://sistemas.unirio.br/apifromunirio.apiimportUNIRIOAPIRequest,APIServerapi_key='afakehashusedforthisexample'api=UNIRIOAPIRequest(api_key,APIServer.PRODUCTION)Optional parameters aredebug: booleanandcache.debuggives console verbosity andcacheis used for caching inUNIRIOAPIRequest.getmethod.getpath='ALUNOS'params={'LMIN':0,'LMAX':1000,'SEXO':'F''ETNIA_ITEM':1}fields=['ID_ALUNO','ID_PESSOA','SEXO']result=api.get(path,params,fields)# type: unirio.api.result.APIRestultObjectThe get method also have an optional parametercache_time,
representing the cache expiration time in seconds, and defaults to0, that means that no cache is applied.[...]result=api.get(path,params,fields,cache_time=60)The above request gives the same response object, but is cached for 60
seconds, wich means that if another request is made within 60 seconds,
for the samepath, another HTTP request wont be made to the API
server.All the caching is done on the client side, wich means that
every request done to the api will always reflect the current state
of the resource at the time of the request. Whenever possible, it’s
always recommended that you cache your requests, since in most cases
it’s much faster.A method call toUNIRIOAPIRequest.getwill return anAPIResultObjectwich is a model object and have the following
attributes:content: list: A list of dictionaries with the result of the GET
request. Iffields != Nonethe dictionaries of the list will only
contain the keys from thefieldslist.lmin: int: The offset of the request resultlmax: int: The limit of the request resultfields: tuple: The list of endpoint fields that should be
returnedExceptionsNoContentException: Raised when the api returns a ‘content not
found’ status code, and it means that no content was found for the
given parameters.postpath='ALUNOS'params={'SEXO':'F','ETNIA_ITEM':1,'NOME_PAI':'Jonathan Kent','NOME_MAE':'Martha Kent''ID_PESSOA':345}result=api.post(path,params)# type: unirio.api.result.APIPOSTResponseA method call toUNIRIOAPIRequest.postwill return anAPIPOSTResponsewich is a model object and have the following
attributes:insertId: int: Unique identifier created on the POST request.ExceptionsInvalidParametersException:ContentNotCreated:putpath='PESSOAS'params={'ID_PESSOA':345,'NOME_PESSOA':'My new name'}result=api.put(path,params)# type: unirio.api.result.APIPUTResponseA method call toUNIRIOAPIRequest.putwill return anAPIPUTResponsewich is a model object and have the following
attributes:affectedRows: int: The number of rows affected by the PUT
request.ExceptionsContentNotFoundException: Invalid unique identifier and nothing
was updatedInvalidParametersException: One or more of the parameters has an
incompatible typeNothingToUpdateException: No valid content passed onparamsand nothing was updatedMissingPrimaryKeyException: The unique identifier field isn’t a
Key in theparamsdictionary.deletepath='PESSOAS'params={'ID_PESSOA':345}result=api.delete(path,params)# type: unirio.api.result.APIDELETEResponseA method call toUNIRIOAPIRequest.deletewill return anAPIDELETEResponsewich is a model object and have the following
attributes:affectedRows: int: The number of rows affected by the DELETE
request.ExceptionsContentNotFoundException: Invalid unique identifier and nothing
was updatedNothingToUpdateException:MissingPrimaryKeyException: The unique identifier field isn’t a
Key in theparamsdictionary.Common ExceptionsForbiddenEndpointException: The API Key doens’t have permission
to perform the request on thepathendpointInvalidAPIKeyException: The API Key used is invalid or inactiveUnhandledAPIException: Something unexpected happened on the
server sideInvalidEndpointException: The endpointpathdoesn’t exist.
Check the list of endpoint on the main page ofhttp://sistemas.unirio.br/apiInvalidParametersException: The request was performed with
invalidparamsand shouldn’t be repeated used the sameparams. That exception object has aninvalid_parametersattribute, wich is a list of the invalid keys onparamsdictionary.CacheTodo: Should explain the necessary interface that the cache object
should have to comply with the api cache duck typing, as well as its
usageFor default value references, check the API documentation.