Changeset - 5509089741dd
[Not reviewed]
0 1 0
Lance Edgar - 5 years ago 2020-03-15 19:29:01
lance@edbob.org
Add `get_customer()` API method
1 file changed with 24 insertions and 2 deletions:
0 comments (0 inline, 0 general) First comment
corepos/api.py
Show inline comments
 
@@ -75,7 +75,9 @@ class CoreWebAPI(object):
 
        specified, ``method`` will be CORE's ``FannieEntity`` webservice.
 
        """
 
        if not method:
 
            method = r'\COREPOS\Fannie\API\webservices\FannieEntity'
 
            method = 'FannieEntity'
 
        if '\\' not in method:
 
            method = r'\COREPOS\Fannie\API\webservices\{}'.format(method)
 

	
 
        payload = {
 
            'jsonrpc': '2.0',
 
@@ -91,7 +93,7 @@ class CoreWebAPI(object):
 
        response.raise_for_status()
 
        return response
 

	
 
    def parse_response(self, response):
 
    def parse_response(self, response, method=None):
 
        """
 
        Generic method to "parse" a response from the API.  Really this just
 
        converts the JSON to a dict (etc.), and then checks for error.  If an
 
@@ -105,10 +107,30 @@ class CoreWebAPI(object):
 
        if 'error' in js:
 
            raise CoreAPIError(js['error'])
 

	
 
        # note, the result data format may depend on the API method involved
 
        if method == 'FannieMember':
 
            return js['result']
 

	
 
        # assuming typical FannieEntity result here
 
        assert set(js.keys()) == set(['jsonrpc', 'id', 'result'])
 
        assert set(js['result'].keys()) == set(['result'])
 
        return js['result']['result']
 

	
 
    def get_customer(self, cardNo, **columns):
 
        """
 
        Fetch an existing Customer record from CORE.
 

	
 
        :returns: Either a customer dict record, or ``None``.
 
        """
 
        params = {
 
            'cardNo': cardNo,
 
            'method': 'get',
 
        }
 
        response = self.post(params, method='FannieMember')
 
        result = self.parse_response(response, method='FannieMember')
 
        if result:
 
            return result
 

	
 
    def get_departments(self, **columns):
 
        """
 
        Fetch some or all of Department records from CORE.
0 comments (0 inline, 0 general) First comment
You need to be logged in to comment. Login now