2019-06-16 23:54:10 -05:00
|
|
|
from grocy.request import Request
|
|
|
|
from grocy.conf import Configuration
|
2019-07-07 13:58:01 -05:00
|
|
|
from grocy.entity import Entity
|
2019-06-16 23:54:10 -05:00
|
|
|
import logging
|
|
|
|
|
|
|
|
|
|
|
|
class Recipe(object):
|
2019-07-07 13:58:01 -05:00
|
|
|
GET_RECIPES_FULFILLMENT_URL_TEMPLATE = '{domain}/api/recipes/fulfillment'
|
|
|
|
GET_RECIPE_FULFILLMENT_URL_TEMPLATE = '{domain}/api/recipes/{recipeId}/fulfillment'
|
|
|
|
GET_RECIPES_POS_FULFILLMENT_URL_TEMPLATE = '{domain}/api/recipes/pos/fulfillment'
|
|
|
|
GET_RECIPE_POS_FULFILLMENT_URL_TEMPLATE = '{domain}/api/recipes/{recipeId}/pos/{recipeId}/fulfillment'
|
2019-06-16 23:54:10 -05:00
|
|
|
|
2019-07-07 13:58:01 -05:00
|
|
|
def __init__(self, id=None):
|
2019-06-16 23:54:10 -05:00
|
|
|
self.conf = Configuration()
|
|
|
|
self.conf.load()
|
2019-07-07 13:58:01 -05:00
|
|
|
self.id = id
|
2019-06-16 23:54:10 -05:00
|
|
|
|
2019-07-07 13:58:01 -05:00
|
|
|
def get_ingredient_requirements(self, recipe_id=None):
|
|
|
|
logger = logging.getLogger('recipe.get_ingredient_requirements')
|
|
|
|
|
|
|
|
|
|
|
|
def get_fulfillments(self):
|
2019-06-16 23:54:10 -05:00
|
|
|
logger = logging.getLogger('recipe.get_requirements')
|
2019-07-07 13:58:01 -05:00
|
|
|
if self.id:
|
|
|
|
url = self.GET_RECIPE_FULFILLMENT_URL_TEMPLATE.format(domain=self.conf.domain, recipeId=self.id)
|
|
|
|
else:
|
|
|
|
url = self.GET_RECIPES_FULFILLMENT_URL_TEMPLATE.format(domain=self.conf.domain)
|
2019-06-16 23:54:10 -05:00
|
|
|
request = Request('get', url)
|
|
|
|
try:
|
|
|
|
return request.send()
|
|
|
|
except Exception as e:
|
|
|
|
logger.error(e)
|
|
|
|
raise e
|
|
|
|
|
2019-07-07 13:58:01 -05:00
|
|
|
def get(self):
|
|
|
|
# Get list of available ingredients
|
|
|
|
if self.id:
|
|
|
|
entity = Entity(name='recipes')
|
|
|
|
recipe = entity.get(id=self.id)
|
|
|
|
|
|
|
|
if type(recipe) is list:
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|