# Path: roulier/transport.py
# class RequestsTransport(ABC):
#     def __init__(self, config_object):
#     def before_ws_call_prepare_request_kwargs(self, payload):
#     def before_ws_call_transform_payload(self, payload):
#     def send(self, payload):
#     def _get_requests_headers(self, payload=None):
#     def _get_requests_auth(self, payload=None):
#     def _get_requests_url(self, payload=None):
#     def send_request(self, body, url, auth=None, headers=None, method="post", **kwargs):
#     def handle_200(self, response):
#     def handle_500(self, response):
#     def handle_response(self, response):
# 
# Path: roulier/exception.py
# class CarrierError(Exception):
#     """Error from WS.
# 
#     Use this class in your application to manage
#     exception with the carrier WS
#     """
# 
#     def __init__(self, response, msg=None):
#         if msg is None:
#             msg = "An error occured with WS"
#         super(CarrierError, self).__init__(msg)
#         self.response = response
#         if self.response:
#             if hasattr(self.response, "text"):
#                 log.debug(response.text)
#             else:
#                 log.debug(response)


import requests
import json
import logging
import hashlib
import time
from roulier.transport import Transport
from roulier.exception import CarrierError
        )

        infos = payload["infos"]
        infos["token"] = token

        response = self.send_request(body, infos)
        log.info("WS response time %s" % response.elapsed.total_seconds())
        return self.handle_response(response)

    def send_request(self, body, infos):
        """Send body to geodis WS."""
        ws_url = infos["url"]
        token = infos["token"]
        return requests.post(ws_url, headers={"X-GEODIS-Service": token,}, data=body,)

    def handle_500(self, response):
        """Handle reponse in case of ERROR 500 type."""
        # TODO : put a try catch (like wrong server)
        log.warning("Geodis error 500")
        errors = [{"id": "", "message": "",}]
        raise CarrierError(response, errors)

    def handle_true_negative_error(self, response, payload):
        """When servers answer an error with a 200 status code."""
        errors = [
            {
                "id": payload.get("codeErreur", ""),
                "message": payload.get("texteErreur", ""),
            }
        ]

# Path: roulier/transport.py
# class RequestsTransport(ABC):
#     def __init__(self, config_object):
#     def before_ws_call_prepare_request_kwargs(self, payload):
#     def before_ws_call_transform_payload(self, payload):
#     def send(self, payload):
#     def _get_requests_headers(self, payload=None):
#     def _get_requests_auth(self, payload=None):
#     def _get_requests_url(self, payload=None):
#     def send_request(self, body, url, auth=None, headers=None, method="post", **kwargs):
#     def handle_200(self, response):
#     def handle_500(self, response):
#     def handle_response(self, response):
# 
# Path: roulier/exception.py
# class CarrierError(Exception):
#     """Error from WS.
# 
#     Use this class in your application to manage
#     exception with the carrier WS
#     """
# 
#     def __init__(self, response, msg=None):
#         if msg is None:
#             msg = "An error occured with WS"
#         super(CarrierError, self).__init__(msg)
#         self.response = response
#         if self.response:
#             if hasattr(self.response, "text"):
#                 log.debug(response.text)
#             else:
#                 log.debug(response)


# Path: roulier/carriers/geodis/geodis_transport_rest_ws.py
import requests
import json
import logging
import hashlib
import time
from roulier.transport import Transport
from roulier.exception import CarrierError

        )

        infos = payload["infos"]
        infos["token"] = token

        response = self.send_request(body, infos)
        log.info("WS response time %s" % response.elapsed.total_seconds())
        return self.handle_response(response)

    def send_request(self, body, infos):
        """Send body to geodis WS."""
        ws_url = infos["url"]
        token = infos["token"]
        return requests.post(ws_url, headers={"X-GEODIS-Service": token,}, data=body,)

    def handle_500(self, response):
        """Handle reponse in case of ERROR 500 type."""
        # TODO : put a try catch (like wrong server)
        log.warning("Geodis error 500")
        errors = [{"id": "", "message": "",}]
        raise CarrierError(response, errors)

    def handle_true_negative_error(self, response, payload):
        """When servers answer an error with a 200 status code."""
        errors = [
            {
                "id": payload.get("codeErreur", ""),
                "message": payload.get("texteErreur", ""),
            }
        ]

        raise CarrierError(response, errors)