Skip to content

Commit

Permalink
Ready View for making sure bamboohr Creds are valid
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashutosh619-sudo committed Dec 27, 2023
1 parent 14e9bee commit 29a9adf
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
3 changes: 2 additions & 1 deletion apps/bamboohr/urls.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from django.urls import path

from .views import PostFolder, PostPackage, BambooHrConnection, BambooHrView, BambooHrConfigurationView, \
DisconnectView, SyncEmployeesView
DisconnectView, SyncEmployeesView, BambooHrReadyView

app_name = 'bamboohr'

urlpatterns = [
path('ready/', BambooHrReadyView.as_view(), name='ready'),
path('', BambooHrView.as_view(), name='bamboohr'),
path('packages/', PostPackage.as_view(), name='package'),
path('folder/', PostFolder.as_view(), name='folder'),
Expand Down
30 changes: 30 additions & 0 deletions apps/bamboohr/views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
from bamboosdk.bamboohrsdk import BambooHrSDK

from rest_framework.response import Response
from rest_framework.views import status
Expand All @@ -12,9 +13,38 @@
from apps.bamboohr.actions import disconnect_bamboohr, sync_employees
from apps.names import BAMBOO_HR

from rest_framework.views import APIView

logger = logging.getLogger(__name__)
logger.level = logging.INFO

class BambooHrReadyView(generics.ListAPIView):

def get(self, request, *args, **kwargs):
try:
# bamboohr = BambooHr.objects.get(org_id__in=[kwargs['org_id']])
bamboohrsdk = BambooHrSDK(api_token='864acbfb14b38f974439af49ec95bc02e52a45b9', sub_domain='baba')
response = bamboohrsdk.time_off.get()

if response['timeOffTypes']:
return Response(
data = {
'message': 'Ready'
},
status=status.HTTP_200_OK
)
else:
return Response(
data = {
'message': 'Invalid token'
},
status=status.HTTP_400_BAD_REQUEST
)
except BambooHr.DoesNotExist:
return Response(
data={'message': 'Bamboo HR Details Not Found'},
status=status.HTTP_404_NOT_FOUND
)

class BambooHrView(generics.ListAPIView):
serializer_class = BambooHrSerializer
Expand Down

0 comments on commit 29a9adf

Please sign in to comment.