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) office_url = self.get_office_url(require=require)
if office_url: if office_url:
return f'{office_url}/item/vendors/VendorIndexPage.php?vid={id}' 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 CORE-POS API
""" """
from requests.auth import HTTPDigestAuth import warnings
from corepos.api import CoreWebAPI
def make_corepos_api(config): def make_corepos_api(config):
""" """ DEPRECATED """
Make and return a new CORE-POS API client object. warnings.warn("make_corepos_api() function is deprecated; please use "
""" "app.get_corepos_handler().make_webapi() instead",
url = config.require('corepos.api', 'url') DeprecationWarning, stacklevel=2)
kwargs = {} app = config.get_app()
username = config.get('corepos.api', 'htdigest.username') return app.get_corepos_handler().make_webapi()
password = config.get('corepos.api', 'htdigest.password')
if username and password:
kwargs['htdigest_username'] = username
kwargs['htdigest_password'] = password
return CoreWebAPI(url, **kwargs)