Beispiel #1
0
    def get_user_directory(self):
        """
        API method for returning all users in the Bamboo system. This includes terminated employees.
        http://www.bamboohr.com/api/documentation/metadata.php#getUsers

        @return: A list of employee dictionaries which is a list of employees in the directory.
        """
        url = self.base_url + "meta/users"
        got_directory = False
        failed_attempts = 0
        while not got_directory and failed_attempts < 10:
            try:
                r = requests.get(url, headers=self.headers, auth=(self.api_key, 'x'))
                got_directory = True
            except:
                time.sleep(3)
        if failed_attempts >= 10:
            raise Exception("Failed trying to get user directory")
        r.raise_for_status()

        data = r.json().values()
        users = filter(lambda x: x["employeeId"], data)
        if self.underscore_keys:
            users = [utils.underscore_keys(employee) for employee in users]

        return users
Beispiel #2
0
    def get_employee(self, employee_id, field_list=None):
        """
        API method for returning a single employee based on employee id.
        http://www.bamboohr.com/api/documentation/employees.php#getEmployee

        @param employee_id: String of the employee id.
        @param field_list: List of fields to return with the employee dictionary.
        @return: A dictionary containing employee information from the specified field list.
        """
        get_fields = []

        field_list = [utils.underscore_to_camelcase(field) for field in field_list] if field_list else None

        if field_list:
            for f in field_list:
                get_fields.append(f)
        else:
            for field in self.employee_fields:
                get_fields.append(field)

        payload = {
            'fields': ",".join(get_fields)
        }

        url = self.base_url + "employees/{0}".format(employee_id)
        r = requests.get(url, headers=self.headers, params=payload, auth=(self.api_key, 'x'))
        r.raise_for_status()

        employee = r.json()

        if self.underscore_keys:
            employee = utils.underscore_keys(employee)

        return employee
Beispiel #3
0
    def get_employee_directory(self):
        """
        API method for returning a globally shared company directory.
        http://www.bamboohr.com/api/documentation/employees.php#getEmployeeDirectory

        @return: A list of employee dictionaries which is a list of employees in the directory.
        """
        url = self.base_url + 'employees/directory'
        r = requests.get(url, headers=self.headers, auth=(self.api_key, 'x'))
        r.raise_for_status()

        data = r.json()
        employees = data['employees']
        if self.underscore_keys:
            employees = [utils.underscore_keys(employee) for employee in employees]

        return employees