Let config override the CORE API client factory

This commit is contained in:
Lance Edgar 2023-09-17 13:47:06 -05:00
parent f662b04ba3
commit 7dc09d0a2e
2 changed files with 27 additions and 15 deletions

View file

@ -24,22 +24,14 @@
CORE-POS API
"""
from requests.auth import HTTPDigestAuth
from corepos.api import CoreWebAPI
import warnings
def make_corepos_api(config):
"""
Make and return a new CORE-POS API client object.
"""
url = config.require('corepos.api', 'url')
""" DEPRECATED """
warnings.warn("make_corepos_api() function is deprecated; please use "
"app.get_corepos_handler().make_webapi() instead",
DeprecationWarning, stacklevel=2)
kwargs = {}
username = config.get('corepos.api', 'htdigest.username')
password = config.get('corepos.api', 'htdigest.password')
if username and password:
kwargs['htdigest_username'] = username
kwargs['htdigest_password'] = password
return CoreWebAPI(url, **kwargs)
app = config.get_app()
return app.get_corepos_handler().make_webapi()