diff --git a/README.md b/README.md index 07b9446..9729ae1 100644 --- a/README.md +++ b/README.md @@ -122,8 +122,7 @@ Return types based on implementation status of wrapped API endpoints ### [CoOrgIdentityLink API](https://spaces.at.internet2.edu/display/COmanage/CoOrgIdentityLink+API) (COmanage v4.0.0+) -- `coorg_identity_links_add() -> dict` - - `### NOT IMPLEMENTED ###` +- `coorg_identity_links_add(coperson_id: int, org_identity_id: int) -> dict` - Add a new CO Org Identity Link. - A person must have an Org Identity and a CO Person record before they can be linked. - Note that invitations are a separate operation. diff --git a/comanage_api/__init__.py b/comanage_api/__init__.py index 39118f1..d7b9af1 100644 --- a/comanage_api/__init__.py +++ b/comanage_api/__init__.py @@ -93,8 +93,8 @@ def __init__(self, co_api_url: str, co_api_user: str, co_api_pass: str, co_api_o self._s.auth = (self._CO_API_USER, self._CO_API_PASS) # CoOrgIdentityLink API - def coorg_identity_links_add(self): - return coorg_identity_links_add(self) + def coorg_identity_links_add(self, coperson_id: int, org_identity_id: int): + return coorg_identity_links_add(self, coperson_id=coperson_id, org_identity_id=org_identity_id) def coorg_identity_links_delete(self): return coorg_identity_links_delete(self) diff --git a/comanage_api/_coorgidentitylinks.py b/comanage_api/_coorgidentitylinks.py index 80d7b7a..a093184 100644 --- a/comanage_api/_coorgidentitylinks.py +++ b/comanage_api/_coorgidentitylinks.py @@ -5,8 +5,7 @@ Methods ------- -coorg_identity_links_add() -> dict - ### NOT IMPLEMENTED ### +coorg_identity_links_add(coperson_id: int, org_identity_id: int) -> dict Add a new CO Org Identity Link. A person must have an Org Identity and a CO Person record before they can be linked. Note that invitations are a separate operation. @@ -27,20 +26,65 @@ import json -def coorg_identity_links_add(self) -> dict: +def coorg_identity_links_add(self, coperson_id: int, org_identity_id: int) -> dict: """ - ### NOT IMPLEMENTED ### Add a new CO Org Identity Link. A person must have an Org Identity and a CO Person record before they can be linked. Note that invitations are a separate operation. - :param self: - :return - 501 Server Error: Not Implemented for url: mock://not_implemented_501.local: + coapi: COmanage API object + coperson_id: COmanage ID of CoPerson to link + orgidentity_id: COmanage ID of OrgIdentity to link + :request + { + "RequestType":"CoOrgIdentityLinks", + "Version":"1.0", + "CoOrgIdentityLinks": + [ + { + "Version":"1.0", + "CoPersonId":"", + "OrgIdentityId":"" + } + ] + }: + + Response Format + HTTP Status Response Body Description + 201 Added NewObjectResponse CoOrgIdentityLink created + 400 Bad Request CoOrgIdentityLink Request not + provided in POST body + 400 Invalid Fields ErrorResponse An error in one or more + provided fields + 401 Unauthorized Authentication required + 403 COPerson Does Not Exist The specified CO Person does not exist + 403 OrgIdentity Already Linked The specified Org Identity is already + a member of this CO + 403 OrgIdentity Does Not Exist The specified Org Identity does + not exist + 500 Other Error Unknown error """ - url = self._MOCK_501_URL - resp = self._mock_session.get( - url=url + post_body = { + "RequestType":"CoOrgIdentityLinks", + "Version":"1.0", + "CoOrgIdentityLinks": + [ + { + "Version":"1.0", + "CoPersonId":"", + "OrgIdentityId":"" + } + ] + } + + post_body['CoOrgIdentityLinks'][0]['CoPersonId'] = coperson_id + post_body['CoOrgIdentityLinks'][0]['OrgIdentityId'] = org_identity_id + + post_body = json.dumps(post_body) + url = self._CO_API_URL + '/co_org_identity_links.json' + resp = self._s.post( + url=url, + data=post_body ) if resp.status_code == 201: return json.loads(resp.text) diff --git a/examples/coorg_identity_links_example.py b/examples/coorg_identity_links_example.py index 52ff2bb..04425ad 100644 --- a/examples/coorg_identity_links_example.py +++ b/examples/coorg_identity_links_example.py @@ -12,14 +12,18 @@ # must be set ahead of time and be valid within the CO IDENTITY_TYPE = 'orgidentityid' IDENTITY_ID = 190 +CO_PERSON_ID = 163 # coorg_identity_links_add, coorg_identity_links_delete, coorg_identity_links_edit, \ # coorg_identity_links_view_all, coorg_identity_links_view_by_identity, coorg_identity_links_view_one -# coorg_identity_links_add() -> dict +# coorg_identity_links_add(coperson_id: int, org_identity_id: int) -> dict print('### coorg_identity_links_add') try: - new_coorg_identity_link = api.coorg_identity_links_add() + new_coorg_identity_link = api.coorg_identity_links_add( + coperson_id=CO_PERSON_ID, + org_identity_id=IDENTITY_ID + ) print(json.dumps(new_coorg_identity_link, indent=4)) except HTTPError as err: print('[ERROR] Exception caught')