def testCallMethodDirect(self): """Test whether we can call an API method directly.""" headers = client.GetAuthCredentials() config = client.GetConfigValues() url = 'https://sandbox.google.com/api/adwords/v13/AccountService' op_config = { 'server': self.__class__.SERVER, 'version': self.__class__.VERSION, 'http_proxy': None } lock = thread.allocate_lock() service = WebService(headers, config, op_config, url, lock) soap_lib = config['soap_lib'] method_name = 'getAccountInfo' if soap_lib == SOAPPY: self.assert_(isinstance(service.CallMethod(method_name, ()), tuple)) elif soap_lib == ZSI: web_services = __import__( 'aw_api.zsi_toolkit.v13.AccountService_services', globals(), locals(), ['']) loc = web_services.AccountServiceLocator() request = eval('web_services.%sRequest()' % method_name) self.assert_( isinstance( service.CallMethod(method_name, (), 'Account', loc, request), tuple))
def CallMethod(self, url, method, params, http_proxy): """Call API method directly, using its service's URL. For API calls performed with this method, outgoing data is not run through library's validation logic. Args: url: str URL of the API service for the method to call. method: str name of the API method to call. params: list list of parameters to send to the API method. http_proxy: str HTTP proxy to use for this API call. Returns: tuple response from the API method. """ headers = self.__GetAuthCredentialsForAccessLevel() # Load additional configuration data. op_config = { 'server': Utils.GetServerFromUrl(url), 'version': Utils.GetVersionFromUrl(url), 'http_proxy': http_proxy } service = WebService(headers, self.__config, op_config, url, self.__lock, self.__logger) if self.__config['soap_lib'] == ZSI: # Check format of parameters. Example of valid formats, # - () # - ({'dummy': 0},) # - ({'campaignIds': ['11111']}, # {'startDay': '2008-07-01'}, # {'endDay': '2008-07-31'}) # # TODO(api.sgrinberg: Figure out how to match the order of params with # those in Holder object below. Then, we don't need to require client code # to provide key/value pairs, just values will be enough (see, issue# 31). try: SanityCheck.ValidateTypes(((params, tuple), )) for item in params: SanityCheck.ValidateTypes(((item, dict), )) except ValidationError: msg = 'Invalid format of parameters, expecting a tuple of dicts.' raise ValidationError(msg) # From the URL, get service being accessed and version used. url_parts = url.split('/') service_name = url_parts[len(url_parts) - 1].split('Service')[0] version = url_parts[len(url_parts) - 2] from aw_api import API_VERSIONS if version in API_VERSIONS: web_services = __import__( 'aw_api.zsi_toolkit.%s.%sService_services' % (version, service_name), globals(), locals(), ['']) else: msg = 'Invalid API version, not one of %s.' % str( list(API_VERSIONS)) raise ValidationError(msg) eval('%sService' % service_name).web_services = web_services self.__loc = eval(('%sService.web_services.%sServiceLocator()' % (service_name, service_name))) request = eval('%sService.web_services.%sRequest()' % (service_name, method)) return service.CallMethod(method, (params), service_name, self.__loc, request) else: return service.CallMethod(method, (params))