def encode(self, api_input, action):
"""Transform input to laposte compatible xml."""
if not (action in LAPOSTE_ACTIONS):
raise InvalidApiInput(
'action %s not in %s' % (action, ', '.join(LAPOSTE_ACTIONS)))
api = LaposteApi()
if not api.validate(api_input):
_logger.warning('Laposte api call exception:')
raise InvalidApiInput(
{'api_call_exception': api.errors(api_input)})
data = api.normalize(api_input)
data['service']['labelFormat'] = self.lookup_label_format(
data['service']['labelFormat'])
env = Environment(
loader=PackageLoader('roulier', '/carriers/laposte/templates'),
extensions=['jinja2.ext.with_', 'jinja2.ext.autoescape'],
autoescape=True)
template = env.get_template("laposte_%s.xml" % action)
return {
"body": template.render(
service=data['service'],
parcel=data['parcels'][0],
auth=data['auth'],
sender_address=data['from_address'],
receiver_address=data['to_address'],
customs=data['customs']),
"headers": data['auth'],
"output_format": data['service']['labelFormat']
}
评论列表
文章目录