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

@ -104,3 +104,23 @@ class CoreHandler(GenericHandler):
office_url = self.get_office_url(require=require)
if office_url:
return f'{office_url}/item/vendors/VendorIndexPage.php?vid={id}'
def make_webapi(self):
"""
Make and return a new CORE-POS API client object.
"""
spec = self.config.get('corepos.api', 'factory',
default='corepos.api:CoreWebAPI')
factory = self.app.load_object(spec)
url = self.config.require('corepos.api', 'url')
kwargs = {}
username = self.config.get('corepos.api', 'htdigest.username')
password = self.config.get('corepos.api', 'htdigest.password')
if username and password:
kwargs['htdigest_username'] = username
kwargs['htdigest_password'] = password
return factory(url, **kwargs)

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()