Skip to content

Instantly share code, notes, and snippets.

@ankona
Created July 27, 2016 21:18
Show Gist options
  • Save ankona/a1837a28a9e6a1253ca7fc91b0318411 to your computer and use it in GitHub Desktop.
Save ankona/a1837a28a9e6a1253ca7fc91b0318411 to your computer and use it in GitHub Desktop.
get_orgunits_properties from bspace valence API
def get_orgunits_properties(uc,org_unit_type_id=None,org_unit_code=None,org_unit_name=None,bookmark=None,ver='1.3',**kwargs):
"""
Custom method hitting Brightspace Valence API. Request to add to service.py in d2lvalence_util submitted; consider removal.
"""
route = '/d2l/api/lp/{0}/orgstructure/'.format(ver)
kwargs.setdefault('params', {})
if org_unit_type_id:
kwargs['params'].update({'orgUnitType': org_unit_type_id})
if org_unit_code:
kwargs['params'].update({'orgUnitCode': org_unit_code})
if org_unit_name:
kwargs['params'].update({'orgUnitName': org_unit_name})
if bookmark:
kwargs['params'].update({'bookmark': bookmark})
try:
r = d2lservice._get(route,uc,**kwargs)
except requests.ConnectionError as e:
logger.exception(e)
raise BadRequestException("Org Unit retrieval failed. Endpoint not found.")
except requests.HTTPError as e:
logger.exception(e)
if e.response.status_code == 403:
raise BspaceAuthException("Unable to authenticate.")
else:
raise BadRequestException("Unable to request org units. An unexpected error occurred.")
result = []
for i in range(len(r["Items"])):
result.append(d2ldata.OrgUnit(r["Items"][i]))
return result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment