def testGetAllEntitiesByStatement(self): """Test whether GetAllEntitiesByStatement() does what it suppose to.""" users = DfpUtils.GetAllEntitiesByStatement( client, 'User', 'ORDER BY name', server=self.__class__.SERVER, version=self.__class__.VERSION, http_proxy=HTTP_PROXY) self.assert_(isinstance(users, list))
def testGetAllEntitiesByStatement(self): client = mock.Mock() line_item_service = mock.Mock() rval = 'Line items for everyone!' def VerifyExpectedCall(arg): self.assertEqual( { 'values': None, 'query': 'ORDER BY name LIMIT 500 OFFSET 0' }, arg) return [{'results': [rval]}] client.GetLineItemService.return_value = line_item_service line_item_service._service_name = 'LineItemService' line_item_service.GetLineItemsByStatement.side_effect = VerifyExpectedCall line_items = DfpUtils.GetAllEntitiesByStatement( client, 'LineItem', 'ORDER BY name') self.assertEqual([rval], line_items)
# Initialize client object. client = DfpClient(path=os.path.join('..', '..', '..', '..')) # Initialize appropriate service. By default, the request is always made against # sandbox environment. user_service = client.GetUserService('https://sandbox.google.com', 'v201010') # Set the id of the user to deactivate. user_id = 'INSERT_USER_ID_HERE' # Create query. query = 'WHERE id = \'%s\'' % user_id # Get users by statement. users = DfpUtils.GetAllEntitiesByStatement(client, 'User', query) for user in users: print( 'User with id \'%s\', email \'%s\', and status \'%s\' will be ' 'deactivated.' % (user['id'], user['email'], { 'true': 'ACTIVE', 'false': 'INACTIVE' }[user['isActive']])) print 'Number of users to be deactivated: %s' % len(users) # Perform action. result = user_service.PerformUserAction({'type': 'DeactivateUsers'}, {'query': query})[0] # Display results. if result and int(result['numChanges']) > 0:
__author__ = '[email protected] (Stan Grinberg)' # Locate the client library. If module was installed via "setup.py" script, then # the following two lines are not needed. import os import sys sys.path.append(os.path.join('..', '..', '..', '..')) # Import appropriate classes from the client library. from adspygoogle.dfp import DfpUtils from adspygoogle.dfp.DfpClient import DfpClient # Initialize client object. client = DfpClient(path=os.path.join('..', '..', '..', '..')) # Initialize appropriate service. By default, the request is always made against # sandbox environment. order_service = client.GetOrderService('https://sandbox.google.com', 'v201010') # Get orders by statement. orders = DfpUtils.GetAllEntitiesByStatement(client, 'Order') # Display results. for order in orders: print( 'Order with id \'%s\', name \'%s\', and advertiser id \'%s\' was ' 'found.' % (order['id'], order['name'], order['advertiserId'])) print print 'Number of results found: %s' % len(orders)
# Initialize client object. client = DfpClient(path=os.path.join('..', '..', '..', '..')) # Initialize appropriate service. By default, the request is always made against # sandbox environment. line_item_service = client.GetLineItemService( 'https://sandbox.google.com', 'v201010') # Set the id of the order to get line items from. order_id = 'INSERT_ORDER_ID_HERE' # Create query. query = 'WHERE orderId = \'%s\' AND status = \'NEEDS_CREATIVES\'' % order_id # Get line items by statement. line_items = DfpUtils.GetAllEntitiesByStatement(client, 'LineItem', query) for line_item in line_items: print ('Line item with id \'%s\', belonging to order id \'%s\', and name ' '\'%s\' will be activated.' % (line_item['id'], line_item['orderId'], line_item['name'])) print 'Number of line items to be activated: %s' % len(line_items) # Perform action. result = line_item_service.PerformLineItemAction({'type': 'ActivateLineItems'}, {'query': query})[0] # Display results. if result and int(result['numChanges']) > 0: print 'Number of line items activated: %s' % result['numChanges'] else: print 'No line items were activated.'
__author__ = '[email protected] (Stan Grinberg)' # Locate the client library. If module was installed via "setup.py" script, then # the following two lines are not needed. import os import sys sys.path.append(os.path.join('..', '..', '..', '..')) # Import appropriate classes from the client library. from adspygoogle.dfp import DfpUtils from adspygoogle.dfp.DfpClient import DfpClient # Initialize client object. client = DfpClient(path=os.path.join('..', '..', '..', '..')) # Initialize appropriate service. By default, the request is always made against # sandbox environment. placement_service = client.GetPlacementService('https://sandbox.google.com', 'v201103') # Get placements by statement. placements = DfpUtils.GetAllEntitiesByStatement(client, 'Placement') # Display results. for placement in placements: print('Placement with id \'%s\' and name \'%s\' was found.' % (placement['id'], placement['name'])) print print 'Number of results found: %s' % len(placements)
# the following two lines are not needed. import os import sys sys.path.append(os.path.join('..', '..', '..', '..')) # Import appropriate classes from the client library. from adspygoogle.dfp import DfpUtils from adspygoogle.dfp.DfpClient import DfpClient # Initialize client object. client = DfpClient(path=os.path.join('..', '..', '..', '..')) # Initialize appropriate service. By default, the request is always made against # sandbox environment. lica_service = client.GetLineItemCreativeAssociationService( 'https://sandbox.google.com', 'v201101') # Get LICAs by statement. licas = DfpUtils.GetAllEntitiesByStatement(client, 'LineItemCreativeAssociation') # Display results. for lica in licas: print ('LICA with line item id \'%s\', creative id \'%s\', and status ' '\'%s\' was found.' % (lica['lineItemId'], lica['creativeId'], lica['status'])) print print 'Number of results found: %s' % len(licas)
from adspygoogle.dfp.DfpClient import DfpClient # Initialize client object. client = DfpClient(path=os.path.join('..', '..', '..', '..')) # Initialize appropriate service. By default, the request is always made against # sandbox environment. inventory_service = client.GetInventoryService( 'https://sandbox.google.com', 'v201103') # Create query. query = 'WHERE status = \'ACTIVE\'' # Get ad units by statement. ad_units = DfpUtils.GetAllEntitiesByStatement(client, 'Inventory', query) for ad_unit in ad_units: print ('Ad unit with id \'%s\', name \'%s\', and status \'%s\' will be ' 'deactivated.' % (ad_unit['id'], ad_unit['name'], ad_unit['status'])) print 'Number of ad units to be deactivated: %s' % len(ad_units) # Perform action. result = inventory_service.PerformAdUnitAction({'type': 'DeactivateAdUnits'}, {'query': query})[0] # Display results. if result and int(result['numChanges']) > 0: print 'Number of ad units deactivated: %s' % result['numChanges'] else: print 'No ad units were deactivated.'
__author__ = '[email protected] (Stan Grinberg)' # Locate the client library. If module was installed via "setup.py" script, then # the following two lines are not needed. import os import sys sys.path.append(os.path.join('..', '..', '..', '..')) # Import appropriate classes from the client library. from adspygoogle.dfp import DfpUtils from adspygoogle.dfp.DfpClient import DfpClient # Initialize client object. client = DfpClient(path=os.path.join('..', '..', '..', '..')) # Initialize appropriate service. By default, the request is always made against # sandbox environment. creative_service = client.GetCreativeService('https://sandbox.google.com', 'v201101') # Get creatives by statement. creatives = DfpUtils.GetAllEntitiesByStatement(client, 'Creative') # Display results. for creative in creatives: print('Creative with id \'%s\', name \'%s\', and type \'%s\' was found.' % (creative['id'], creative['name'], creative['Creative_Type'])) print print 'Number of results found: %s' % len(creatives)
__author__ = '[email protected] (Stan Grinberg)' # Locate the client library. If module was installed via "setup.py" script, then # the following two lines are not needed. import os import sys sys.path.append(os.path.join('..', '..', '..', '..')) # Import appropriate classes from the client library. from adspygoogle.dfp import DfpUtils from adspygoogle.dfp.DfpClient import DfpClient # Initialize client object. client = DfpClient(path=os.path.join('..', '..', '..', '..')) # Initialize appropriate service. By default, the request is always made against # sandbox environment. company_service = client.GetCompanyService('https://sandbox.google.com', 'v201004') # Get companies by statement. companies = DfpUtils.GetAllEntitiesByStatement(client, 'Company') # Display results. for company in companies: print('Company with id \'%s\', name \'%s\', and type \'%s\' was found.' % (company['id'], company['name'], company['type'])) print print 'Number of results found: %s' % len(companies)