Repository URL to install this package:
|
Version:
0.4.139 ▾
|
lib-py-b2b
/
dialect.py
|
|---|
import abc
import logging
from os import environ
from typing import Type
from .order_request import OrderRequestType, OrderRequest
log_level = logging.getLevelName(environ['LOG_LEVEL']) if 'LOG_LEVEL' in environ else logging.INFO
logging.basicConfig(format='%(asctime)s,%(msecs)d %(levelname)-8s [%(filename)s:%(lineno)d] %(message)s',
datefmt='%d-%m-%Y:%H:%M:%S',
level=log_level)
logger = logging.getLogger('b2b-lib-dialect')
class Dialect:
@staticmethod
def infer_from(request):
from .shopify import ShopifyDialect
if ShopifyDialect.matches_dialect(request):
return ShopifyDialect(request)
else:
from .standard import StandardDialect
return StandardDialect(request)
@staticmethod
def matches_dialect(request):
pass
@property
@abc.abstractmethod
def request_type(self) -> OrderRequestType:
raise NotImplementedError
@abc.abstractmethod
def verify(self, request_type: OrderRequestType):
raise NotImplementedError
@abc.abstractmethod
def data_provider_for(self, order_request: OrderRequest, change_request_type: Type[OrderRequest.C]):
raise NotImplementedError
@property
@abc.abstractmethod
def shipTo(self):
raise NotImplementedError
class CreateOrderRequestDataProvider(metaclass=abc.ABCMeta):
@property
@abc.abstractmethod
def order_id(self):
raise NotImplementedError
class CancelOrderRequestDataProvider(metaclass=abc.ABCMeta):
@property
@abc.abstractmethod
def cancellation_reason(self):
raise NotImplementedError
@property
@abc.abstractmethod
def cancelled_at(self):
raise NotImplementedError