rename module pyrohlik to rohlik
This commit is contained in:
parent
d10cef9705
commit
e3ba823070
8 changed files with 1 additions and 1 deletions
72
rohlik/client.py
Normal file
72
rohlik/client.py
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
import uuid
|
||||
from apiclient import APIClient, endpoint, JsonRequestFormatter, JsonResponseHandler, HeaderAuthentication
|
||||
from apiclient_pydantic import serialize
|
||||
|
||||
from .models.order import Order, Orders
|
||||
from .models.product import Product
|
||||
from .models.recipe import Recipe
|
||||
from .models.cart import Cart, AddItem, Add
|
||||
from .endpoints import Endpoints
|
||||
|
||||
|
||||
class Rohlik(APIClient):
|
||||
def __init__(self, api_key: str):
|
||||
super().__init__(request_formatter=JsonRequestFormatter, response_handler=JsonResponseHandler, authentication_method=HeaderAuthentication(token=api_key,parameter="x-api-authorization",scheme="token"))
|
||||
|
||||
@serialize()
|
||||
def get_product(self, product_id: int) -> Product:
|
||||
product = self.get(Endpoints.product.format(product_id=product_id))
|
||||
prices = self.get(Endpoints.prices.format(product_id=product_id))
|
||||
stock = self.get(Endpoints.stock.format(product_id=product_id))
|
||||
description = self.get(Endpoints.description.format(product_id=product_id))
|
||||
composition = self.get(Endpoints.composition.format(product_id=product_id))
|
||||
product['prices'] = prices
|
||||
product['stock'] = stock
|
||||
product['description'] = description['description']
|
||||
product['composition'] = composition
|
||||
return product
|
||||
|
||||
@serialize()
|
||||
def get_order(self, order_id: int) -> Order:
|
||||
return self.get(Endpoints.order.format(order_id=order_id))
|
||||
|
||||
@serialize()
|
||||
def get_orders(self) -> Orders:
|
||||
return self.get(Endpoints.orders_delivered)
|
||||
|
||||
@serialize()
|
||||
def get_recipe(self, recipe_id: int) -> Recipe:
|
||||
recipe_response = self.get(Endpoints.recipe.format(recipe_id=recipe_id))
|
||||
return recipe_response['data']
|
||||
|
||||
@serialize()
|
||||
def get_cart(self) -> Cart:
|
||||
return self.get(Endpoints.cart)
|
||||
|
||||
@serialize()
|
||||
def add_to_cart(self, product_id) -> Cart:
|
||||
add = Add()
|
||||
add_item=AddItem()
|
||||
add_item.uuid=str(uuid.uuid4())
|
||||
add_item.product_id = product_id
|
||||
add_item.action_type = "modify"
|
||||
add_item.amount = 1
|
||||
add_item.source = "hp-v2"
|
||||
add_item.sale_id = 0
|
||||
add.items = []
|
||||
add.items.append(add_item)
|
||||
return self.patch(Endpoints.cart, add.dict(by_alias=True))
|
||||
|
||||
@serialize()
|
||||
def remove_from_cart(self, product_id) -> Cart:
|
||||
add = Add()
|
||||
add_item=AddItem()
|
||||
add_item.uuid=str(uuid.uuid4())
|
||||
add_item.product_id = product_id
|
||||
add_item.action_type = "modify"
|
||||
add_item.amount = -1
|
||||
add_item.source = "hp-v2"
|
||||
add_item.sale_id = 0
|
||||
add.items = []
|
||||
add.items.append(add_item)
|
||||
return self.patch(Endpoints.cart, add.dict(by_alias=True))
|
||||
Loading…
Add table
Add a link
Reference in a new issue