Skip to content

Commit

Permalink
(disable) dev dpdhl extension
Browse files Browse the repository at this point in the history
  • Loading branch information
danh91 committed Oct 14, 2023
1 parent 59cb062 commit 0a0f053
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 70 deletions.
File renamed without changes.
3 changes: 2 additions & 1 deletion sdk/extensions/dpdhl/generate
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ touch "${LIB_MODULES}/__init__.py"

quicktype () {
echo "Generating $1..."
docker run -it -v $PWD:/app -e SCHEMAS=/app/schemas -e LIB_MODULES=/app/karrio/schemas/dpdhl \
docker run -it -v $PWD:/app -e SCHEMAS=/app/schemas -e USER=$USER -e USERID=$UID -e LIB_MODULES=/app/karrio/schemas/dpdhl \
karrio/tools /quicktype/script/quicktype --no-uuids --no-date-times --no-enums --src-lang json --lang jstruct \
--no-nice-property-names --all-properties-optional --type-as-suffix $@
}

quicktype --src="${SCHEMAS}/cancel_response.json" --out="${LIB_MODULES}/cancel_response.py"
quicktype --src="${SCHEMAS}/error_response.json" --out="${LIB_MODULES}/error_response.py"
quicktype --src="${SCHEMAS}/shipping_request.json" --out="${LIB_MODULES}/shipping_request.py"
quicktype --src="${SCHEMAS}/shipping_response.json" --out="${LIB_MODULES}/shipping_response.py"
Expand Down
2 changes: 1 addition & 1 deletion sdk/extensions/dpdhl/karrio/mappers/dpdhl/mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def parse_cancel_shipment_response(
def parse_rate_response(
self, response: lib.Deserializable[str]
) -> typing.Tuple[typing.List[models.RateDetails], typing.List[models.Message]]:
return provider.parse_rate_response(response, self.settings)
return universal_provider.parse_rate_response(response, self.settings)

def parse_shipment_response(
self, response: lib.Deserializable[str]
Expand Down
4 changes: 2 additions & 2 deletions sdk/extensions/dpdhl/karrio/mappers/dpdhl/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def get_rates(self, request: lib.Serializable) -> lib.Deserializable[str]:

def create_shipment(self, request: lib.Serializable) -> lib.Deserializable[str]:
response = lib.request(
url=f"{self.settings.server_url}/orders",
url=f"{self.settings.server_url}/v2/orders",
data=request.serialize(),
trace=self.trace_as("json"),
method="POST",
Expand All @@ -30,7 +30,7 @@ def create_shipment(self, request: lib.Serializable) -> lib.Deserializable[str]:

def cancel_shipment(self, request: lib.Serializable) -> lib.Deserializable[str]:
response = lib.request(
url=f"{self.settings.server_url}/orders?profile=STANDARD_GRUPPENPROFIL&shipment={request.serialize()}",
url=f"{self.settings.server_url}/v2/orders?profile=STANDARD_GRUPPENPROFIL&shipment={request.serialize()}",
data=request.serialize(),
trace=self.trace_as("json"),
method="POST",
Expand Down
2 changes: 0 additions & 2 deletions sdk/extensions/dpdhl/karrio/providers/dpdhl/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@

from karrio.providers.dpdhl.utils import Settings
from karrio.providers.dpdhl.rate import parse_rate_response, rate_request
from karrio.providers.dpdhl.shipment import (
parse_shipment_cancel_response,
parse_shipment_response,
Expand Down
57 changes: 0 additions & 57 deletions sdk/extensions/dpdhl/karrio/providers/dpdhl/rate.py

This file was deleted.

25 changes: 20 additions & 5 deletions sdk/extensions/dpdhl/karrio/providers/dpdhl/shipment/create.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

import karrio.schemas.dpdhl.shipping_request as dpdhl
import karrio.schemas.dpdhl.shipping_response as shipping
import typing
import karrio.lib as lib
import karrio.core.units as units
Expand Down Expand Up @@ -49,14 +50,28 @@ def shipment_request(
payload: models.ShipmentRequest,
settings: provider_utils.Settings,
) -> lib.Serializable:
packages = lib.to_packages(payload.parcels) # preprocess the request parcels
service = provider_units.ShippingService.map(payload.service).value_or_key # preprocess the request services
packages = lib.to_packages(payload.parcels)
service = provider_units.ShippingService.map(payload.service).value_or_key
options = lib.to_shipping_options(
payload.options,
package_options=packages.options,
option_type=provider_units.ShippingOption,
) # preprocess the request options
)

request = None # map data to convert karrio model to dpdhl specific type
request = dpdhl.ShippingRequestType(
profile=None,
shipments=[
dpdhl.ShipmentType(
product=None,
billingNumber=None,
refNo=None,
shipper=dpdhl.ConsigneeType(),
consignee=None,
details=None,
customs=None,
services=None,
)
],
)

return lib.Serializable(request)
4 changes: 2 additions & 2 deletions sdk/extensions/dpdhl/karrio/providers/dpdhl/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ def carrier_name(self):
@property
def server_url(self):
return (
"https://api-sandbox.dhl.com/parcel/de/shipping/v2"
"https://api-sandbox.dhl.com/parcel/de/shipping"
if self.test_mode
else "https://api-eu.dhl.com/parcel/de/shipping/v2"
else "https://api-eu.dhl.com/parcel/de/shipping"
)

@property
Expand Down
36 changes: 36 additions & 0 deletions sdk/extensions/dpdhl/karrio/schemas/dpdhl/cancel_response.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from attr import s
from typing import Optional, List
from jstruct import JStruct, JList


@s(auto_attribs=True)
class LabelType:
url: Optional[str] = None
format: Optional[str] = None


@s(auto_attribs=True)
class SstatusType:
title: Optional[str] = None
status: Optional[int] = None


@s(auto_attribs=True)
class ItemType:
shipmentNo: Optional[int] = None
sstatus: Optional[SstatusType] = JStruct[SstatusType]
label: Optional[LabelType] = JStruct[LabelType]


@s(auto_attribs=True)
class StatusType:
title: Optional[str] = None
statusCode: Optional[int] = None
instance: Optional[str] = None
detail: Optional[str] = None


@s(auto_attribs=True)
class CancelResponseType:
status: Optional[StatusType] = JStruct[StatusType]
items: List[ItemType] = JList[ItemType]
21 changes: 21 additions & 0 deletions sdk/extensions/dpdhl/schemas/cancel_response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"status": {
"title": "ok",
"statusCode": 200,
"instance": "string",
"detail": "The Webservice call ran successfully."
},
"items": [
{
"shipmentNo": 340434310428091700,
"sstatus": {
"title": "OK",
"status": 200
},
"label": {
"url": "https://api-dev.dhl.com/parcel/de/shipping/v1-feature-order-endpoint/labels?token=x5xzrHE7ctmqPqk33k%2BKkBwbvIfYP4elMQsBFM%2BJOdiT2bmoaXXzris%2Ftz9jBtdVFLY5cCENit0Jnd9aXuxoNEXhP9PQ8tAVdPeXD26RZ6JZqF5NCJlrihrAv1%2FAOzuDPqWJLRVaRq461BpT4bcbzChAAHVg%2FHUaQAkeIkaZ8NqfcxWEQzK1AYJWczpy6sv6",
"format": "PDF"
}
}
]
}

0 comments on commit 0a0f053

Please sign in to comment.