Skip to content

Add get_template_content and get_user_recipes methods - #272

Draft
erikzimmermann wants to merge 1 commit into
miaucl:mainfrom
erikzimmermann:feat/get-user-recipes
Draft

Add get_template_content and get_user_recipes methods#272
erikzimmermann wants to merge 1 commit into
miaucl:mainfrom
erikzimmermann:feat/get-user-recipes

Conversation

@erikzimmermann

Copy link
Copy Markdown

Thanks @miaucl for the great work on this library. I am missing an export endpoint for the recipes though. So here it is.

Summary

  • Adds get_template_content(content_uuid) to fetch full template details
    (including ingredients) from the /v2/bringtemplates/content/{uuid} endpoint
  • Adds get_user_recipes() as a convenience method that combines
    get_inspirations("mine") with get_template_content to return fully
    populated templates for all user-saved recipes (ad/POST entries excluded)
  • Merges summary-level metadata (name, image, link) into the detail response
    where the detail endpoint omits it
  • Adds tests and snapshot fixtures for both methods

Note: existing tests are currently affected by an aioresponses/aiohttp 3.13+
incompatibility — a fix is pending upstream in pnuckowski/aioresponses.

@github-actions github-actions Bot added the 🧪 testing Pull request that adds tests label Jun 27, 2026
Comment thread bring_api/bring.py
Comment on lines +1470 to +1512
async def get_user_recipes(self) -> list[BringTemplate]:
"""Fetch all recipes and templates saved by the user, with full item details.

Combines :meth:`get_inspirations` (``filter="mine"``) with
:meth:`get_template_content` to return complete templates whose
``items`` list is populated with ingredients and staples.

Returns
-------
list[BringTemplate]
Full templates for every user-created recipe/template (ad entries
of type ``POST`` are excluded). Each template's ``items`` field
contains all ingredients; items with ``stock=True`` are staples.

Raises
------
BringRequestException
If any request fails.
BringParseException
If parsing of any response fails.
BringAuthException
If the request fails due to invalid or expired authorization token.

"""
inspirations = await self.get_inspirations("mine")
recipes: list[BringTemplate] = []
for entry in inspirations.entries:
if entry.template_type == TemplateType.POST:
continue
summary = entry.content
if not summary.contentUuid:
recipes.append(summary)
continue
full = await self.get_template_content(summary.contentUuid)
# Detail endpoint may omit top-level metadata present in the summary
if not full.name:
full.name = summary.name or summary.title
if not full.linkOutUrl:
full.linkOutUrl = summary.linkOutUrl
if not full.imageUrl:
full.imageUrl = summary.imageUrl
recipes.append(full)
return recipes

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the library should only serve as an interface to the Bring REST API. Any processing or interpretation of the API responses should be handled downstream rather than in the library itself.

@tr4nt0r tr4nt0r changed the title feat: add get_template_content and get_user_recipes methods Add get_template_content and get_user_recipes methods Jul 23, 2026
@tr4nt0r tr4nt0r added 🚀 feature New feature or request and removed 🧪 testing Pull request that adds tests labels Jul 23, 2026
@tr4nt0r
tr4nt0r marked this pull request as draft July 23, 2026 00:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🚀 feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants