Skip to content

Commit

Permalink
Webhook create and delete API (#108)
Browse files Browse the repository at this point in the history
* webhook api added

* indentation fixed

* indentaion fixed

* minor fix

* Fields get API (#109)

* Fields get API

* added timeoff instead of fields and tested
  • Loading branch information
Ashutosh619-sudo authored Dec 20, 2023
1 parent 2a729af commit 100ce17
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 2 deletions.
5 changes: 3 additions & 2 deletions bamboosdk/api/api_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,9 @@ def set_api_token(self, api_token):
self.__api_token = api_token

self.headers = {
"content-type": "application/json",
"authorization": f"Basic {self.__encode_username_password()}"
'Accept': 'application/json',
'content-type': 'application/json',
'authorization': f'Basic {self.__encode_username_password()}'
}

def set_sub_domain(self, sub_domain):
Expand Down
12 changes: 12 additions & 0 deletions bamboosdk/api/time_off.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from .api_base import ApiBase

class TimeOff(ApiBase):
CHECK_URL = '/v1/meta/time_off/types/'

def get(self):
"""
Get method to get the different fields,
used here for checking connection.
Returns:
"""
return self._get_request(self.CHECK_URL)
22 changes: 22 additions & 0 deletions bamboosdk/api/webhook.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from .api_base import ApiBase


class Webhook(ApiBase):
""" Class for webhook APIs for bamboohr """

POST_WEBHOOK = '/v1/webhooks/'
DELETE_WEBHOOK = '/v1/webhooks/{}'

def post(self, payload):
"""
Post webhook url to bamboohr for employee update or create
Returns:
"""
return self._post_request(self.POST_WEBHOOK, payload)

def delete(self, id):
"""
Delete Webhook
Returns:
"""
return self._delete_request(self.DELETE_WEBHOOK.format(id))
21 changes: 21 additions & 0 deletions bamboosdk/bamboohrsdk.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from .api.employee import Employee
from .api.webhook import Webhook
from .api.time_off import TimeOff

class BambooHrSDK:
"""
Expand All @@ -14,5 +16,24 @@ def __init__(self, api_token: str, sub_domain: str):
self.__sub_domain = sub_domain

self.employees = Employee()
self.webhook = Webhook()
self.time_off = TimeOff()

self.set_api_token()
self.set_sub_domain()

def set_api_token(self):
"""
Set the api token for all the APIs
"""
self.employees.set_api_token(self.__api_token)
self.webhook.set_api_token(self.__api_token)
self.time_off.set_api_token(self.__api_token)

def set_sub_domain(self):
"""
Set sub domain for all the APIs
"""
self.employees.set_sub_domain(self.__sub_domain)
self.webhook.set_sub_domain(self.__sub_domain)
self.time_off.set_sub_domain(self.__sub_domain)

0 comments on commit 100ce17

Please sign in to comment.