This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
Project Description

Python module for the API provided by the Universidade Federal do Estado do Rio de Janeiro (UNIRIO) Please visit http://sistemas.unirio.br/api for futher information.

Installing

pip install unirio-api

File Structure

api/
├── 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.py

Tests

python -m unittest -v tests

UNIRIOAPIRequest

UNIRIOAPIRequest takes 2 arguments:

  • A valid APIKey that will be used for future requests
  • An APIServer that identify the server used to perform the requests
  • An integer identifier for the server used to perform requests. Default: APIServer.LOCAL (Local Server)

The Methods

The public module interface for interacting with the API methods is as follows:

def get(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 parameters
  • fields: The return fields for the request. A value of None is equal do requesting ALL the fields
def post(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.
def delete(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}
def put(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.

Usage

On your models, import UNIRIOAPIRequest and the enum APIServer and create an api object using your APIKey provided by http://sistemas.unirio.br/api

from unirio.api import UNIRIOAPIRequest, APIServer

api_key = 'afakehashusedforthisexample'
api = UNIRIOAPIRequest(api_key, APIServer.PRODUCTION)

Optional parameters are debug: boolean and cache. debug gives console verbosity and cache is used for caching in UNIRIOAPIRequest.get method.

get

path = '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.APIRestultObject

The get method also have an optional parameter cache_time, representing the cache expiration time in seconds, and defaults to 0, 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 same path, 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 to UNIRIOAPIRequest.get will return an APIResultObject wich is a model object and have the following attributes:

  • content: list: A list of dictionaries with the result of the GET request. If fields != None the dictionaries of the list will only contain the keys from the fields list.
  • lmin: int: The offset of the request result
  • lmax: int: The limit of the request result
  • fields: tuple: The list of endpoint fields that should be returned

Exceptions

  • NoContentException: Raised when the api returns a ‘content not found’ status code, and it means that no content was found for the given parameters.

post

path = '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.APIPOSTResponse

A method call to UNIRIOAPIRequest.post will return an APIPOSTResponse wich is a model object and have the following attributes:

  • insertId: int: Unique identifier created on the POST request.

Exceptions

  • InvalidParametersException:
  • ContentNotCreated:

put

path = 'PESSOAS'
params = {
    'ID_PESSOA': 345,
    'NOME_PESSOA': 'My new name'
}
result = api.put(path, params)  # type: unirio.api.result.APIPUTResponse

A method call to UNIRIOAPIRequest.put will return an APIPUTResponse wich is a model object and have the following attributes:

  • affectedRows: int: The number of rows affected by the PUT request.

Exceptions

  • ContentNotFoundException: Invalid unique identifier and nothing was updated
  • InvalidParametersException: One or more of the parameters has an incompatible type
  • NothingToUpdateException: No valid content passed on params and nothing was updated
  • MissingPrimaryKeyException: The unique identifier field isn’t a Key in the params dictionary.

delete

path = 'PESSOAS'
params = {'ID_PESSOA': 345}
result = api.delete(path, params)   # type: unirio.api.result.APIDELETEResponse

A method call to UNIRIOAPIRequest.delete will return an APIDELETEResponse wich is a model object and have the following attributes:

  • affectedRows: int: The number of rows affected by the DELETE request.

Exceptions

  • ContentNotFoundException: Invalid unique identifier and nothing was updated
  • NothingToUpdateException:
  • MissingPrimaryKeyException: The unique identifier field isn’t a Key in the params dictionary.

Common Exceptions

  • ForbiddenEndpointException: The API Key doens’t have permission to perform the request on the path endpoint
  • InvalidAPIKeyException: The API Key used is invalid or inactive
  • UnhandledAPIException: Something unexpected happened on the server side
  • InvalidEndpointException: The endpoint path doesn’t exist. Check the list of endpoint on the main page of http://sistemas.unirio.br/api
  • InvalidParametersException: The request was performed with invalid params and shouldn’t be repeated used the same params. That exception object has an invalid_parameters attribute, wich is a list of the invalid keys on params dictionary.

Cache

Todo: Should explain the necessary interface that the cache object should have to comply with the api cache duck typing, as well as its usage

  • For default value references, check the API documentation.
Release History

Release History

1.1.1

This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

1.1.0

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

1.0.2

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

1.0.1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

1.0.0

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
unirio_api-1.1.1-py2.py3-none-any.whl (14.4 kB) Copy SHA256 Checksum SHA256 2.7 Wheel Jul 5, 2016
unirio-api-1.1.1.tar.gz (12.6 kB) Copy SHA256 Checksum SHA256 Source Jul 5, 2016

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS HPE HPE Development Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting