-
-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from PurplShip/CleanUpUnifiedTypesAndFreightIn…
…tegrations Clean up unified types and freight integrations
- Loading branch information
Showing
34 changed files
with
491 additions
and
328 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Global options: | ||
|
||
[mypy] | ||
python_version = 3.6 | ||
warn_return_any = True | ||
warn_unused_configs = True | ||
|
||
# Per-module options: | ||
|
||
[mypy-lxml] | ||
ignore_missing_imports = True | ||
|
||
[mypy-gds_helpers] | ||
ignore_missing_imports = True | ||
|
||
[mypy-pycaps.*] | ||
ignore_missing_imports = True | ||
|
||
[mypy-pydhl.*] | ||
ignore_missing_imports = True | ||
|
||
[mypy-pyfedex.*] | ||
ignore_missing_imports = True | ||
|
||
[mypy-pyups.*] | ||
ignore_missing_imports = True | ||
|
||
[mypy-pysoap.*] | ||
ignore_missing_imports = True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,47 @@ | ||
from collections import namedtuple | ||
from typing import List, Dict | ||
from purplship.domain.Types.datatypes import item_type, party, invoice_type, doc_image, option_type | ||
from purplship.domain.Types.datatypes import item_type, party, invoice_type, doc_image, option_type, shipment_options, customs_type | ||
|
||
''' customs Type definition ''' | ||
class customs_details_type(namedtuple("customs_details_type", "no_eei aes description terms_of_trade items commercial_invoice extra")): | ||
def __new__(cls, no_eei: str = None, aes: str = None, description: str = None, terms_of_trade: str = None, items: List[dict] = [], commercial_invoice: bool = None, extra: dict = None): | ||
return super(cls, customs_details_type).__new__( | ||
cls, | ||
no_eei, | ||
aes, | ||
description, | ||
terms_of_trade, | ||
[item_type(**i) for i in items], | ||
commercial_invoice, | ||
extra, | ||
) | ||
def create_customs_type(no_eei: str = None, aes: str = None, description: str = None, terms_of_trade: str = None, items: List[dict] = [], commercial_invoice: bool = False, extra: dict = {}) -> customs_type: | ||
''' customs Type factory function ''' | ||
return customs_type( | ||
no_eei=no_eei, | ||
aes=aes, | ||
description=description, | ||
terms_of_trade=terms_of_trade, | ||
items=[item_type(**i) for i in items], | ||
commercial_invoice=commercial_invoice, | ||
extra=extra, | ||
) | ||
|
||
|
||
''' shipment options Type definition ''' | ||
class shipment_options_type(namedtuple("shipment_options_type", "items insured_amount total_items packaging_type is_document currency date total_weight weight_unit dimension_unit paid_by duty_paid_by payment_type payment_country_code duty_payment_account declared_value payment_account_number billing_account_number services options customs invoice doc_images references label, extra")): | ||
def __new__(cls, items: List, insured_amount: float = None, total_items: int = None, packaging_type: str = None, is_document: bool = False, currency: str = None, date: str = None, total_weight: float = None, weight_unit: str = "LB", dimension_unit: str = "IN", paid_by: str = None, duty_paid_by: str = None, payment_type: str = None, payment_country_code: str = None, duty_payment_account: str = None, declared_value: float = None, payment_account_number: str = None, billing_account_number: str = None, services: List[str] = [], options: List[dict] = [], customs: Dict = None, invoice: dict = None, doc_images: List[dict] = [], references: List[str] = [], label: Dict = None, extra: Dict = {}): | ||
return super(cls, shipment_options_type).__new__( | ||
cls, | ||
[item_type(**p) for p in items], | ||
insured_amount, | ||
total_items, | ||
packaging_type, | ||
is_document, | ||
currency, | ||
date, | ||
total_weight, | ||
weight_unit, | ||
dimension_unit, | ||
paid_by, | ||
duty_paid_by, | ||
payment_type, | ||
payment_country_code, | ||
duty_payment_account, | ||
declared_value, | ||
payment_account_number, | ||
billing_account_number, | ||
services, | ||
[option_type(**option) for option in options], | ||
customs_details_type(**customs) if customs else None, | ||
invoice_type(**invoice) if invoice else None, | ||
[doc_image(**doc) for doc in doc_images], | ||
references, | ||
doc_image(**label) if label else None, | ||
extra | ||
) | ||
|
||
|
||
''' shipment request Type definition ''' | ||
class shipment_request_type(namedtuple("shipment_request_type", "shipper recipient shipment")): | ||
def __new__(cls, shipper: Dict, recipient: Dict, shipment: Dict): | ||
return super(cls, shipment_request_type).__new__( | ||
cls, | ||
party(**shipper), | ||
party(**recipient), | ||
shipment_options_type(**shipment) | ||
) | ||
def create_shipment_options(items: List, insured_amount: float = None, total_items: int = None, packaging_type: str = None, is_document: bool = False, currency: str = None, total_weight: float = None, weight_unit: str = "LB", dimension_unit: str = "IN", paid_by: str = None, duty_paid_by: str = None, payment_type: str = None, payment_country_code: str = None, duty_payment_account: str = None, declared_value: float = None, payment_account_number: str = None, services: List[str] = [], options: List[dict] = [], date : str = None, customs: dict = None, invoice: dict = None, doc_images: List[dict] = [], references: List[str] = [], label: Dict = None, extra: Dict = {}) -> shipment_options: | ||
''' shipment options Type factory function ''' | ||
return shipment_options( | ||
items=[item_type(**p) for p in items], | ||
insured_amount=insured_amount, | ||
total_items=total_items, | ||
packaging_type=packaging_type, | ||
is_document=is_document, | ||
currency=currency, | ||
total_weight=total_weight, | ||
weight_unit=weight_unit, | ||
dimension_unit=dimension_unit, | ||
paid_by=paid_by, | ||
duty_paid_by=duty_paid_by, | ||
payment_type=payment_type, | ||
payment_country_code=payment_country_code, | ||
duty_payment_account=duty_payment_account, | ||
declared_value=declared_value, | ||
payment_account_number=payment_account_number, | ||
services=services, | ||
options=[option_type(**option) for option in options], | ||
date=date, | ||
customs=create_customs_type(**customs) if customs else None, | ||
invoice=invoice_type(**invoice) if invoice else None, | ||
doc_images=[doc_image(**doc) for doc in doc_images], | ||
references=references, | ||
label=doc_image(**label) if label else None, | ||
extra=extra | ||
) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,16 @@ | ||
from abc import ABC | ||
|
||
class Client: | ||
""" Unitied API carrier Client (Interface) """ | ||
class Client(ABC): | ||
""" | ||
Unitied API carrier Client (Interface) | ||
... | ||
Attributes | ||
---------- | ||
server_url : str | ||
a carrier server url address (can be test or prod) | ||
carrier_name : str | ||
a custom name to identified the carrier client instance (set to carrier name by default) | ||
""" | ||
server_url: str | ||
carrier_name: str |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,58 @@ | ||
from abc import ABC, abstractmethod | ||
from typing import List, Tuple | ||
from .client import Client | ||
from ..domain import Types as T | ||
|
||
class Mapper: | ||
""" Unitied API to carrier API Mapper (Interface) """ | ||
client: Client | ||
class Mapper(ABC): | ||
""" | ||
United API to carrier data Mapper (Interface) | ||
... | ||
Attributes | ||
---------- | ||
client : Client | ||
a carrier client (holding connection settings) | ||
""" | ||
|
||
def create_quote_request(self, payload: T.shipment_request): | ||
""" Create carrier specific quote request xml data from payload """ | ||
""" Create a carrier specific quote request xml data from payload """ | ||
raise Exception("Not Supported") | ||
|
||
def parse_quote_response(self, response) -> Tuple[List[T.QuoteDetails], List[T.Error]]: | ||
""" Create united API quote result list from carrier xml response """ | ||
""" Create a united API quote result list from carrier xml response """ | ||
raise Exception("Not Supported") | ||
|
||
def create_tracking_request(self, payload: T.tracking_request): | ||
""" Create carrier specific tracking request xml data from payload """ | ||
""" Create a carrier specific tracking request xml data from payload """ | ||
raise Exception("Not Supported") | ||
|
||
def parse_tracking_response(self, response) -> Tuple[List[T.TrackingDetails], List[T.Error]]: | ||
""" Create united API tracking result list from carrier xml response """ | ||
""" Create a united API tracking result list from carrier xml response """ | ||
raise Exception("Not Supported") | ||
|
||
def create_shipment_request(self, payload: T.shipment_request): | ||
""" Create carrier specific shipment creation request xml data from payload """ | ||
""" Create a carrier specific shipment creation request xml data from payload """ | ||
raise Exception("Not Supported") | ||
|
||
def parse_shipment_response(self, response) -> Tuple[T.ShipmentDetails, List[T.Error]]: | ||
""" Create united API shipment creation result from carrier xml response """ | ||
""" Create a united API shipment creation result from carrier xml response """ | ||
raise Exception("Not Supported") | ||
|
||
def create_pickup_request(self, payload: T.pickup_request): | ||
""" Create carrier specific pickup request xml data from payload """ | ||
""" Create a carrier specific pickup request xml data from payload """ | ||
raise Exception("Not Supported") | ||
|
||
def modify_pickup_request(self, payload: T.pickup_request): | ||
""" Create carrier specific pickup modification request xml data from payload """ | ||
""" Create a carrier specific pickup modification request xml data from payload """ | ||
raise Exception("Not Supported") | ||
|
||
def parse_pickup_response(self, response) -> Tuple[T.PickupDetails, List[T.Error]]: | ||
""" Create united API pickup result from carrier xml response """ | ||
""" Create a united API pickup result from carrier xml response """ | ||
raise Exception("Not Supported") | ||
|
||
def create_pickup_cancellation_request(self, payload: T.pickup_cancellation_request): | ||
""" Create carrier specific pickup cancellation request xml data from payload """ | ||
""" Create a carrier specific pickup cancellation request xml data from payload """ | ||
raise Exception("Not Supported") | ||
|
||
def parse_pickup_cancellation_response(self, response) -> Tuple[dict, List[T.Error]]: | ||
""" Create united API pickup cancellation result from carrier xml response """ | ||
""" Create a united API pickup cancellation result from carrier xml response """ | ||
raise Exception("Not Supported") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.