Skip to content

Commit

Permalink
get_employee_picture using Employee object or ID
Browse files Browse the repository at this point in the history
  • Loading branch information
klamann committed Sep 9, 2020
1 parent d7720d1 commit 2bb8a03
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
9 changes: 6 additions & 3 deletions src/personio_py/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,16 +225,19 @@ def get_employee(self, employee_id: int) -> Employee:
employee = Employee.from_dict(response['data'], self)
return employee

def get_employee_picture(self, employee_id: int, width: int = None) -> Optional[bytes]:
def get_employee_picture(self, employee: Union[int, Employee], width: int = None) \
-> Optional[bytes]:
"""
Get the profile picture of the employee with the specified ID as image file
Get the profile picture of the specified employee as image file
(usually png or jpg).
:param employee_id: the Personio ID of the employee to fetch
:param employee: get the picture of this employee or the employee with
the specified Personio ID
:param width: optionally scale the profile picture to this width.
Defaults to the original width of the profile picture.
:return: the profile picture as png or jpg file (bytes)
"""
employee_id = employee.id_ if isinstance(employee, Employee) else int(employee)
path = f'company/employees/{employee_id}/profile-picture'
if width:
path += f'/{width}'
Expand Down
2 changes: 1 addition & 1 deletion src/personio_py/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,7 @@ def _update(self, client: 'Personio' = None):
def picture(self, client: 'Personio' = None, width: int = None) -> bytes:
if self._picture is None:
client = get_client(self, client)
self._picture = client.get_employee_picture(self.id_, width=width)
self._picture = client.get_employee_picture(self, width=width)
return self._picture

def __str__(self):
Expand Down

0 comments on commit 2bb8a03

Please sign in to comment.