diff --git a/PyBambooHR/PyBambooHR.py b/PyBambooHR/PyBambooHR.py index dda5f88..be4d565 100644 --- a/PyBambooHR/PyBambooHR.py +++ b/PyBambooHR/PyBambooHR.py @@ -11,6 +11,7 @@ """ import datetime +import json import requests from . import utils from .utils import make_field_xml @@ -34,7 +35,7 @@ class PyBambooHR(object): and an optional datatype argument (defaults to JSON). This class implements methods for basic CRUD operations for employees and more. """ - def __init__(self, subdomain='', api_key='', datatype='JSON', underscore_keys=False): + def __init__(self, subdomain='', api_key='', onlyCurrent=True, datatype='JSON', underscore_keys=False): """ Using the subdomain, __init__ initializes the base_url for our API calls. This method also sets up some headers for our HTTP requests as well as our authentication (API key). @@ -70,6 +71,9 @@ def __init__(self, subdomain='', api_key='', datatype='JSON', underscore_keys=Fa # Some people will want to use underscore keys for employee data... self.underscore_keys = underscore_keys + # Ask BambooHR for information that is scheduled in the future + self.onlyCurrent = onlyCurrent + # We are focusing on JSON for now. if self.datatype == 'XML': raise NotImplemented("Returning XML is not currently supported.") @@ -166,6 +170,9 @@ def __init__(self, subdomain='', api_key='', datatype='JSON', underscore_keys=Fa "benefitClassDate": ("date", ""), "benefitClassClass": ("list", ""), "benefitClassChangeReason": ("list", ""), + "customOrientation": ("list", ""), + "customPreferredDoorDashEmail": ("text", ""), + "customTeam": ("text", "") } def _format_employee_xml(self, employee): @@ -293,6 +300,10 @@ def get_employee(self, employee_id, field_list=None): payload = { 'fields': ",".join(get_fields) } + if self.onlyCurrent == False: + payload.update({ + 'onlyCurrent': 'false' + }) url = self.base_url + "employees/{0}".format(employee_id) r = requests.get(url, headers=self.headers, params=payload, auth=(self.api_key, '')) @@ -401,7 +412,7 @@ def request_company_report(self, report_id, report_format='json', output_filenam raise UserWarning("You requested an invalid report type. Valid values are: {0}".format(','.join([k for k in self.report_formats]))) filter_duplicates = 'yes' if filter_duplicates else 'no' - url = self.base_url + "reports/{0}?format={1}&fd={2}".format(report_id, report_format, filter_duplicates) + url = self.base_url + "reports/{0}?format={1}&fd={2}&onlyCurrent={3}".format(report_id, report_format, filter_duplicates, self.onlyCurrent) r = requests.get(url, headers=self.headers, auth=(self.api_key, '')) r.raise_for_status() @@ -484,11 +495,19 @@ def get_tabular_data(self, table_name, employee_id='all'): @return A dictionary with employee ID as key and a list of dictionaries, each dictionary showing the values of the table's fields for a particular date, which is stored by key 'date' in the dictionary. """ + records = [] + url = self.base_url + 'employees/{}/tables/{}'.format(employee_id, table_name) r = requests.get(url, headers=self.headers, auth=(self.api_key, '')) r.raise_for_status() - return utils.transform_tabular_data(r.content) + data = json.loads(r.content.decode()) + + for row in data: + records.append(row[0]) + + #return utils.transform_tabular_data(r.content) + return records def get_employee_changes(self, since=None): """ diff --git a/README.md b/README.md index 2c019f3..0f27042 100644 --- a/README.md +++ b/README.md @@ -85,3 +85,11 @@ for employee in result['employees']: result = bamboo.request_company_report(1, format='pdf', output_file='/tmp/report.pdf', filter_duplicates=True) ``` +Getting information that is scheduled in the future + ```python + from PyBambooHR import PyBambooHR + + bamboo = PyBambooHR(subdomain='yoursub', api_key='yourapikeyhere', onlyCurrent=False) + + ``` + BambooHR has effective dates for when promotions are scheduled to happen or when new hires are going to join the organization. In order to see these events before they happen using the BambooHR API set `onlyCurrent` to `False`. As a note, this only works for pulling reports and getting employee information. This does not work on getting the employee directory.