def _get_client(request_reference, config): if requests: debug = "{0} Using the 'requests' library".format(request_reference) securetrading.util.logger.debug(debug) client = HTTPRequestsClient(config) else: msg = "No request library found" raise securetrading.SecureTradingError("2", data=[msg]) return client
def _get_requests_lib(): try: import requests split_version = requests.__version__.split(".") requests_version = requests.__version__ except ImportError as e: requests = None split_version = ["0", "0", "0"] requests_version = "Not found" requests_version = tuple(map(int, split_version)) min_requests_version = securetrading.util.min_requests_version if requests_version < min_requests_version: data = ["Current requests version: {0}".format(requests_version)] raise securetrading.SecureTradingError("2", data=data) return requests
def _verify_request(self, request): if not isinstance(request, securetrading.Request): data = ["Incorrect type of request specified"] raise securetrading.SecureTradingError("10", data=data)
def _verify_result(self, result, request_reference): if result.get("requestreference") != request_reference: msg = "Different request reference: sent ({0}) received ({1})"\ .format(request_reference, result.get("requestreference")) data = [msg] raise securetrading.SecureTradingError("9", data=data)
def _generate_error(self, e, request_reference): excep = "Secure Trading API had an unexpected error" securetrading.util.logger.exception(excep) data = ["{0}".format("\n".join(e.args))] error = securetrading.SecureTradingError("9", data=data) return self._generate_st_error(error, request_reference)