Permalink
Browse files

Use an easier overridable client-factory, with support for proxies

  • Loading branch information...
1 parent ef3b1e3 commit 7ab6d315fe32dc253f96de0995706ab23347bfc4 @alexbrasetvik alexbrasetvik committed Feb 17, 2012
Showing with 28 additions and 26 deletions.
  1. +16 −1 payex/handlers.py
  2. +6 −13 payex/pxagreement.py
  3. +6 −12 payex/pxorder.py
View
@@ -1,3 +1,4 @@
+import os
try:
from collections import OrderedDict
@@ -8,7 +9,7 @@
import hashlib
import logging
-from suds import WebFault
+from suds import WebFault, client
from payex.utils import XmlDictConfig, normalize_dictionary_values, smart_str
@@ -103,3 +104,17 @@ def _send_request(self):
logger.error(resp)
return self.response
+
+ def client_factory(self):
+ if self._service.production:
+ url = self.production_url
+ else:
+ url = self.testing_url
+
+ proxy_options = dict()
+ if os.environ.get('https_proxy'):
+ proxy_options['https'] = os.environ['https_proxy']
+ if os.environ.get('http_proxy'):
+ proxy_options['http'] = os.environ['http_proxy']
+
+ return client.Client(url, proxy=proxy_options)
View
@@ -1,26 +1,19 @@
-from suds.client import Client
-
from payex.handlers import BaseHandler
class PxAgreementHandler(BaseHandler):
"""
Base handler for PxAgreement methods.
"""
-
+
+ production_url = 'https://external.payex.com/pxagreement/pxagreement.asmx?WSDL'
+ testing_url = 'https://test-external.payex.com/pxagreement/pxagreement.asmx?WSDL'
+
def __call__(self, *args, **kwargs):
-
# Set the parameters on object
for key, value in kwargs.iteritems():
setattr(self, key, value)
-
- # Which WDSL URL to use
- if self._service.production:
- self._wdsl_url = 'https://external.payex.com/pxagreement/pxagreement.asmx?WSDL'
- else:
- self._wdsl_url = 'https://test-external.payex.com/pxagreement/pxagreement.asmx?WSDL'
-
- # Initialize the client with the WDSL schema
- self._client = Client(self._wdsl_url)
+
+ self._client = self.client_factory()
###################
# METHOD HANDLERS #
View
@@ -1,26 +1,20 @@
-from suds.client import Client
-
from payex.handlers import BaseHandler
class PxOrderHandler(BaseHandler):
"""
Base handler for PxOrder methods.
"""
-
+
+ production_url = 'https://external.payex.com/pxorder/pxorder.asmx?WSDL'
+ testing_url = 'https://test-external.payex.com/pxorder/pxorder.asmx?WSDL'
+
def __call__(self, *args, **kwargs):
# Set the parameters on object
for key, value in kwargs.iteritems():
setattr(self, key, value)
-
- # Which WDSL URL to use
- if self._service.production:
- self._wdsl_url = 'https://external.payex.com/pxorder/pxorder.asmx?WSDL'
- else:
- self._wdsl_url = 'https://test-external.payex.com/pxorder/pxorder.asmx?WSDL'
-
- # Initialize the client with the WDSL schema
- self._client = Client(self._wdsl_url)
+
+ self._client = self.client_factory()
###################
# METHOD HANDLERS #

0 comments on commit 7ab6d31

Please sign in to comment.