Source code for fatsecret.resources._generated.exercises

# AUTO-GENERATED by scripts/oas-sync emit-resource Exercise Diary. Do not edit by hand.
"""Resource wrapper for the OAS ``Exercise Diary`` tag (generated)."""

from __future__ import annotations

from typing import Any, Optional

from .._base import BaseResource

from ...models._generated.exercise_diary import Day, Exercise, ExerciseEntry


class ExercisesResource(BaseResource):
    """Resource methods for the OAS `Exercise Diary` tag (generated)."""

[docs] def entries_commit_day_v1( self, date: Optional[int] = None, ) -> bool: """Saves the default exercise entries for the user on a nominated date. The API will always return 24 hours worth of exercise entries for a given user on a given date. Users can set up and save standard routines for the activities they do on any given day of the week, known as "template" exercise entries. When the exercise entries are retrieved for a day that has not previously been committed or adjusted by the user a set of 24 hours worth of "template" or default entries will be returned. The exercise_entries.commit_day method takes the current "template" exercise entries and saves them to the exercise diary. Calling this method is in effect an acknowledgement on behalf of a user that they undertook the activities presented in the template. :param date: Number of days since January 1, 1970 (default value is the current day) Notes: exercise_entries.commit_day (v1). Premier-only. """ params: dict[str, Any] = {"method": "exercise_entries.commit_day"} self._client._set_optional( params, [ ("date", None if date is None else self._client.unix_time_v2(date)), ], ) payload = self._client._call(params, method="POST") return self._client._mutator_success(payload)
[docs] def entries_get_month_v1( self, date: Optional[int] = None, ) -> list[Day]: """Returns the summary estimated daily calories expended for a user's exercise diary entries for the month specified. Use this call to display total energy expenditure information to users about their exercise and activities for a nominated month. Days with no saved exercise diary entries are not included. :param date: Number of days since January 1, 1970 (default value is the current day) :return: List of :class:`Day` instances. Notes: exercise_entries.get_month (v1). DEPRECATED upstream. Premier-only. """ params: dict[str, Any] = {"method": "exercise_entries.get_month"} self._client._set_optional( params, [ ("date", None if date is None else self._client.unix_time_v2(date)), ], ) payload = self._client._call(params) raw = self._client._unwrap(payload, "month", list_key="day") return [Day.model_validate(r) for r in raw]
[docs] def entries_get_month_v2( self, date: Optional[int] = None, ) -> list[Day]: """Returns the summary estimated daily calories expended for a user's exercise diary entries for the month specified. Use this call to display total energy expenditure information to users about their exercise and activities for a nominated month. Days with no saved exercise diary entries are not included. :param date: Number of days since January 1, 1970 (default value is the current day) :return: List of :class:`Day` instances. Notes: exercise_entries.get_month (v2). Premier-only. """ params: dict[str, Any] = {"method": "exercise_entries.get_month.v2"} self._client._set_optional( params, [ ("date", None if date is None else self._client.unix_time_v2(date)), ], ) payload = self._client._call(params) raw = self._client._unwrap(payload, "month", list_key="day") return [Day.model_validate(r) for r in raw]
[docs] def entries_get_v1( self, date: Optional[int] = None, ) -> list[ExerciseEntry]: """Returns the daily exercise entries for the user on a nominated date. The API will always return 24 hours worth of exercise entries for a given user on a given date. These entries will either be "template" entries (which a user may override for any given day of the week) or saved exercise entry values. Once a user saves or updates the entries on any given day, all entries for that day are saved. All adjustments to the day involve reducing the time for an existing activity in order to either add or increase the time taken for another activity. The default entries presented for a user for a given day of the week can be overridden using exercise_entries.save_template. :param date: Number of days since January 1, 1970 (default value is the current day) :return: List of :class:`ExerciseEntry` instances. Notes: exercise_entries.get (v1). DEPRECATED upstream. Premier-only. """ params: dict[str, Any] = {"method": "exercise_entries.get"} self._client._set_optional( params, [ ("date", None if date is None else self._client.unix_time_v2(date)), ], ) payload = self._client._call(params) raw = self._client._unwrap(payload, "exercise_entries", list_key="exercise_entry") return [ExerciseEntry.model_validate(r) for r in raw]
[docs] def entries_get_v2( self, date: Optional[int] = None, ) -> list[ExerciseEntry]: """Returns the daily exercise entries for the user on a nominated date. The API will always return 24 hours worth of exercise entries for a given user on a given date. These entries will either be "template" entries (which a user may override for any given day of the week) or saved exercise entry values. Once a user saves or updates the entries on any given day, all entries for that day are saved. All adjustments to the day involve reducing the time for an existing activity in order to either add or increase the time taken for another activity. The default entries presented for a user for a given day of the week can be overridden using exercise_entries.save_template. :param date: Number of days since January 1, 1970 (default value is the current day) :return: List of :class:`ExerciseEntry` instances. Notes: exercise_entries.get (v2). Premier-only. """ params: dict[str, Any] = {"method": "exercise_entries.get.v2"} self._client._set_optional( params, [ ("date", None if date is None else self._client.unix_time_v2(date)), ], ) payload = self._client._call(params) raw = self._client._unwrap(payload, "exercise_entries", list_key="exercise_entry") return [ExerciseEntry.model_validate(r) for r in raw]
def entries_save_template_v1( self, days: int, date: Optional[int] = None, ) -> bool: """Takes the set of exercise entries on a nominated date and saves these entries as "template" entries for nominated days of the week. By default, the template daily exercise entries for all users for all days of the week are: his method is used to take the saved entries on for a nominated date and to copy them for one or more days of the week as the template daily exercise entries. So, for instance, if a user records 1 hour of walking, 8 hours of sleeping and 15 hours of resting for a particular day in their exercise diary, and then saves that date as a template for Saturday and Sunday, these three activities will be presented as the default exercise entries for all future Saturdays and Sundays. :param days: The days of the week specified as bits with Sunday being the 1st bit and Saturday being the last and then converted to an Int. For example Tuesday and Thursday would be represented as 00010100 in bits or 20 in Int where Tuesday is the 3rd bit from the right and Thursday being the 5th. Must be between 0 and 128 :param date: Number of days since January 1, 1970 (default value is the current day) Notes: exercise_entries.save_template (v1). Premier-only. """ params: dict[str, Any] = {"method": "exercise_entries.save_template"} params["days"] = days self._client._set_optional( params, [ ("date", None if date is None else self._client.unix_time_v2(date)), ], ) payload = self._client._call(params, method="POST") return self._client._mutator_success(payload)
[docs] def entry_edit_v1( self, shift_to_id: int, shift_from_id: int, minutes: int, date: Optional[int] = None, shift_to_name: Optional[str] = None, shift_from_name: Optional[str] = None, kcal: Optional[int] = None, ) -> bool: """Records a change to a user's exercise diary entry for a nominated date. All changes to an exercise diary involve either increasing the duration of an existing activity or introducing a new activity for a nominated duration. Because there are always 24 hours worth of exercise entries on any given date, the user must nominate the exercise or activity from which the time was taken to balance out the total duration of activities and exercises for the 24 hour period. As such, each change to the exercise entries on a given day is a "shifting" operation where time is moved from one activity to another. An exercise is removed from the day when all of the time allocated to it is shifted to other exercises. :param shift_to_id: ID of the exercise type to shift to :param shift_from_id: ID of the exercise type to shift from :param minutes: Duration in minutes :param date: Number of days since January 1, 1970 (default value is the current day) :param shift_to_name: Only required if shift_to_id is 0 (exercise type "Other"). This is the name of the new custom exercise type to shift to :param shift_from_name: Only required if shift_from_id is 0 (exercise type "Other"). This is the name of the custom exercise type to shift from :param kcal: Only required if shift_to_id is 0 (exercise type "Other"). This is the total number of kcals burned for this exercise Notes: exercise_entry.edit (v1). Premier-only. """ params: dict[str, Any] = {"method": "exercise_entry.edit"} params["shift_to_id"] = shift_to_id params["shift_from_id"] = shift_from_id params["minutes"] = minutes self._client._set_optional( params, [ ("date", None if date is None else self._client.unix_time_v2(date)), ("shift_to_name", shift_to_name), ("shift_from_name", shift_from_name), ("kcal", kcal), ], ) payload = self._client._call(params, method="PUT") return self._client._mutator_success(payload)
[docs] def list_v1( self, region: Optional[str] = None, language: Optional[str] = None, ) -> list[Exercise]: """This is a utility method, returning the full list of all supported exercise type names and their associated unique identifiers. :param region: Results will be filtered by region. E.G.: "FR" returns results from France. If not specified this will default to "US" (United States). Click here for full documentation on localization. :param language: (Ignored unless region is also specified) Results will be in the specified language. E.G.: "fr" returns results in French :return: List of :class:`Exercise` instances. Notes: exercises.get (v1). DEPRECATED upstream. Premier-only. """ params: dict[str, Any] = {"method": "exercises.get"} self._client._set_optional( params, [ ("region", region), ("language", language), ], ) payload = self._client._call(params) raw = self._client._unwrap(payload, "exercise_types", list_key="exercise") return [Exercise.model_validate(r) for r in raw]
[docs] def list_v2( self, region: Optional[str] = None, language: Optional[str] = None, ) -> list[Exercise]: """This is a utility method, returning the full list of all supported exercise type names and their associated unique identifiers. :param region: Results will be filtered by region. E.G.: "FR" returns results from France. If not specified this will default to "US" (United States). Click here for full documentation on localization. :param language: (Ignored unless region is also specified) Results will be in the specified language. E.G.: "fr" returns results in French :return: List of :class:`Exercise` instances. Notes: exercises.get (v2). Premier-only. """ params: dict[str, Any] = {"method": "exercises.get.v2"} self._client._set_optional( params, [ ("region", region), ("language", language), ], ) payload = self._client._call(params) raw = self._client._unwrap(payload, "exercise_types", list_key="exercise") return [Exercise.model_validate(r) for r in raw]
__all__ = ["ExercisesResource"]