forked from CMS/memberPlumbing
lib/MembershipWorks: Allow getting both CSV and json transactions data
This commit is contained in:
parent
06516ad0cd
commit
a201b9f09c
@ -182,19 +182,25 @@ class MembershipWorks:
|
|||||||
raise MembershipWorksRemoteError('csv generation', r)
|
raise MembershipWorksRemoteError('csv generation', r)
|
||||||
return list(csv.DictReader(StringIO(r.text)))
|
return list(csv.DictReader(StringIO(r.text)))
|
||||||
|
|
||||||
# TODO: doesn't return as much info as csv?
|
def get_transactions(self, start_date, end_date, json=False):
|
||||||
def get_transactions(self, start_date, end_date):
|
|
||||||
"""Get the transactions between start_date and end_date
|
"""Get the transactions between start_date and end_date
|
||||||
Dates can be datetime.date or datetime.datetime"""
|
|
||||||
|
Dates can be datetime.date or datetime.datetime
|
||||||
|
|
||||||
|
json gets a different version of the transactions list,
|
||||||
|
which contains a different set information
|
||||||
|
"""
|
||||||
r = self._get(BASE_URL + "csv",
|
r = self._get(BASE_URL + "csv",
|
||||||
params={'crm': '12,13,14,18,19', # transaction types, see CRM
|
params={'crm': '12,13,14,18,19', # transaction types, see CRM
|
||||||
'txl': '', # changes output type?
|
**({'txl': ''} if json else {}),
|
||||||
# without this, returns a csv with more info
|
|
||||||
'sdp': start_date.strftime('%s'),
|
'sdp': start_date.strftime('%s'),
|
||||||
'edp': end_date.strftime('%s')})
|
'edp': end_date.strftime('%s')})
|
||||||
if r.status_code != 200:
|
if r.status_code != 200:
|
||||||
raise MembershipWorksRemoteError('csv generation', r)
|
raise MembershipWorksRemoteError('csv generation', r)
|
||||||
|
if json:
|
||||||
return r.json()
|
return r.json()
|
||||||
|
else:
|
||||||
|
return list(csv.DictReader(StringIO(r.text)))
|
||||||
|
|
||||||
def get_all_members(self):
|
def get_all_members(self):
|
||||||
"""Get all the data for all the members"""
|
"""Get all the data for all the members"""
|
||||||
|
Loading…
Reference in New Issue
Block a user