Skip to content
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
2 changes: 1 addition & 1 deletion spec/openapi.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
openapi: 3.0.0
info:
title: YAZIO API
version: 0.0.0-dev
version: 0.1.0
description: |-
An unofficial description of the private API behind the YAZIO food-diary app,
covering version 22 of the API at https://yzapi.yazio.com.
Expand Down
11 changes: 11 additions & 0 deletions src/yazio_sdk/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
"""A client library for accessing YAZIO API"""

from .client import AuthenticatedClient, Client

__all__ = (
"AuthenticatedClient",
"Client",
)

from ._version import SPEC_VERSION as __spec_version__ # noqa: E402
from ._version import __version__ # noqa: E402
7 changes: 7 additions & 0 deletions src/yazio_sdk/_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"""Written by scripts/generate.sh from the spec's info.version. Do not edit."""

__version__ = "0.1.0"

# The SDK is versioned as the spec it was generated from, so these are one
# string. See the spec repo's CONTRIBUTING for why.
SPEC_VERSION = __version__
1 change: 1 addition & 0 deletions src/yazio_sdk/api/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Contains methods for accessing the API"""
1 change: 1 addition & 0 deletions src/yazio_sdk/api/activity/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Contains endpoint functions for accessing the API"""
180 changes: 180 additions & 0 deletions src/yazio_sdk/api/activity/get_daily_exercise_summary.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
from http import HTTPStatus
from typing import Any

import httpx

from ... import errors
from ...client import AuthenticatedClient, Client
from ...models.daily_exercise_summary import DailyExerciseSummary
from ...types import UNSET, Response, Unset


def _get_kwargs(
*,
start: str | Unset = UNSET,
end: str | Unset = UNSET,
) -> dict[str, Any]:

params: dict[str, Any] = {}

params["start"] = start

params["end"] = end

params = {k: v for k, v in params.items() if v is not UNSET and v is not None}

_kwargs: dict[str, Any] = {
"method": "get",
"url": "/v22/user/exercises/summary-daily",
"params": params,
}

return _kwargs


def _parse_response(
*, client: AuthenticatedClient | Client, response: httpx.Response
) -> list[DailyExerciseSummary] | None:
if response.status_code == 200:
response_200 = []
_response_200 = response.json()
for response_200_item_data in _response_200:
response_200_item = DailyExerciseSummary.from_dict(response_200_item_data)

response_200.append(response_200_item)

return response_200

if client.raise_on_unexpected_status:
raise errors.UnexpectedStatus(response.status_code, response.content)
else:
return None


def _build_response(
*, client: AuthenticatedClient | Client, response: httpx.Response
) -> Response[list[DailyExerciseSummary]]:
return Response(
status_code=HTTPStatus(response.status_code),
content=response.content,
headers=response.headers,
parsed=_parse_response(client=client, response=response),
)


def sync_detailed(
*,
client: AuthenticatedClient | Client,
start: str | Unset = UNSET,
end: str | Unset = UNSET,
) -> Response[list[DailyExerciseSummary]]:
"""Daily totals of logged exercise

Args:
start (str | Unset):
end (str | Unset):

Raises:
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
httpx.TimeoutException: If the request takes longer than Client.timeout.

Returns:
Response[list[DailyExerciseSummary]]
"""

kwargs = _get_kwargs(
start=start,
end=end,
)

response = client.get_httpx_client().request(
**kwargs,
)

return _build_response(client=client, response=response)


def sync(
*,
client: AuthenticatedClient | Client,
start: str | Unset = UNSET,
end: str | Unset = UNSET,
) -> list[DailyExerciseSummary] | None:
"""Daily totals of logged exercise

Args:
start (str | Unset):
end (str | Unset):

Raises:
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
httpx.TimeoutException: If the request takes longer than Client.timeout.

Returns:
list[DailyExerciseSummary]
"""

return sync_detailed(
client=client,
start=start,
end=end,
).parsed


