Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

add a delete method for employee file #48

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
22 changes: 18 additions & 4 deletions PyBambooHR/PyBambooHR.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ def _format_row_xml(self, row):
@param employee: Dictionary containing row data information.
"""
xml_fields = ''
for k, v in row.iteritems():
for k, v in row.items():
xml_fields += make_field_xml(k, v, pre='\t', post='\n')

xml = "<row>\n{}</row>".format(xml_fields)
Expand Down Expand Up @@ -401,9 +401,9 @@ def get_employee_files(self, employee_id):
url = self.base_url + "employees/{0}/files/view/".format(employee_id)
r = requests.get(url, timeout=self.timeout, headers=self.headers, auth=(self.api_key, ''))
r.raise_for_status()
data = utils.transform_table_data(r.content)
data = r.json()

return data['employee']
return data

def upload_employee_file(self, employee_id, file_path, category_id, share, override_file_name=None):
"""
Expand All @@ -419,7 +419,7 @@ def upload_employee_file(self, employee_id, file_path, category_id, share, overr
file_name = override_file_name if override_file_name else basename(file_path)

with open(file_path, "rb") as f:
params = {"file": f,
params = {"file": (file_name, f, 'application/pdf'),
"fileName": (None, file_name),
"category": (None, str(category_id)),
"share": (None, "yes" if share else "no")}
Expand All @@ -429,6 +429,20 @@ def upload_employee_file(self, employee_id, file_path, category_id, share, overr
r.raise_for_status()
return True

def delete_employee_file(self, employee_id, file_id):
"""
API method to delete a file data for an employee

@param employee_id: String of the employee id.
@param file_id: String of the file id.
"""

url = self.base_url + "employees/{0}/files/{1}/".format(employee_id, file_id)
r = requests.delete(url, timeout=self.timeout, headers=self.headers, auth=(self.api_key, ''))
r.raise_for_status()

return True

def add_row(self, table_name, employee_id, row):
"""
API method for adding a row to a table
Expand Down