-
Notifications
You must be signed in to change notification settings - Fork 5
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
Sdk update #428
Sdk update #428
Conversation
Merging to
|
script_cript.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.
This file should not be part of the of the PR
from cript.nodes.primary_nodes.project import Project | ||
from deepdiff import DeepDiff | ||
import cript |
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.
you can't import cript here.
That's a circular import.
Be specific and import exactly what you need.
@@ -48,6 +56,16 @@ def _get_global_cached_api(): | |||
return _global_cached_api | |||
|
|||
|
|||
# load from .env |
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.
not a good idea, this should be the API class.
@@ -484,6 +502,404 @@ def _check_initial_host_connection(self) -> None: | |||
except Exception as exc: | |||
raise CRIPTConnectionError(self.host, self._api_token) from exc | |||
|
|||
# ================ helpers ============== | |||
@classmethod | |||
def object_exists(cls, node: str, name: str): |
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.
use the api.search function to see if an object exist
return False, None | ||
|
||
@staticmethod | ||
def fetch_object_data(object_type: str, uuid: str): |
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.
should be through paginator and search.
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 realize, that this comment is not helpful at the moment, because I am refactoring the paginator.
but eventually, we should strive to not duplicate code paths that essentially do the same thing....
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.
@InnocentBug could you give a quick example where the call to the paginator would look like to retrieve an already existing node?
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.
Sure.
import cript
with cript.API() as cript_api: # Assumes you have the host and token in the environment.
# If you know its uuid
uuid_paginator = cript_api.search(node_type=cript.Project, search_mode=cript.SearchModes.UUID, value_to_search="e7381525-64b9-4849-a416-57aa1e09044f")
project = next(uuid_paginator)
print(project)
# if you know its name
exact_name_paginator = cript_api.search(node_type=cript.Material, search_mode=cript.SearchModes.EXACT_NAME, value_to_search="Sodium polystyrene sulfonate")
material = next(exact_name_paginator)
print(material)
return remaining_items | ||
|
||
@staticmethod | ||
def send_patch_request_for_node(parent_node=None, payload=None): # (self, base_url, entity_uuid, data, auth_token=None): |
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 should not be a public function.
Users should never call this function.
Also, shouldn't be a static function, host, header etc. should be loaded from api class.
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 think here i will implement the capsule to resolve this
return response | ||
|
||
@staticmethod | ||
def send_delete_request_for_node(parent_node=None, payload=None): # (self, base_url, entity_uuid, data, auth_token=None): |
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.
should be delete
function of API.
Also not a static function.
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.
same here - implement capsule
return response | ||
|
||
@staticmethod | ||
def find_uuid_by_name_and_type(name, node_type): |
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.
use search and paginator.
return None | ||
|
||
@classmethod | ||
def create_node(cls, node_type, data): |
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.
should not be public.
Maybe and should be capsuled in api.save
response = requests.post(url, json=data, headers=headers) | ||
return response | ||
|
||
@classmethod |
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.
not a pulic API class.
Maybe in api.utils as private function if needed.
Description
this allows nodes to be changed and saved based off the deep diff registry of changes
I will be updating the description on a more technical basis before merging
Changes
Known Issues
Notes
Checklist
CONTRIBUTORS.md
) in the pull request source branch.