# AUTO-GENERATED by scripts/oas-sync emit-resource Recipes. Do not edit by hand.
"""Resource wrapper for the OAS ``Recipes`` tag (generated)."""
from __future__ import annotations
from typing import Any, Optional
from .._base import BaseResource
from ...models._generated.recipes import RecipesRecipe
class RecipesResource(BaseResource):
"""Resource methods for the OAS `Recipes` tag (generated)."""
def add_favorite_v1(
self,
recipe_id: int,
) -> bool:
"""Add a recipe to a user's favorite.
:param recipe_id: Unique recipe identifier
Notes:
recipe.add_favorite (v1). Premier-only.
"""
params: dict[str, Any] = {"method": "recipe.add_favorite"}
params["recipe_id"] = recipe_id
payload = self._client._call(params, method="POST")
return self._client._mutator_success(payload)
def delete_favorite_v1(
self,
recipe_id: int,
) -> bool:
"""Deletes the specified recipe from the user's favorite.
:param recipe_id: Unique recipe identifier
Notes:
recipe.delete_favorite (v1). Premier-only.
"""
params: dict[str, Any] = {"method": "recipe.delete_favorite"}
params["recipe_id"] = recipe_id
payload = self._client._call(params, method="DELETE")
return self._client._mutator_success(payload)
def get_favorites_v1(
self,
) -> list[RecipesRecipe]:
"""Returns the favorite recipes for the specified user.
:return: List of :class:`RecipesRecipe` instances.
Notes:
recipes.get_favorites (v1). DEPRECATED upstream. Premier-only.
"""
params: dict[str, Any] = {"method": "recipes.get_favorites"}
payload = self._client._call(params)
raw = self._client._unwrap(payload, "recipes", list_key="recipe")
return [RecipesRecipe.model_validate(r) for r in raw]
def get_favorites_v2(
self,
) -> list[RecipesRecipe]:
"""Returns the favorite recipes for the specified user.
:return: List of :class:`RecipesRecipe` instances.
Notes:
recipes.get_favorites (v2). Premier-only.
"""
params: dict[str, Any] = {"method": "recipes.get_favorites.v2"}
payload = self._client._call(params)
raw = self._client._unwrap(payload, "recipes", list_key="recipe")
return [RecipesRecipe.model_validate(r) for r in raw]
[docs]
def get_v1(
self,
recipe_id: int,
region: Optional[str] = None,
) -> Optional[RecipesRecipe]:
"""Returns detailed information for the specified recipe for the standard serving.
:param recipe_id: Unique recipe identifier
: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.
:return: :class:`RecipesRecipe` instance, or ``None`` when the response is empty.
Notes:
recipe.get (v1). DEPRECATED upstream. Premier-only.
"""
params: dict[str, Any] = {"method": "recipe.get"}
params["recipe_id"] = recipe_id
self._client._set_optional(
params,
[
("region", region),
],
)
payload = self._client._call(params)
raw = self._client._unwrap(payload, "recipe")
if raw is None:
return None
return RecipesRecipe.model_validate(raw)
[docs]
def get_v2(
self,
recipe_id: int,
region: Optional[str] = None,
) -> Optional[RecipesRecipe]:
"""Returns detailed information for the specified recipe for the standard serving.
:param recipe_id: Unique recipe identifier
: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.
:return: :class:`RecipesRecipe` instance, or ``None`` when the response is empty.
Notes:
recipe.get (v2). Premier-only.
"""
params: dict[str, Any] = {"method": "recipe.get.v2"}
params["recipe_id"] = recipe_id
self._client._set_optional(
params,
[
("region", region),
],
)
payload = self._client._call(params)
raw = self._client._unwrap(payload, "recipe")
if raw is None:
return None
return RecipesRecipe.model_validate(raw)
[docs]
def search_v1(
self,
search_expression: Optional[str] = None,
recipe_type: Optional[str] = None,
page_number: Optional[int] = None,
max_results: Optional[int] = None,
) -> list[RecipesRecipe]:
"""Conducts a search of the recipe database using the search expression specified. The results are paginated according to a zero-based "page" offset. Successive pages of results may be retrieved by specifying a starting page offset value. For instance, specifying a max_results of 10 and page_number of 4 will return results numbered 41-50. An interactive demonstration of our Recipe Search API can be accessed here
:param search_expression: Search expression to match on food names
:param recipe_type: Recipe type E.G.: "Appetizer"
:param page_number: Zero-based offset into the results for the query
:param max_results: Maximum number of results to return (default value is 20). This number cannot be greater than 50
:return: List of :class:`RecipesRecipe` instances.
Notes:
recipes.search (v1). DEPRECATED upstream. Premier-only.
"""
params: dict[str, Any] = {"method": "recipes.search"}
self._client._set_optional(
params,
[
("search_expression", search_expression),
("recipe_type", recipe_type),
("page_number", page_number),
("max_results", max_results),
],
)
payload = self._client._call(params)
raw = self._client._unwrap(payload, "recipes", list_key="recipe")
return [RecipesRecipe.model_validate(r) for r in raw]
def search_v2(
self,
search_expression: Optional[str] = None,
must_have_images: Optional[str] = None,
calories_from: Optional[int] = None,
calories_to: Optional[int] = None,
carb_percentage_from: Optional[int] = None,
carb_percentage_to: Optional[int] = None,
protein_percentage_from: Optional[int] = None,
protein_percentage_to: Optional[int] = None,
fat_percentage_from: Optional[int] = None,
fat_percentage_to: Optional[int] = None,
prep_time_from: Optional[int] = None,
prep_time_to: Optional[int] = None,
page_number: Optional[int] = None,
max_results: Optional[int] = None,
sort_by: Optional[str] = None,
region: Optional[str] = None,
) -> list[RecipesRecipe]:
"""Conducts a search of the recipe database using the search expression specified. The results are paginated according to a zero-based "page" offset. Successive pages of results may be retrieved by specifying a starting page offset value. For instance, specifying a max_results of 10 and page_number of 4 will return results numbered 41-50. An interactive demonstration of our Recipe Search API can be accessed here
:param search_expression: Search expression to match on food names
:param must_have_images: This option will restrict results to recipes with at least one image
:param calories_from: Minimum calories that are contained in the recipe
:param calories_to: Maximum calories that are contained in the recipe
:param carb_percentage_from: Minimum percentage of the calories composed of carbohydrate
:param carb_percentage_to: Maximum percentage of the calories composed of carbohydrate
:param protein_percentage_from: Minimum percentage of the calories composed of protein
:param protein_percentage_to: Maximum percentage of the calories composed of protein
:param fat_percentage_from: Minimum percentage of the calories composed of fat
:param fat_percentage_to: Maximum percentage of the calories composed of fat
:param prep_time_from: Minimum preparation and cook time in minutes required to create the recipe
:param prep_time_to: Maximum preparation and cook time in minutes required to create the recipe
:param page_number: Zero-based offset into the results for the query
:param max_results: Maximum number of results to return (default value is 20). This number cannot be greater than 50
:param sort_by: This option will order results. Valid options include: newest, oldest, caloriesPerServingAscending, caloriesPerServingDescending. When not explicitly set, the ordering will be returned by newest
: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.
:return: List of :class:`RecipesRecipe` instances.
Notes:
recipes.search (v2). DEPRECATED upstream. Premier-only.
"""
params: dict[str, Any] = {"method": "recipes.search.v2"}
self._client._set_optional(
params,
[
("search_expression", search_expression),
("must_have_images", must_have_images),
("calories.from", calories_from),
("calories.to", calories_to),
("carb_percentage.from", carb_percentage_from),
("carb_percentage.to", carb_percentage_to),
("protein_percentage.from", protein_percentage_from),
("protein_percentage.to", protein_percentage_to),
("fat_percentage.from", fat_percentage_from),
("fat_percentage.to", fat_percentage_to),
("prep_time.from", prep_time_from),
("prep_time.to", prep_time_to),
("page_number", page_number),
("max_results", max_results),
("sort_by", sort_by),
("region", region),
],
)
payload = self._client._call(params)
raw = self._client._unwrap(payload, "recipes", list_key="recipe")
return [RecipesRecipe.model_validate(r) for r in raw]
def search_v3(
self,
recipe_types: Optional[str] = None,
recipe_types_matchall: Optional[str] = None,
search_expression: Optional[str] = None,
must_have_images: Optional[str] = None,
calories_from: Optional[int] = None,
calories_to: Optional[int] = None,
carb_percentage_from: Optional[int] = None,
carb_percentage_to: Optional[int] = None,
protein_percentage_from: Optional[int] = None,
protein_percentage_to: Optional[int] = None,
fat_percentage_from: Optional[int] = None,
fat_percentage_to: Optional[int] = None,
prep_time_from: Optional[int] = None,
prep_time_to: Optional[int] = None,
page_number: Optional[int] = None,
max_results: Optional[int] = None,
sort_by: Optional[str] = None,
region: Optional[str] = None,
) -> list[RecipesRecipe]:
"""Conducts a search of the recipe database using the search expression specified. The results are paginated according to a zero-based "page" offset. Successive pages of results may be retrieved by specifying a starting page offset value. For instance, specifying a max_results of 10 and page_number of 4 will return results numbered 41-50. An interactive demonstration of our Recipe Search API can be accessed here
:param recipe_types: This option filters by specified recipe types and should be provided as a comma separated string of recipe type names. The values are provided via the api: Recipe Types Get All
:param recipe_types_matchall: This option will affect recipe type filters. If true, a recipe must match all provided recipe types, if false (default) then recipes matching any of the supplied types will be returned, The values are provided via the api: Recipe Types Get All
:param search_expression: Search expression to match on food names
:param must_have_images: This option will restrict results to recipes with at least one image
:param calories_from: Minimum calories that are contained in the recipe
:param calories_to: Maximum calories that are contained in the recipe
:param carb_percentage_from: Minimum percentage of the calories composed of carbohydrate
:param carb_percentage_to: Maximum percentage of the calories composed of carbohydrate
:param protein_percentage_from: Minimum percentage of the calories composed of protein
:param protein_percentage_to: Maximum percentage of the calories composed of protein
:param fat_percentage_from: Minimum percentage of the calories composed of fat
:param fat_percentage_to: Maximum percentage of the calories composed of fat
:param prep_time_from: Minimum preparation and cook time in minutes required to create the recipe
:param prep_time_to: Maximum preparation and cook time in minutes required to create the recipe
:param page_number: Zero-based offset into the results for the query
:param max_results: Maximum number of results to return (default value is 20). This number cannot be greater than 50
:param sort_by: This option will order results. Valid options include: newest, oldest, caloriesPerServingAscending, caloriesPerServingDescending. When not explicitly set, the ordering will be returned by newest
: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.
:return: List of :class:`RecipesRecipe` instances.
Notes:
recipes.search (v3). Premier-only.
"""
params: dict[str, Any] = {"method": "recipes.search.v3"}
self._client._set_optional(
params,
[
("recipe_types", recipe_types),
("recipe_types_matchall", recipe_types_matchall),
("search_expression", search_expression),
("must_have_images", must_have_images),
("calories.from", calories_from),
("calories.to", calories_to),
("carb_percentage.from", carb_percentage_from),
("carb_percentage.to", carb_percentage_to),
("protein_percentage.from", protein_percentage_from),
("protein_percentage.to", protein_percentage_to),
("fat_percentage.from", fat_percentage_from),
("fat_percentage.to", fat_percentage_to),
("prep_time.from", prep_time_from),
("prep_time.to", prep_time_to),
("page_number", page_number),
("max_results", max_results),
("sort_by", sort_by),
("region", region),
],
)
payload = self._client._call(params)
raw = self._client._unwrap(payload, "recipes", list_key="recipe")
return [RecipesRecipe.model_validate(r) for r in raw]
[docs]
def types_get_v1(
self,
) -> list:
"""This is a utility method, returning the full list of all supported recipe type names.
:return: Raw FatSecret response shape (no typed model — see ``docs/migration-v3.rst``).
Notes:
recipe_types.get (v1). DEPRECATED upstream. Premier-only.
"""
params: dict[str, Any] = {"method": "recipe_types.get"}
payload = self._client._call(params)
raw = self._client._unwrap(payload, "recipe_types", list_key="recipe_type")
return raw
[docs]
def types_get_v2(
self,
region: Optional[str] = None,
language: Optional[str] = None,
) -> list:
"""This is a utility method, returning the full list of all supported recipe type names.
: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: Raw FatSecret response shape (no typed model — see ``docs/migration-v3.rst``).
Notes:
recipe_types.get (v2). Premier-only.
"""
params: dict[str, Any] = {"method": "recipe_types.get.v2"}
self._client._set_optional(
params,
[
("region", region),
("language", language),
],
)
payload = self._client._call(params)
raw = self._client._unwrap(payload, "recipe_types", list_key="recipe_type")
return raw
__all__ = ["RecipesResource"]