def Get(self, selector): """Return a list of ad group criteria. List of ad group criteria specified by the selector from the customer's account. Args: selector: dict Filter to run ad group criteria through. Returns: tuple List of ad group criteria meeting all the criteria of the selector. """ method_name = 'getAdGroupCriterion' selector_tag = AdWordsUtils.GetSelectorTag(self._op_config['version']) selector_type = AdWordsUtils.GetSelectorType('AdGroupCriterionSelector', self._op_config['version']) SanityCheck.NewSanityCheck(self._wsdl_types_map, selector, selector_type) if self._config['soap_lib'] == SOAPPY: selector = self._message_handler.PackVarAsXml( selector, selector_tag, self._wsdl_types_map, False, selector_type) return self.__service.CallMethod( method_name.split(self.__class__.__name__.split('Service')[0])[0], (selector)) elif self._config['soap_lib'] == ZSI: selector = self._transformation.MakeZsiCompatible( selector, selector_type, self._wsdl_types_map, self._web_services) request = eval('self._web_services.%sRequest()' % method_name) return self.__service.CallMethod(method_name, (({selector_tag: selector},)), 'AdGroupCriterion', self._loc, request)
def Mutate(self, op): """Add or update bulk mutate job. Args: op: dict Operation. Returns: tuple Mutated bulk mutate job. """ method_name = 'mutateBulkMutateJob' AdWordsUtils.TransformJobOperationXsi(op) SanityCheck.NewSanityCheck(self._wsdl_types_map, op, 'JobOperation') if self._config['soap_lib'] == SOAPPY: op = self._message_handler.PackVarAsXml( op, 'operation', self._wsdl_types_map, False, 'JobOperation') return self.__service.CallMethod( method_name.split(self.__class__.__name__.split('Service')[0])[0], (op)) elif self._config['soap_lib'] == ZSI: op = self._transformation.MakeZsiCompatible( op, 'JobOperation', self._wsdl_types_map, self._web_services) request = eval('self._web_services.%sRequest()' % method_name) return self.__service.CallMethod(method_name, (({'operation': op},)), 'BulkMutateJob', self._loc, request)
def Mutate(self, ops): """Add, update, or remove user lists. Args: ops: list Unique operations. Returns: tuple Mutated user lists. """ method_name = 'mutateUserList' SanityCheck.ValidateTypes(((ops, list),)) for op in ops: if 'operand' in op: AdWordsUtils.TransformUserListRuleOperands(op['operand']) SanityCheck.NewSanityCheck(self._wsdl_types_map, op, 'UserListOperation') if self._config['soap_lib'] == SOAPPY: new_ops = [] for op in ops: new_ops.append(self._message_handler.PackVarAsXml( op, 'operations', self._wsdl_types_map, False, 'UserListOperation')) return self.__service.CallMethod( method_name.split(self.__class__.__name__.split('Service')[0])[0], (''.join(new_ops))) elif self._config['soap_lib'] == ZSI: new_ops = [] for op in ops: new_ops.append(self._transformation.MakeZsiCompatible( op, 'UserListOperation', self._wsdl_types_map, self._web_services)) request = eval('self._web_services.%sRequest()' % method_name) return self.__service.CallMethod(method_name, (({'operations': new_ops},)), 'UserList', self._loc, request)
def _DetermineNamespacePrefix(url): """Returns the SOAP prefix to use for definitions within the given namespace. Args: url: string The URL of the namespace. Returns: string The SOAP namespace prefix to use for the given namespace. """ return AdWordsUtils.ExtractGroupNameFromUrl(url) + ':'
def _TakeActionOnSoapCall(self, method_name, args): """Gives the service a chance to take product-specific action on raw inputs. AdWords will support legacy xsi_typing for the BulkMutateJobService. Args: method_name: string The name of the SOAP operation being called. args: tuple The arguments passed into the SOAP operation. Returns: tuple The method arguments, possibly modified. """ if (self._service_name == 'BulkMutateJobService' and method_name.lower() == 'mutate'): AdWordsUtils.TransformJobOperationXsi(args[0]) elif (self._service_name == 'UserListService' and method_name.lower() == 'mutate'): if isinstance(args[0], (list, tuple)): for operation in args[0]: if isinstance(operation, dict) and 'operand' in operation: AdWordsUtils.TransformUserListRuleOperands(operation['operand']) return args
def __init__(self, headers, config, op_config, lock, logger, service_name): """Inits GenericAdWordsService. Args: headers: dict Dictionary object with populated authentication credentials. config: dict Dictionary object with populated configuration values. op_config: dict Dictionary object with additional configuration values for this operation. lock: thread.lock Thread lock to use to synchronize requests. logger: Logger Instance of Logger to use for logging. service_name: string The name of this service. Raises: ApiVersionNotSupportedError: If client login is used after v201309. """ if 'authToken' in headers and op_config['version'] > 'v201309': raise ApiVersionNotSupportedError('ClientLogin is not supported for this' ' version') group = op_config['group'] if service_name == 'BulkMutateJobService': group = 'job' service_url = [op_config['server'], 'api/adwords', group, op_config['version'], service_name] if config['access']: service_url.insert(len(service_url) - 1, config['access']) service_url = '/'.join(service_url) namespace = '/'.join(['https://adwords.google.com/api/adwords', op_config['group'], op_config['version']]) namespace_extractor = _DetermineNamespacePrefix super(GenericAdWordsService, self).__init__( headers, config, op_config, lock, logger, service_name, service_url, GenericAdWordsService._WRAP_LISTS, GenericAdWordsService._BUFFER_CLASS, namespace, namespace_extractor) # AdWords-specific changes to the SOAPpy.WSDL.Proxy methodattrs = {} for namespace in self._soappyservice.wsdl.types.keys(): group_name = AdWordsUtils.ExtractGroupNameFromUrl(namespace) methodattrs['xmlns:' + group_name] = namespace methodattrs['xmlns'] = self._namespace self._soappyservice.soapproxy.methodattrs = methodattrs
def testDataFileTimezones(self): """Test whether csv data file with timezones is valid.""" cols = 1 for item in AdWordsUtils.GetTimezones(): self.assertEqual(len(item), cols)
def testDataFileErrorCodes(self): """Test whether csv data file with error codes is valid.""" cols = 2 for item in AdWordsUtils.GetErrorCodes(): self.assertEqual(len(item), cols)
def testDataFileCurrencies(self): """Test whether csv data file with currencies is valid.""" cols = 2 for item in AdWordsUtils.GetCurrencies(): self.assertEqual(len(item), cols)