Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bamboo sdk base api class #97

Merged
merged 8 commits into from
Dec 20, 2023
Merged

Bamboo sdk base api class #97

merged 8 commits into from
Dec 20, 2023

Conversation

Ashutosh619-sudo
Copy link
Contributor

No description provided.

Copy link

Tests Skipped Failures Errors Time
45 1 💤 0 ❌ 0 🔥 2.862s ⏱️

Copy link

codecov bot commented Dec 11, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (3812a71) 94.88% compared to head (6788d58) 94.47%.
Report is 5 commits behind head on master.

❗ Current head 6788d58 differs from pull request most recent head 5867d4b. Consider uploading reports for the commit 5867d4b to get more accurate results

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #97      +/-   ##
==========================================
- Coverage   94.88%   94.47%   -0.42%     
==========================================
  Files          29       30       +1     
  Lines         958     1031      +73     
==========================================
+ Hits          909      974      +65     
- Misses         49       57       +8     

see 4 files with indirect coverage changes

Copy link

Tests Skipped Failures Errors Time
45 1 💤 0 ❌ 0 🔥 2.259s ⏱️

Copy link

Tests Skipped Failures Errors Time
45 1 💤 0 ❌ 0 🔥 2.741s ⏱️

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Ashutosh619-sudo we can create a new folders called connectors
and moved this inside that folder and name it bamboohr

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is fine for now, connectors sounds very generic. We'll just assume we've kept the SDK folder inside API, that's it.

"""


class BambooHrSDKError(Exception):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Ashutosh619-sudo make sure this contains all the errors


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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of encoding every time, let's do it in line 63 so that it's done only once per SDK initialise

"authorization": f"Basic {self.__encode_username_password()}"
}

payload = { "fields": ["displayName", "firstName", "lastName", "department", "workEmail", "supervisorEmail", "status"] }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if this is common for every API placing here is fine, else move this to resource class

Comment on lines +38 to +48
if response.status_code == 403:
error_msg = json.loads(response.text)
raise NoPrivilegeError('Forbidden, the user has insufficient privilege', error_msg)

if response.status_code == 404:
error_msg = json.loads(response.text)
raise NotFoundItemError('Not found item with ID', error_msg)

if response.status_code == 401:
error_msg = 'The api token is invalid'
raise InvalidTokenError('Invalid token, try to refresh it', error_msg)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

checkout docs once and see if these status codes are expected, also in the end add raise 1 exception to handle status codes that are not handled above, 5xx for example

Copy link
Contributor Author

@Ashutosh619-sudo Ashutosh619-sudo Dec 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i have checked the docs these are the errors there

raise InvalidTokenError('Invalid token, try to refresh it', error_msg)


def __encode_username_password(self):
Copy link
Collaborator

@NileshPant1999 NileshPant1999 Dec 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are we encoding and decoding it again

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the method b64encode converts the string to base64 byte code which doesn't work when sending in the header and the encoding it done on the this 'byte' its only making that to base64 string.

self.__api_token = None
self.__sub_domain = None

def _post_request(self, module_api_path):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we'll need a new func for generator too

Copy link

Tests Skipped Failures Errors Time
45 1 💤 0 ❌ 0 🔥 2.472s ⏱️

@@ -47,6 +44,10 @@ def _post_request(self, module_api_path):
error_msg = 'The api token is invalid'
raise InvalidTokenError('Invalid token, try to refresh it', error_msg)

else:
error_msg = 'Something went wrong'
raise Exception('Something went wrong')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

send response.text to the exception, also create 1 exception, something like BambooHRSDKError() instead of generic one

Copy link

Tests Skipped Failures Errors Time
45 1 💤 0 ❌ 0 🔥 2.602s ⏱️

Copy link

Tests Skipped Failures Errors Time
45 1 💤 0 ❌ 0 🔥 2.773s ⏱️

Copy link

Tests Skipped Failures Errors Time
45 1 💤 0 ❌ 0 🔥 2.785s ⏱️

* class to sync employees from bamboo hr

* bug fix

* minor changes

* comment resolved

* minor changes

* Bamboo sdk class (#99)

* bamboo sdk class

* comment resolved

* Webhook create and delete API  (#108)

* webhook api added

* indentation fixed

* indentaion fixed

* minor fix

* Fields get API (#109)

* Fields get API

* added timeoff instead of fields and tested
Copy link

Tests Skipped Failures Errors Time
45 1 💤 0 ❌ 0 🔥 2.588s ⏱️

@Ashutosh619-sudo Ashutosh619-sudo merged commit 6fd47e9 into master Dec 20, 2023
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants