Skip to content

Commit

Permalink
[IMP] api mas flexible para login en WS
Browse files Browse the repository at this point in the history
  • Loading branch information
ovnicraft committed Sep 6, 2018
1 parent e9f9f69 commit b87867b
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 17 deletions.
18 changes: 16 additions & 2 deletions runa/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
"""
import logging
from urllib.error import URLError

try:
from urllib.error import URLError
except ImportError:
from urllib2 import URLError

from suds.client import Client
from suds.wsse import Security, UsernameToken, Timestamp
Expand All @@ -20,7 +24,8 @@
USER,
PASSWORD,
CODAGENCIA,
CODINSTITUCION
CODINSTITUCION,
WS_ENABLED
)
from .models import PreparedRuna, PreparedContribuyente

Expand All @@ -46,6 +51,10 @@ def login(WSDL):
return response, client


def login_service(service='sri'):
return login(WS_ENABLED[service])


def _has_error(response):
if not response.CodigoError == '000':
return '{0} {1}'.format(response.CodigoError, response.Error)
Expand All @@ -67,6 +76,11 @@ def create_tokens(response):
return security


def set_token(response, client):
security = create_tokens(response)
client.set_options(wsse=security)


def read_by_nui(nui, mode='prod', authorized_nui=AUTHORIZED_NUI):
response, client = login(WS_CIUDADANO)
if not response:
Expand Down
33 changes: 30 additions & 3 deletions runa/utils.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,37 @@
# -*- coding: utf-8 -*-

import sys
import json
from pathlib import Path

import logging

logger = logging.getLogger(__name__)

CONFIG_FILE_NAME = '.runa.json'

CONFIG_FILE = '{0}/{1}'.format(str(Path.home()), CONFIG_FILE_NAME)

if not Path(CONFIG_FILE).is_file():
def get_home():
if sys.version_info[0] > 3:
from pathlib import Path
return str(Path.home())
else:
from os.path import expanduser
return expanduser('~')


def get_path(path_file):
if sys.version_info[0] > 2:
from pathlib import Path
return Path().is_file()
else:
import os
return os.path.isfile(path_file)


HOME = get_home()
CONFIG_FILE = '{0}/{1}'.format(HOME, CONFIG_FILE_NAME)

if not get_path(CONFIG_FILE):
mf = open(CONFIG_FILE, 'w')
json.dumps({}, mf)
mf.close()
Expand All @@ -37,3 +58,9 @@

def set_ws(mode='prod'):
WS_CIUDADANO = mode == 'prod' and WS_CIUDADANO_PRODUCTION or WS_CIUDADANO_TESTING # noqa


WS_ENABLED = {
'rcivil': WS_CIUDADANO,
'sri': WS_SRI
}
15 changes: 3 additions & 12 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,8 @@

"""The setup script."""

import sys

from setuptools import setup, find_packages

VERSION_REQUIRED = (3, 5)

if sys.version_info < VERSION_REQUIRED:
sys.exit('Python %s.%s is required' % VERSION_REQUIRED)

with open('README.rst') as readme_file:
readme = readme_file.read()

Expand All @@ -33,8 +26,7 @@

setup(
name='runa',
version='0.2.4',
python_requires='>=3.2',
version='0.2.5',
description="Librería para uso de WS del Bus Gubernamental de Ecuador",
long_description=readme + '\n\n' + history,
author="Cristian Salamea",
Expand All @@ -50,19 +42,18 @@
install_requires=requirements,
license="MIT license",
zip_safe=False,
keywords='runa',
keywords='runa webservices ecuador bgs',
classifiers=[
'Development Status :: 2 - Pre-Alpha',
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
'Natural Language :: English',
"Programming Language :: Python :: 2",
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
],
test_suite='tests',
tests_require=test_requirements,
Expand Down

0 comments on commit b87867b

Please sign in to comment.