Skip to content

Commit

Permalink
[IMP] prepared data
Browse files Browse the repository at this point in the history
  • Loading branch information
ovnicraft committed Nov 27, 2017
1 parent db5044f commit 5454256
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 21 deletions.
2 changes: 1 addition & 1 deletion requirements_dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ coverage==4.1
Sphinx==1.4.8
cryptography==1.7
PyYAML==3.11

git+https://github.com/ovnicraft/suds.git
18 changes: 8 additions & 10 deletions runa/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,22 @@
__email__ = 'cristian.salamea@gmail.com'
__version__ = '0.1.0'

# _____ _ _ _ _
# | __ \| | | | \ | | /\
# | |__) | | | | \| | / \
# | _ /| | | | . ` | / /\ \
# | | \ \| |__| | |\ |/ ____ \
# |_| \_\\____/|_| \_/_/ \_\
#


"""
Runa Library
~~~~~~~~~~~~
_____ _ _ _ _
| __ \| | | | \ | | /\
| |__) | | | | \| | / \
| _ /| | | | . ` | / /\ \
| | \ \| |__| | |\ |/ ____ \
|_| \_\\____/|_| \_/_/ \_\
Runa es una libreria para consumir los servicios web
del bus gubernamental de Ecuador de una manera *Pythonica*
>>> import runa
>>> r = runa.read_by_nui('0102030405')
>>> r = runa.busqueda_por_nui('0102030405')
>>> r.Nombre
PUJON JUAN
>>> print(r)
Expand Down
19 changes: 12 additions & 7 deletions runa/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
)
from .models import PreparedRuna

logger = logging.getLogger('suds')
logger = logging.getLogger('runa')


def login(WSDL):
Expand All @@ -46,14 +46,11 @@ def login(WSDL):


def _has_error(response):
if response.Error:
if not response.CodigoError == '000':
return '{0} {1}'.format(response.CodigoError, response.Error)


def read_by_nui(nui, mode='prod', authorized_nui=AUTHORIZED_NUI):
response, client = login(WS_CIUDADANO)
if not response:
return False
def create_tokens(response):
security = Security()
token = UsernameToken(AUTHORIZED_NUI)
token.setcreated(response.Fecha)
Expand All @@ -66,6 +63,14 @@ def read_by_nui(nui, mode='prod', authorized_nui=AUTHORIZED_NUI):
token_ts.created = response.Fecha
token_ts.expires = response.FechaF
security.tokens.append(token_ts)
return security


def read_by_nui(nui, mode='prod', authorized_nui=AUTHORIZED_NUI):
response, client = login(WS_CIUDADANO)
if not response:
return False
security = create_tokens(response)
client.set_options(wsse=security)

consulta_response = client.service.BusquedaPorNui(
Expand All @@ -84,4 +89,4 @@ def read_by_nui(nui, mode='prod', authorized_nui=AUTHORIZED_NUI):


def busqueda_por_nui(nui, mode='prod', authorized_nui=AUTHORIZED_NUI):
read_by_nui(nui, mode=mode, authorized_nui=authorized_nui)
return read_by_nui(nui, mode=mode, authorized_nui=authorized_nui)
32 changes: 29 additions & 3 deletions runa/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@
RUNA Models
"""
import logging
import json

logger = logging.getLogger('runa')


class PreparedRuna(object):

def __init__(self):
self.Calle = None
self.CodigoTipoCedulado = None
# self.CodigoTipoCedulado = None
self.CondicionCedulado = None
self.Conyuge = None
self.Domicilio = None
Expand Down Expand Up @@ -41,14 +44,37 @@ def __repr__(self):
return '<Runa [%s - %s]>' % (self.NUI, self.Nombre)

def json(self):
return json.dumps(self.__dict__)
return json.dumps(self.__dict__, indent=4)

def nui_is_valid(self):
""" Validate NUI """
pass
try:
import stdnum
except ImportError:
logger.warning("Warning: stdnum library not installed, can't validate.") # noqa
return False
return stdnum.ec.ci.is_valid(self.NUI)

def prepare(self, response):
""" Prepare given response data in object"""
self.Calle = response.Calle
# self.CodigoTipoCedulado = response.CodigoTipoCedulado
self.CondicionCedulado = response.CondicionCedulado
self.Conyuge = response.Conyuge
self.Domicilio = response.Domicilio
self.EstadoCivil = response.EstadoCivil
self.FechaCedulacion = response.FechaCedulacion
self.FechaNacimiento = response.FechaNacimiento
self.Instruccion = response.Instruccion
self.LugarNacimiento = response.LugarNacimiento
self.NUI = response.NUI
self.Nacionalidad = response.Nacionalidad
self.Nombre = response.Nombre
self.NombreMadre = response.NombreMadre
self.NombrePadre = response.NombrePadre
self.NumeroCasa = response.NumeroCasa
self.Profesion = response.Profesion
self.Sexo = response.Sexo
self.Genero = response.Genero
self.FechaInscripcionGenero = response.FechaInscripcionGenero
self.ValidNUI = True

0 comments on commit 5454256

Please sign in to comment.