Skip to content

Commit

Permalink
update on_get
Browse files Browse the repository at this point in the history
  • Loading branch information
oboratav committed Oct 31, 2020
1 parent 05b3b1a commit 789e8af
Showing 1 changed file with 25 additions and 24 deletions.
49 changes: 25 additions & 24 deletions proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from zeep import Client, xsd
from zeep.cache import SqliteCache
from zeep.transports import Transport
from zeep.helpers import serialize_object

from reference import (ERRORS_CREATE_SHIPMENT, PROD_WSDL_URL, SUCCESSFUL,
TEST_WSDL_URL, QueryShipmentIdentifier)
Expand Down Expand Up @@ -76,33 +77,33 @@ def on_get(self, req, resp):
queryShipment
"""
identifiers = []
shipment_id = req.params.get("shipment_id", None)
invoice_id = req.params.get("invoice_id", None)
if not any(shipment_id, invoice_id):
shipment_id = req.get_param_as_list("shipment_id", None)
invoice_id = req.get_param_as_list("invoice_id", None)
add_historical_data = req.get_param_as_bool("add_historical_data", default=True)

if not any((shipment_id, invoice_id)):
raise falcon.HTTPBadRequest(title="400 Bad Request",
description="No shipment identifier was provided")
else:
if shipment_id is not None:
identifiers.extend(parameter_as_list(shipment_id))
identifier_type = QueryShipmentIdentifier.SHIPMENT_ID
query = req.context["client"].service.queryShipment(
wsUserName=req.context["username"],
wsPassword=req.context["password"],
wsLanguage="TR", # Fixed value
keys=identifiers,
keyType=identifier_type,
addHistoricalData=True, # hardcoded for now. will add a parameter for this later.
onlyTracking=False, # also hardcoded for now.
)
if query.outFlag == SUCCESSFUL:
resp.status = falcon.HTTP_OK
response = {

}
else:
identifiers.extend(parameter_as_list(invoice_id))
identifier_type = QueryShipmentIdentifier.INVOICE_ID

if shipment_id is not None:
identifiers.extend(parameter_as_list(shipment_id))
identifier_type = QueryShipmentIdentifier.SHIPMENT_ID
else:
identifiers.extend(parameter_as_list(invoice_id))
identifier_type = QueryShipmentIdentifier.INVOICE_ID

query = req.context["client"].service.queryShipment(
wsUserName=req.context["username"],
wsPassword=req.context["password"],
wsLanguage="TR", # Fixed value
keys=identifiers,
keyType=identifier_type,
addHistoricalData=add_historical_data, # hardcoded for now. will add a parameter for this later.
onlyTracking=False, # also hardcoded for now.
)
if query.outFlag == SUCCESSFUL:
resp.status = falcon.HTTP_OK
resp.body = json.dumps(serialize_object(query, target_cls=dict))

def on_delete(self, req, resp):
"""
Expand Down

0 comments on commit 789e8af

Please sign in to comment.