Skip to content

Commit d8d418b

Browse files
authored
Merge pull request #76 from opengisch/QF-5886-adding_support_for_the_status_endpoint
Adding the support for the status endpoint
2 parents 7056a5d + 940905f commit d8d418b

2 files changed

Lines changed: 44 additions & 0 deletions

File tree

qfieldcloud_sdk/cli.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,28 @@ def logout(ctx):
177177
log(payload["detail"])
178178

179179

180+
@cli.command()
181+
@click.pass_context
182+
def status(ctx: Context):
183+
"""Check the status of the QFieldCloud server."""
184+
log("Checking server status...")
185+
client: sdk.Client = ctx.obj["client"]
186+
is_json: bool = ctx.obj["format_json"]
187+
188+
status_info = client.check_server_status()
189+
190+
if is_json:
191+
print_json(status_info)
192+
else:
193+
log(click.style("Server Status:", bold=True))
194+
195+
if isinstance(status_info, dict):
196+
for key, value in status_info.items():
197+
log(f" {key.replace('_', ' ').capitalize()}: {value}")
198+
else:
199+
log(str(status_info))
200+
201+
180202
@cli.command()
181203
@paginated
182204
@click.option(

qfieldcloud_sdk/sdk.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,28 @@ def logout(self) -> None:
326326

327327
return resp.json()
328328

329+
def check_server_status(self) -> Dict[str, Any]:
330+
"""Checks the status of the QFieldCloud server.
331+
332+
This endpoint usually provides information of the server health.
333+
334+
Returns:
335+
A dictionary containing the server status information (e.g., {"storage": "ok", ...}).
336+
337+
Example:
338+
```python
339+
client = sdk.Client(url="[https://app.qfield.cloud/api/v1/](https://app.qfield.cloud/api/v1/)")
340+
status = client.check_server_status()
341+
print(f"Server status: {status}")
342+
```
343+
"""
344+
resp = self._request(
345+
"GET",
346+
"status/",
347+
skip_token=True,
348+
)
349+
return resp.json()
350+
329351
def list_projects(
330352
self,
331353
include_public: bool = False,

0 commit comments

Comments
 (0)