async def asyncio_detailed(
*,
client: AuthenticatedClient | Client,
start: str | Unset = UNSET,
end: str | Unset = UNSET,
) -> Response[list[DailyExerciseSummary]]:
"""Daily totals of logged exercise

Args:
start (str | Unset):
end (str | Unset):

Raises:
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
httpx.TimeoutException: If the request takes longer than Client.timeout.

Returns:
Response[list[DailyExerciseSummary]]
"""

kwargs = _get_kwargs(
start=start,
end=end,
)

response = await client.get_async_httpx_client().request(**kwargs)

return _build_response(client=client, response=response)


async def asyncio(
*,
client: AuthenticatedClient | Client,
start: str | Unset = UNSET,
end: str | Unset = UNSET,
) -> list[DailyExerciseSummary] | None:
"""Daily totals of logged exercise

Args:
start (str | Unset):
end (str | Unset):

Raises:
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
httpx.TimeoutException: If the request takes longer than Client.timeout.

Returns:
list[DailyExerciseSummary]
"""

return (
await asyncio_detailed(
client=client,
start=start,
end=end,
)
).parsed
160 changes: 160 additions & 0 deletions src/yazio_sdk/api/activity/list_exercises.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
from http import HTTPStatus
from typing import Any

import httpx

from ... import errors
from ...client import AuthenticatedClient, Client
from ...models.exercise_log import ExerciseLog
from ...types import UNSET, Response, Unset


def _get_kwargs(
*,
date: str | Unset = UNSET,
) -> dict[str, Any]:

params: dict[str, Any] = {}

params["date"] = date

params = {k: v for k, v in params.items() if v is not UNSET and v is not None}

_kwargs: dict[str, Any] = {
"method": "get",
"url": "/v22/user/exercises",
"params": params,
}

return _kwargs


def _parse_response(
*, client: AuthenticatedClient | Client, response: httpx.Response
) -> ExerciseLog | None:
if response.status_code == 200:
response_200 = ExerciseLog.from_dict(response.json())

return response_200

if client.raise_on_unexpected_status:
raise errors.UnexpectedStatus(response.status_code, response.content)
else:
return None


def _build_response(
*, client: AuthenticatedClient | Client, response: httpx.Response
) -> Response[ExerciseLog]:
return Response(
status_code=HTTPStatus(response.status_code),
content=response.content,
headers=response.headers,
parsed=_parse_response(client=client, response=response),
)


def sync_detailed(
*,
client: AuthenticatedClient | Client,
date: str | Unset = UNSET,
) -> Response[ExerciseLog]:
"""List logged exercises for a day

Args:
date (str | Unset):

Raises:
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
httpx.TimeoutException: If the request takes longer than Client.timeout.

Returns:
Response[ExerciseLog]
"""

kwargs = _get_kwargs(
date=date,
)

response = client.get_httpx_client().request(
**kwargs,
)

return _build_response(client=client, response=response)


def sync(
*,
client: AuthenticatedClient | Client,
date: str | Unset = UNSET,
) -> ExerciseLog | None:
"""List logged exercises for a day

Args:
date (str | Unset):

Raises:
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
httpx.TimeoutException: If the request takes longer than Client.timeout.

Returns:
ExerciseLog
"""

return sync_detailed(
client=client,
date=date,
).parsed


async def asyncio_detailed(
*,
client: AuthenticatedClient | Client,
date: str | Unset = UNSET,
) -> Response[ExerciseLog]:
"""List logged exercises for a day

Args:
date (str | Unset):

Raises:
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
httpx.TimeoutException: If the request takes longer than Client.timeout.

Returns:
Response[ExerciseLog]
"""

kwargs = _get_kwargs(
date=date,
)

response = await client.get_async_httpx_client().request(**kwargs)

return _build_response(client=client, response=response)


async def asyncio(
*,
client: AuthenticatedClient | Client,
date: str | Unset = UNSET,
) -> ExerciseLog | None:
"""List logged exercises for a day

Args:
date (str | Unset):

Raises:
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
httpx.TimeoutException: If the request takes longer than Client.timeout.

Returns:
ExerciseLog
"""

return (
await asyncio_detailed(
client=client,
date=date,
)
).parsed
Loading
Loading