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

20 sdk enhancements #27

Merged
merged 3 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 36 additions & 1 deletion javelin_sdk/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ def _prepare_request(self, request: Request) -> tuple:
secret_name=request.secret,
template_name=request.template,
query=request.is_query,
archive=request.archive,
query_params=request.query_params,
)
headers = {**self._headers, **(request.headers or {})}
return url, headers
Expand Down Expand Up @@ -116,6 +118,8 @@ def _construct_url(
secret_name: Optional[str] = "",
template_name: Optional[str] = "",
query: bool = False,
archive: Optional[str] = "",
query_params: Optional[Dict[str, Any]] = None,
) -> str:
url_parts = [self.base_url]

Expand Down Expand Up @@ -148,9 +152,20 @@ def _construct_url(
url_parts.extend(["admin", "processors", "dp", "templates"])
if template_name != "###":
url_parts.append(template_name)
elif archive:
url_parts.extend(["admin", "archives"])
if archive != "###":
url_parts.append(archive)
else:
url_parts.extend(["admin", "routes"])
return "/".join(url_parts)

url = "/".join(url_parts)

if query_params:
query_string = "&".join(f"{k}={v}" for k, v in query_params.items())
url += f"?{query_string}"

return url

# Gateway methods
create_gateway = lambda self, gateway: self.gateway_service.create_gateway(gateway)
Expand Down Expand Up @@ -292,3 +307,23 @@ def _construct_url(
strategy_name
)
)

# Archive methods
def get_last_n_chronicle_records(self, archive_name: str, n: int) -> Dict[str, Any]:
request = Request(
method=HttpMethod.GET,
archive=archive_name,
query_params={"page": 1, "limit": n}
)
response = self._send_request_sync(request)
print(response)
return response

async def aget_last_n_chronicle_records(self, archive_name: str, n: int) -> Dict[str, Any]:
request = Request(
method=HttpMethod.GET,
archive=archive_name,
query_params={"page": 1, "limit": n}
)
response = await self._send_request_async(request)
return response
4 changes: 4 additions & 0 deletions javelin_sdk/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,8 @@ def __init__(
is_query: bool = False,
data: Optional[Dict[str, Any]] = None,
headers: Optional[Dict[str, str]] = None,
archive: Optional[str] = "",
query_params: Optional[Dict[str, Any]] = None,
):
self.method = method
self.gateway = gateway
Expand All @@ -342,3 +344,5 @@ def __init__(
self.is_query = is_query
self.data = data
self.headers = headers
self.archive = archive
self.query_params = query_params
4 changes: 4 additions & 0 deletions javelin_sdk/services/template_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def create_template(self, template: Template) -> str:
method=HttpMethod.POST, template=template.name, data=template.dict()
)
)
self.reload_data_protection(template.name)
return self._process_template_response_ok(response)

async def acreate_template(self, template: Template) -> str:
Expand All @@ -56,6 +57,7 @@ async def acreate_template(self, template: Template) -> str:
method=HttpMethod.POST, template=template.name, data=template.dict()
)
)
await self.areload_data_protection(template.name)
return self._process_template_response_ok(response)

def get_template(self, template_name: str) -> Template:
Expand Down Expand Up @@ -100,12 +102,14 @@ def update_template(self, template: Template) -> str:
response = self.client._send_request_sync(
Request(method=HttpMethod.PUT, template=template.name, data=template.dict())
)
self.reload_data_protection(template.name)
return self._process_template_response_ok(response)

async def aupdate_template(self, template: Template) -> str:
response = await self.client._send_request_async(
Request(method=HttpMethod.PUT, template=template.name, data=template.dict())
)
await self.areload_data_protection(template.name)
return self._process_template_response_ok(response)

def delete_template(self, template_name: str) -> str:
Expand Down