Skip to content

Commit

Permalink
* Fixes issue #5. (for adwords, dfa, and dfp)
Browse files Browse the repository at this point in the history
  • Loading branch information
msaniscalchi committed Apr 23, 2014
1 parent 08397da commit 854169e
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 20 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
1.0.4 - 04/22/2014
* Fixed a bug where https_proxy wasn't set for retrieving the API WSDL. This
resolves issue #5.

1.0.3 - 04/02/2014
==================
* The common module's LoadFromStorage method now parses the yaml file with
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ def main(client):
statement.ToStatement())
if result and int(result['numChanges']) > 0:
num_approved_suggested_ad_units += int(result['numChanges'])
statement.offset += dfp.SUGGESTED_PAGE_LIMIT
else:
break

Expand Down
10 changes: 8 additions & 2 deletions googleads/adwords.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,16 @@ def GetService(self, service_name, version=sorted(_SERVICE_MAP.keys())[-1],
"""
if server[-1] == '/': server = server[:-1]
try:
proxy_option = None
if self.https_proxy:
proxy_option = {
'https': self.https_proxy
}

client = suds.client.Client(
self._SOAP_SERVICE_FORMAT %
(server, _SERVICE_MAP[version][service_name], version, service_name))
(server, _SERVICE_MAP[version][service_name], version, service_name),
proxy=proxy_option)
except KeyError:
if version in _SERVICE_MAP:
raise googleads.errors.GoogleAdsValueError(
Expand All @@ -202,7 +209,6 @@ def GetService(self, service_name, version=sorted(_SERVICE_MAP.keys())[-1],
'Unrecognized version of the AdWords API. Version given: %s '
'Supported versions: %s' % (version, _SERVICE_MAP.keys()))

if self.https_proxy: client.set_options(proxy={'https': self.https_proxy})
return googleads.common.SudsServiceProxy(
client, _AdWordsHeaderHandler(self, version))

Expand Down
2 changes: 1 addition & 1 deletion googleads/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import googleads.errors
import googleads.oauth2

VERSION = '1.0.3'
VERSION = '1.0.4'
_COMMON_LIB_SIG = 'googleads/%s' % VERSION
_PYTHON_VERSION = 'Python/%d.%d' % (sys.version_info[0], sys.version_info[1])

Expand Down
10 changes: 8 additions & 2 deletions googleads/dfa.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,15 @@ def GetService(self, service_name, version=sorted(_SERVICE_MAP.keys())[-1],
"""
server = server[:-1] if server[-1] == '/' else server
try:
proxy_option = None
if self.https_proxy:
proxy_option = {
'https': self.https_proxy
}

client = suds.client.Client(
self._SOAP_SERVICE_FORMAT % (server, version, service_name))
self._SOAP_SERVICE_FORMAT % (server, version, service_name),
proxy=proxy_option)
except suds.transport.TransportError:
if version in self._SERVICE_MAP:
if service_name in self._SERVICE_MAP[version]:
Expand All @@ -145,7 +152,6 @@ def GetService(self, service_name, version=sorted(_SERVICE_MAP.keys())[-1],
'Unrecognized version of the DFA API. Version given: %s Supported '
'versions: %s' % (version, self._SERVICE_MAP.keys()))

if self.https_proxy: client.set_options(proxy={'https': self.https_proxy})
return googleads.common.SudsServiceProxy(client, self._header_handler)


Expand Down
10 changes: 8 additions & 2 deletions googleads/dfp.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,15 @@ def GetService(self, service_name, version=sorted(_SERVICE_MAP.keys())[-1],
"""
server = server[:-1] if server[-1] == '/' else server
try:
proxy_option = None
if self.https_proxy:
proxy_option = {
'https': self.https_proxy
}

client = suds.client.Client(
self._SOAP_SERVICE_FORMAT % (server, version, service_name))
self._SOAP_SERVICE_FORMAT % (server, version, service_name),
proxy=proxy_option)
except suds.transport.TransportError:
if version in _SERVICE_MAP:
if service_name in _SERVICE_MAP[version]:
Expand All @@ -169,7 +176,6 @@ def GetService(self, service_name, version=sorted(_SERVICE_MAP.keys())[-1],
'Unrecognized version of the DFP API. Version given: %s Supported '
'versions: %s' % (version, _SERVICE_MAP.keys()))

if self.https_proxy: client.set_options(proxy={'https': self.https_proxy})
return googleads.common.SudsServiceProxy(client, self._header_handler)

def GetDataDownloader(self, version=sorted(_SERVICE_MAP.keys())[-1],
Expand Down
6 changes: 2 additions & 4 deletions tests/adwords_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,7 @@ def testGetService_success(self):

mock_client.assert_called_once_with(
'https://testing.test.com/api/adwords/%s/%s/%s?wsdl'
% (namespace, version, service))
mock_client.return_value.set_options.assert_called_once_with(
proxy=https_proxy)
% (namespace, version, service), proxy=https_proxy)
self.assertIsInstance(suds_service, googleads.common.SudsServiceProxy)

# Use the default server and https_proxy.
Expand All @@ -166,7 +164,7 @@ def testGetService_success(self):

mock_client.assert_called_once_with(
'https://adwords.google.com/api/adwords/%s/%s/%s?wsdl'
% (namespace, version, service))
% (namespace, version, service), proxy=None)
self.assertFalse(mock_client.return_value.set_options.called)
self.assertIsInstance(suds_service, googleads.common.SudsServiceProxy)

Expand Down
6 changes: 2 additions & 4 deletions tests/dfa_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,7 @@ def testGetService_success(self):

mock_client.assert_called_once_with(
'https://testing.test.com/%s/api/dfa-api/%s?wsdl'
% (version, service))
mock_client.return_value.set_options.assert_called_once_with(
proxy=https_proxy)
% (version, service), proxy=https_proxy)
self.assertIsInstance(suds_service, googleads.common.SudsServiceProxy)

# Use the default server and https_proxy.
Expand All @@ -118,7 +116,7 @@ def testGetService_success(self):

mock_client.assert_called_once_with(
'https://advertisersapi.doubleclick.com/%s/api/dfa-api/%s?wsdl'
% (version, service))
% (version, service), proxy=None)
self.assertFalse(mock_client.return_value.set_options.called)
self.assertIsInstance(suds_service, googleads.common.SudsServiceProxy)

Expand Down
6 changes: 2 additions & 4 deletions tests/dfp_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,7 @@ def testGetService_success(self):

mock_client.assert_called_once_with(
'https://testing.test.com/apis/ads/publisher/%s/%s?wsdl'
% (version, service))
mock_client.return_value.set_options.assert_called_once_with(
proxy=https_proxy)
% (version, service), proxy=https_proxy)
self.assertIsInstance(suds_service, googleads.common.SudsServiceProxy)

# Use the default server and https proxy.
Expand All @@ -109,7 +107,7 @@ def testGetService_success(self):

mock_client.assert_called_once_with(
'https://www.google.com/apis/ads/publisher/%s/%s?wsdl'
% (version, service))
% (version, service), proxy=None)
self.assertFalse(mock_client.return_value.set_options.called)
self.assertIsInstance(suds_service, googleads.common.SudsServiceProxy)

Expand Down

0 comments on commit 854169e

Please sign in to comment.