-
Notifications
You must be signed in to change notification settings - Fork 21
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 #84 from akretion/develop
2.0
- Loading branch information
Showing
19 changed files
with
473 additions
and
70 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
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 +1 @@ | ||
0.1.6 | ||
0.2.0 |
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
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,6 +1,9 @@ | ||
# -*- coding: utf-8 -*- | ||
from . import geodis | ||
from . import geodis_api | ||
from . import geodis_encoder | ||
from . import geodis_api_ws | ||
from . import geodis_api_edi | ||
from . import geodis_encoder_ws | ||
from . import geodis_encoder_edi | ||
from . import geodis_decoder | ||
from . import geodis_transport | ||
from . import geodis_transport_ws | ||
from . import geodis_transport_edi |
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,32 +1,60 @@ | ||
# -*- coding: utf-8 -*- | ||
"""Implementation for Geodis.""" | ||
from geodis_encoder import GeodisEncoder | ||
from geodis_encoder_edi import GeodisEncoderEdi | ||
from geodis_encoder_ws import GeodisEncoderWs | ||
from geodis_decoder import GeodisDecoder | ||
from geodis_transport import GeodisTransport | ||
from geodis_transport_ws import GeodisTransportWs | ||
from geodis_transport_edi import GeodisTransportEdi | ||
from roulier.carrier import Carrier | ||
from roulier.exception import InvalidAction | ||
|
||
|
||
class Geodis(Carrier): | ||
"""Implementation for Geodis.""" | ||
|
||
encoder = GeodisEncoder() | ||
decoder = GeodisDecoder() | ||
ws = GeodisTransport() | ||
|
||
def api(self): | ||
def api(self, action='label'): | ||
"""Expose how to communicate with Geodis.""" | ||
return self.encoder.api() | ||
try: | ||
method = self.ACTIONS[action] | ||
except: | ||
raise InvalidAction("Action not supported") | ||
return method(self, None, api=True) | ||
|
||
def get(self, data, action): | ||
"""Run an action with data against Geodis WS.""" | ||
request = self.encoder.encode(data, action) | ||
response = self.ws.send(request) | ||
return self.decoder.decode( | ||
""".""" | ||
try: | ||
method = self.ACTIONS[action] | ||
except: | ||
raise InvalidAction("Action not supported") | ||
|
||
return method(self, data) | ||
|
||
def get_label(self, data, api=False): | ||
"""Genereate a demandeImpressionEtiquette.""" | ||
encoder = GeodisEncoderWs() | ||
decoder = GeodisDecoder() | ||
transport = GeodisTransportWs() | ||
|
||
if api: | ||
return encoder.api() | ||
|
||
request = encoder.encode(data, "demandeImpressionEtiquette") | ||
response = transport.send(request) | ||
return decoder.decode( | ||
response['body'], | ||
response['parts'], | ||
request['output_format']) | ||
|
||
# shortcuts | ||
def get_label(self, data): | ||
"""Genereate a generateLabelRequest.""" | ||
return self.get(data, 'demandeImpressionEtiquette') | ||
def get_edi(self, data, api=False): | ||
encoder = GeodisEncoderEdi() | ||
transport = GeodisTransportEdi() | ||
if api: | ||
return encoder.api() | ||
arr = encoder.encode(data) | ||
return transport.send(arr) | ||
|
||
ACTIONS = { | ||
'label': get_label, | ||
'demandeImpressionEtiquette': get_label, | ||
'edi': get_edi | ||
} |
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,90 @@ | ||
# -*- coding: utf-8 -*- | ||
"""Implementation of Geodis Api.""" | ||
from roulier.api import Api, MyValidator | ||
from .geodis_api_ws import GeodisApiWs | ||
|
||
|
||
class GeodisApiEdi(Api): | ||
def _service(self): | ||
schema = { | ||
"depositId": { | ||
'type': 'string', | ||
'default': '', 'empty': False, 'required': True}, | ||
"depositDate": { | ||
'type': 'datetime', | ||
'default': '', 'empty': False, 'required': True}, | ||
"customerId": { | ||
'type': 'string', | ||
'default': '', 'empty': False, 'required': True}, | ||
"interchangeSender": { | ||
'type': 'string', | ||
'default': '', 'empty': False, 'required': True}, | ||
"interchangeRecipient": { | ||
'type': 'string', | ||
'default': '', 'empty': False, 'required': True}, | ||
} | ||
return schema | ||
|
||
def _address(self): | ||
schema = super(GeodisApiEdi, self)._address() | ||
schema['country'].update({ | ||
'required': True, 'empty': False, | ||
'maxlength': 2}) | ||
schema['zip'].update({'required': True, 'empty': False}) | ||
schema['city'].update({'required': True, 'empty': False}) | ||
return schema | ||
|
||
def _from_address(self): | ||
schema = super(GeodisApiEdi, self)._from_address() | ||
schema['phone'].update({'required': True, 'empty': False}) | ||
schema['street1']['required'] = True | ||
schema['siret'] = { | ||
'type': 'string', 'required': True, | ||
'default': '', 'empty': False} | ||
return schema | ||
|
||
def _parcel(self): | ||
weight = GeodisApiWs()._parcel()['weight'] | ||
return { | ||
'weight': weight, | ||
'barcode': { | ||
'type': 'string', 'empty': False, 'default': '', | ||
'required': True, | ||
'description': 'Barcode of the parcel'} | ||
} | ||
|
||
def _shipments(self): | ||
ws_api = GeodisApiWs() | ||
v = MyValidator() | ||
schema = { | ||
'to_address': { | ||
'type': 'dict', | ||
'schema': ws_api._to_address(), | ||
'default': v.normalized({}, ws_api._to_address()) | ||
}, | ||
'parcels': { | ||
'type': 'list', | ||
'schema': self._parcel(), | ||
'default': [v.normalized({}, self._parcel())] | ||
}, | ||
'product': {'type': 'string', 'default': '', 'empty': False, 'required': True}, | ||
'productOption': {'type': 'string', 'default': '', 'empty': True, 'required': False}, | ||
'productTOD': {'type': 'string', 'default': '', 'empty': True, 'required': False}, | ||
'shippingId': {'type': 'string', 'default': '', 'empty': False, 'required': True}, | ||
'reference1': {'type': 'string', 'default': '', 'empty': True}, | ||
'reference2': {'type': 'string', 'default': '', 'empty': True}, | ||
'reference3': {'type': 'string', 'default': '', 'empty': True}, | ||
} | ||
return { | ||
"type": "list", | ||
"schema": {'type': 'dict', 'schema': schema}, | ||
"default": [v.normalized({}, schema)], | ||
} | ||
|
||
def _schemas(self): | ||
return { | ||
'service': self._service(), | ||
'shipments': self._shipments(), | ||
'agency_address': self._from_address(), | ||
'from_address': self._from_address(), | ||
} |
Oops, something went wrong.