Add make_corepos_api() convenience function

This commit is contained in:
Lance Edgar 2021-02-09 14:28:38 -06:00
parent 67618d4784
commit 1be258246c
4 changed files with 43 additions and 13 deletions

View file

@ -0,0 +1,35 @@
# -*- coding: utf-8; -*-
################################################################################
#
# Rattail -- Retail Software Framework
# Copyright © 2010-2021 Lance Edgar
#
# This file is part of Rattail.
#
# Rattail is free software: you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your option) any later
# version.
#
# Rattail is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# Rattail. If not, see <http://www.gnu.org/licenses/>.
#
################################################################################
"""
CORE-POS API
"""
from corepos.api import CoreWebAPI
def make_corepos_api(config):
"""
Make and return a new CORE-POS API client object.
"""
url = config.require('corepos.api', 'url')
return CoreWebAPI(url)

View file

@ -2,7 +2,7 @@
################################################################################
#
# Rattail -- Retail Software Framework
# Copyright © 2010-2020 Lance Edgar
# Copyright © 2010-2021 Lance Edgar
#
# This file is part of Rattail.
#
@ -24,11 +24,10 @@
CORE-POS model importers (webservices API)
"""
from corepos.api import CoreWebAPI
from rattail import importing
from rattail.util import data_diffs
from rattail_corepos.corepos.util import get_core_members
from rattail_corepos.corepos.api import make_corepos_api
class ToCoreAPI(importing.Importer):
@ -46,8 +45,7 @@ class ToCoreAPI(importing.Importer):
self.establish_api()
def establish_api(self):
url = self.config.require('corepos.api', 'url')
self.api = CoreWebAPI(url)
self.api = self.make_corepos_api(self.config)
def ensure_fields(self, data):
"""