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)