Skip to content

Commit 2d6c74f

Browse files
authored
Merge pull request #65 from opengisch/adding_push_delta_method_on_cli_sdk
Adding CLI and SDK for push delta files
2 parents 8c7c1c0 + 8170eb1 commit 2d6c74f

2 files changed

Lines changed: 50 additions & 0 deletions

File tree

qfieldcloud_sdk/cli.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,22 @@ def job_status(ctx: Context, job_id):
460460
log(f'Job status for {job_id}: {status["status"]}')
461461

462462

463+
@cli.command(short_help="Push a delta file to a project.")
464+
@click.argument("project_id")
465+
@click.argument("delta_filename", type=click.Path(exists=True))
466+
@click.pass_context
467+
def delta_push(ctx: Context, project_id: str, delta_filename: str) -> None:
468+
"""Push a delta file to a project with PROJECT_ID."""
469+
log(f'Pushing delta file "{delta_filename}" to project "{project_id}"…')
470+
471+
response = ctx.obj["client"].push_delta(project_id, delta_filename)
472+
473+
if ctx.obj["format_json"]:
474+
print_json(response)
475+
else:
476+
log(f'Delta file "{delta_filename}" pushed to project "{project_id}".')
477+
478+
463479
@cli.command()
464480
@click.argument("project_id")
465481
@click.pass_context

qfieldcloud_sdk/sdk.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,20 @@ def is_empty(self) -> bool:
183183
return self.limit is None and self.offset is None
184184

185185

186+
class DeltaPushResponse(TypedDict):
187+
"""Represents the structure of the response for pushing a delta file.
188+
189+
Attributes:
190+
status: The status of the response.
191+
message: A message providing additional information about the response.
192+
details: Additional details about the delta push operation.
193+
"""
194+
195+
status: str
196+
message: Optional[str]
197+
details: Optional[Dict[str, Any]]
198+
199+
186200
class Client:
187201
"""The core component of the QFieldCloud SDK, providing methods for interacting with the QFieldCloud platform.
188202
@@ -617,6 +631,26 @@ def job_status(self, job_id: str) -> Dict[str, Any]:
617631

618632
return resp.json()
619633

634+
def push_delta(self, project_id: str, delta_filename: str) -> DeltaPushResponse:
635+
"""Push a delta file to a project.
636+
637+
Args:
638+
project_id: Project ID.
639+
delta_filename: Path to the delta JSON file.
640+
641+
Returns:
642+
A DeltaPushResponse containing the response from the server.
643+
"""
644+
with open(delta_filename, "r") as delta_file:
645+
files = {"file": delta_file}
646+
response = self._request(
647+
"POST",
648+
f"deltas/{project_id}/",
649+
files=files,
650+
)
651+
652+
return cast(DeltaPushResponse, response)
653+
620654
def delete_files(
621655
self,
622656
project_id: str,

0 commit comments

Comments
 (0)