-
Notifications
You must be signed in to change notification settings - Fork 0
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
Conversation
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ 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 |
|
|
bamboosdk/__init__.py
Outdated
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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
bamboosdk/api/api_base.py
Outdated
|
||
headers = { | ||
"content-type": "application/json", | ||
"authorization": f"Basic {self.__encode_username_password()}" |
There was a problem hiding this comment.
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
bamboosdk/api/api_base.py
Outdated
"authorization": f"Basic {self.__encode_username_password()}" | ||
} | ||
|
||
payload = { "fields": ["displayName", "firstName", "lastName", "department", "workEmail", "supervisorEmail", "status"] } |
There was a problem hiding this comment.
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
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) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
bamboosdk/api/api_base.py
Outdated
self.__api_token = None | ||
self.__sub_domain = None | ||
|
||
def _post_request(self, module_api_path): |
There was a problem hiding this comment.
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
|
bamboosdk/api/api_base.py
Outdated
@@ -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') |
There was a problem hiding this comment.
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
|
|
|
* 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
|
No description provided.