Add get_customer()
API method
This commit is contained in:
parent
2d0cfa30ca
commit
5509089741
|
@ -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.
|
||||
|
|
Loading…
Reference in a new issue