Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,7 @@ ENTITY_OPTIONS = ['codeptid', 'cogroupid', 'copersonid', 'organizationid', 'orgi

### <a name="name"></a>[Name API](https://spaces.at.internet2.edu/display/COmanage/Name+API) (COmanage v3.3.0+)

- `names_add() -> dict`
- `### NOT IMPLEMENTED ###`
- `names_add(person_type: str, person_id: int, given: str, family: str) -> dict`
- Add a new Name.
- `names_delete() -> bool`
- `### NOT IMPLEMENTED ###`
Expand Down
4 changes: 2 additions & 2 deletions comanage_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,8 @@ def identifiers_view_one(self, identifier_id: int):
return identifiers_view_one(self, identifier_id=identifier_id)

# Name API
def names_add(self):
return names_add(self)
def names_add(self, person_type: str, person_id: int, given: str, family: str):
return names_add(self, person_type=person_type, person_id=person_id, given=given, family=family)

def names_delete(self):
return names_delete(self)
Expand Down
91 changes: 80 additions & 11 deletions comanage_api/_names.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@

Methods
-------
names_add() -> dict
### NOT IMPLEMENTED ###
names_add(person_type: str, person_id: int, given: str, family: str) -> dict
Add a new Name.
names_delete() -> bool
### NOT IMPLEMENTED ###
Expand All @@ -25,18 +24,88 @@
import json


def names_add(self) -> dict:
def names_add(self, person_type: str, person_id: int, given: str, family: str) -> dict:
"""
### NOT IMPLEMENTED ###
Add a new Name.
Add a new Name.

:param self:
:return
501 Server Error: Not Implemented for url: mock://not_implemented_501.local:
person_type: Type of person (i.e. "CO"|"Org")
person_id: COmanage ID for the person_type
given: First name for the person
family: Last name for the person
:request
{
"RequestType":"Names",
"Version":"1.0",
"Names":
[
{
"Version":"1.0",
"Honorific":"<Honorific>",
"Given":"<Given>",
"Middle":"<Middle>",
"Family":"<Family>",
"Suffix":"<Suffix>",
"Type":"<Type>",
"Language":"<Language>",
"PrimaryName":true|false,
"Person":
{
"Type":("CO"|"Org"),
"Id":"<ID>"
}
}
]
}:

Response Format
HTTP Status Response Body Description
201 Added NewObjectResponse Name added
400 Bad Request Name Request not
provided in POST body
400 Invalid Fields ErrorResponse An error in one or more
provided fields
401 Unauthorized Authentication required
403 No Person Specified Either a CO Person or an Org Identity
must be specified to attach the
Name to
403 Person Does Not Exist The specified CO Person or
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":"Names",
"Version":"1.0",
"Names":
[
{
"Version":"1.0",
"Honorific":"",
"Given":"<Given>",
"Middle":"",
"Family":"<Family>",
"Suffix":"",
"Type":"official",
"Language":"",
"PrimaryName": True,
"Person":
{
"Type":"<Type>",
"Id":"<ID>"
}
}
]
}

post_body['Names'][0]['Given'] = given
post_body['Names'][0]['Family'] = family
post_body['Names'][0]['Person']['Type'] = person_type
post_body['Names'][0]['Person']['Id'] = person_id

post_body = json.dumps(post_body)
url = self._CO_API_URL + '/names.json'
resp = self._s.post(
url=url,
data=post_body
)
if resp.status_code == 201:
return json.loads(resp.text)
Expand Down
9 changes: 7 additions & 2 deletions examples/names_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,15 @@
# must be set ahead of time and be valid within the CO
CO_PERSON_ID = 163

# names_add() -> dict
# names_add(person_type: str, person_id: int, given: str, family: str) -> dict
print('### names_add')
try:
new_name = api.names_add()
new_name = api.names_add(
person_type='copersonid',
person_id=CO_PERSON_ID,
given="TestGiven",
family="TestFamily"
))
print(json.dumps(new_name, indent=4))
except HTTPError as err:
print('[ERROR] Exception caught')
Expand Down