コード例 #1
0
    /// <summary>
    /// Run the code example.
    /// </summary>
    /// <param name="user">The DFP user object running the code example.</param>
    public override void Run(DfpUser user) {
      // Get the SuggestedAdUnitService.
      SuggestedAdUnitService suggestedAdUnitService = (SuggestedAdUnitService) user.GetService(
          DfpService.v201408.SuggestedAdUnitService);

      // Set defaults for page and filterStatement.
      SuggestedAdUnitPage page = new SuggestedAdUnitPage();
      Statement filterStatement = new Statement();
      int offset = 0;

      try {
        do {
          // Create a statement to get all suggested ad units.
          filterStatement.query = "LIMIT 500 OFFSET " + offset;

          // Get suggested ad units by statement.
          page = suggestedAdUnitService.getSuggestedAdUnitsByStatement(filterStatement);

          if (page.results != null) {
            int i = page.startIndex;
            foreach (SuggestedAdUnit suggestedAdUnit in page.results) {
              Console.WriteLine("{0}) Suggested ad unit with ID \"{1}\", and number of requests " +
                  "\"{2}\" was found.", i, suggestedAdUnit.id, suggestedAdUnit.numRequests);
              i++;
            }
          }
          offset += 500;
        } while (offset < page.totalResultSetSize);

        Console.WriteLine("Number of results found: " + page.totalResultSetSize);
      } catch (Exception ex) {
        Console.WriteLine("Failed to get suggested ad units. Exception says \"{0}\"",
            ex.Message);
      }
    }
コード例 #2
0
        public void TestAllStatementBuilderPartialFunctions()
        {
            StatementBuilder statementBuilder = new StatementBuilder()
              .Select("Name, Id")
              .From("Geo_Target")
              .Where("Targetable = :targetable")
              .OrderBy("Id DESC")
              .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT)
              .Offset(0)
              .AddValue("targetable", true)
              .IncreaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT)
              .RemoveLimitAndOffset();
              Assert.AreEqual(null, statementBuilder.GetOffset());

              Statement expectedStatement = new Statement();
              expectedStatement.query = "SELECT Name, Id FROM Geo_Target"
              + " WHERE Targetable = :targetable ORDER BY Id DESC";
              String_ValueMapEntry targetableEntry = new String_ValueMapEntry();
              targetableEntry.key = "targetable";
              BooleanValue targetableValue = new BooleanValue();
              targetableValue.value = true;
              targetableEntry.value = targetableValue;
              expectedStatement.values = new String_ValueMapEntry[] {targetableEntry};
              Assert.True(StatementsAreEqual(expectedStatement, statementBuilder.ToStatement()));
        }
コード例 #3
0
        public void TestStatementBuilderBasicStatement()
        {
            StatementBuilder statementBuilder = new StatementBuilder()
              .Where("ID = 1");

              Statement expectedStatement = new Statement();
              expectedStatement.query = "WHERE ID = 1";
              expectedStatement.values = new String_ValueMapEntry[0];

              Assert.True(StatementsAreEqual(expectedStatement,
                                     statementBuilder.ToStatement()));
        }
コード例 #4
0
    public User GetUserByEmail(DfpUser user, string email) {
      UserService userService = (UserService) user.GetService(DfpService.v201408.UserService);

      // Create a Statement to get all users sorted by name.
      Statement statement = new Statement();
      statement.query = string.Format("where email = '{0}' LIMIT 1", email);

      UserPage page = userService.getUsersByStatement(statement);

      if (page.results != null && page.results.Length > 0) {
        return page.results[0];
      } else {
        return null;
      }
    }
コード例 #5
0
 private static bool StatementsAreEqual(Statement s1, Statement s2) {
   // Assumes both Statements are non-null and have non-null properties
   if (String.Compare(s1.query, s2.query, true) != 0) {
     return false;
   }
   if (s1.values.Length != s2.values.Length) {
     return false;
   }
   // Assumes Statement values are in the same order
   for (int i = 0; i < s1.values.Length; i++) {
     if (!StringValueMapEntriesAreEqual(s1.values[i], s2.values[i])) {
       return false;
     }
   }
   return true;
 }
コード例 #6
0
    /// <summary>
    /// Run the code example.
    /// </summary>
    /// <param name="user">The DFP user object running the code example.</param>
    public override void Run(DfpUser user) {
      // Get the PlacementService.
      PlacementService placementService =
          (PlacementService) user.GetService(DfpService.v201408.PlacementService);

      // Create a statement to select first 500 placements.
      Statement filterStatement = new Statement();
      filterStatement.query = "LIMIT 500";

      try {
        // Get placements by statement.
        PlacementPage page = placementService.getPlacementsByStatement(filterStatement);

        if (page.results != null) {
          Placement[] placements = page.results;

          // Update each local placement object by enabling AdSense targeting.
          foreach (Placement placement in placements) {
            placement.targetingDescription = (string.IsNullOrEmpty(placement.description))?
                "Generic description" : placement.description;
            placement.targetingAdLocation = "All images on sports pages.";
            placement.targetingSiteName = "http://code.google.com";
            placement.isAdSenseTargetingEnabled = true;
          }

          // Update the placements on the server.
          placements = placementService.updatePlacements(placements);

          // Display results.
          if (placements != null) {
            foreach (Placement placement in placements) {
              Console.WriteLine("A placement with ID \"{0}\", name \"{1}\", and AdSense targeting" +
                  " enabled \"{2}\" was updated.", placement.id, placement.name,
                  placement.isAdSenseTargetingEnabled);
            }
          } else {
            Console.WriteLine("No placements updated.");
          }
        }
      } catch (Exception ex) {
        Console.WriteLine("Failed to update placements. Exception says \"{0}\"",
            ex.Message);
      }
    }
コード例 #7
0
    /// <summary>
    /// Run the code example.
    /// </summary>
    /// <param name="dfpUser">The DFP user object running the code example.</param>
    public override void Run(DfpUser dfpUser) {
      // Get the UserTeamAssociationService.
      UserTeamAssociationService userTeamAssociationService = (UserTeamAssociationService)
          dfpUser.GetService(DfpService.v201408.UserTeamAssociationService);

      // Set defaults for page and filterStatement.
      UserTeamAssociationPage page = new UserTeamAssociationPage();
      Statement filterStatement = new Statement();
      int offset = 0;

      try {
        do {
          // Create a statement to get all user team associations.
          filterStatement.query = "LIMIT 500 OFFSET " + offset;

          // Get user team associations by statement.
          page = userTeamAssociationService.getUserTeamAssociationsByStatement(filterStatement);

          if (page.results != null) {
            int i = page.startIndex;
            foreach (UserTeamAssociation userTeamAssociation in page.results) {
              Console.WriteLine("{0}) User team association between user with ID \"{1}\" and " +
                  "team with ID \"{2}\" was found.", i, userTeamAssociation.userId,
                  userTeamAssociation.teamId);
              i++;
            }
          }

          offset += 500;
        } while (offset < page.totalResultSetSize);

        Console.WriteLine("Number of results found: {0}." + page.totalResultSetSize);
      } catch (Exception ex) {
        Console.WriteLine("Failed to get user team associations. Exception says \"{0}\"",
            ex.Message);
      }
    }
コード例 #8
0
    /// <summary>
    /// Run the code example.
    /// </summary>
    /// <param name="user">The DFP user object running the code example.</param>
    public override void Run(DfpUser user) {
      // Get the PlacementService.
      PlacementService placementService =
          (PlacementService) user.GetService(DfpService.v201408.PlacementService);

      // Sets defaults for page and Statement.
      PlacementPage page = new PlacementPage();
      Statement statement = new Statement();
      int offset = 0;

      try {
        do {
          // Create a Statement to get all ad units.
          statement.query = string.Format("LIMIT 500 OFFSET {0}", offset);

          // Get ad units by Statement.
          page = placementService.getPlacementsByStatement(statement);

          if (page.results != null && page.results.Length > 0) {
            int i = page.startIndex;
            foreach (Placement placement in page.results) {
              Console.WriteLine("{0}) Placement with ID = '{1}' and name = '{2}' was found.",
                  i, placement.id, placement.name);
              i++;
            }
          }

          offset += 500;
        } while (offset < page.totalResultSetSize);

        Console.WriteLine("Number of results found: {0}" + page.totalResultSetSize);
      } catch (Exception ex) {
        Console.WriteLine("Failed to get all placements. Exception says \"{0}\"",
            ex.Message);
      }
    }
コード例 #9
0
    /// <summary>
    /// Run the code example.
    /// </summary>
    /// <param name="user">The DFP user object running the code example.</param>
    public override void Run(DfpUser user) {
      // Create the CreativeWrapperService.
      CreativeWrapperService creativeWrapperService = (CreativeWrapperService) user.GetService(
          DfpService.v201408.CreativeWrapperService);

      // Set defaults for page and Statement.
      CreativeWrapperPage page = new CreativeWrapperPage();
      Statement statement = new Statement();
      int offset = 0;

      try {
        do {
          // Create a Statement to get all creative wrappers.
          statement.query = string.Format("LIMIT 500 OFFSET {0}", offset);

          // Get creative wrappers by Statement.
          page = creativeWrapperService.getCreativeWrappersByStatement(statement);

          if (page.results != null && page.results.Length > 0) {
            int i = page.startIndex;
            foreach (CreativeWrapper wrapper in page.results) {
              Console.WriteLine("Creative wrapper with ID \'{0}\' applying to label \'{1}\' with " +
                "status \'{2}\' was found.", wrapper.id, wrapper.labelId, wrapper.status);
              i++;
            }
          }

          offset += 500;
        } while (offset < page.totalResultSetSize);

        Console.WriteLine("Number of results found: {0}", page.totalResultSetSize);
      } catch (Exception ex) {
        Console.WriteLine("Failed to get active creative wrappers. Exception says \"{0}\"",
            ex.Message);
      }
    }
コード例 #10
0
    public void TestUpdateUsers() {
      Statement statement = new Statement();
      statement.query = String.Format("WHERE id = {0} LIMIT 1", salespersonId);
      User user = userService.getUsersByStatement(statement).results[0];
      user.preferredLocale = (user.preferredLocale == "fr_FR")? "en_US" : "fr_FR";

      User[] newUsers = null;

      Assert.DoesNotThrow(delegate() {
        newUsers = userService.updateUsers(new User[] {user});
      });

      Assert.NotNull(newUsers);
      Assert.AreEqual(newUsers.Length, 1);
      Assert.AreEqual(newUsers[0].id, user.id);
      Assert.AreEqual(newUsers[0].preferredLocale, user.preferredLocale);
    }
コード例 #11
0
 public virtual CreativeTemplatePage getCreativeTemplatesByStatement(Statement filterStatement) {
   object[] results = this.Invoke("getCreativeTemplatesByStatement", new object[] { filterStatement });
   return ((CreativeTemplatePage) (results[0]));
 }
コード例 #12
0
    public void TestGetUsersByStatement() {
      Statement statement = new Statement();
      statement.query = "ORDER BY name LIMIT 500";

      UserPage page = null;

      Assert.DoesNotThrow(delegate() {
        page = userService.getUsersByStatement(statement);
      });

      Assert.NotNull(page);
      Assert.NotNull(page.results);

      List<long> salesPersonIds = new List<long>();
      List<long> traffickerIds = new List<long>();

      foreach(User tempUser in page.results) {
        if (tempUser.roleName == "Salesperson") {
          salesPersonIds.Add(tempUser.id);
        } else if (tempUser.roleName == "Trafficker") {
          traffickerIds.Add(tempUser.id);
        }
      }
      Assert.Contains(salespersonId, salesPersonIds);
      Assert.Contains(traffickerId, traffickerIds);
    }
コード例 #13
0
    public void TestPerformUserAction() {
      Statement statement = new Statement();
      statement.query = string.Format("WHERE id = {0}", salespersonId);

      DeactivateUsers action = new DeactivateUsers();

      UpdateResult result = null;

      Assert.DoesNotThrow(delegate() {
        result = userService.performUserAction(action, statement);
      });

      Assert.NotNull(result);
      Assert.AreEqual(result.numChanges, 1);

      // Activate the user again.

      Assert.DoesNotThrow(delegate() {
        result = userService.performUserAction(new ActivateUsers(), statement);
      });

      Assert.NotNull(result);
      Assert.AreEqual(result.numChanges, 1);
    }
コード例 #14
0
    public AdUnit FindRootAdUnit(DfpUser user) {
      // Get InventoryService.
      InventoryService inventoryService =
          (InventoryService)user.GetService(DfpService.v201408.InventoryService);

      // Create a Statement to only select the root ad unit.
      Statement statement = new Statement();
      statement.query = "WHERE parentId IS NULL LIMIT 500";

      // Get ad units by Statement.
      AdUnitPage page = inventoryService.getAdUnitsByStatement(statement);
      return page.results[0];
    }
コード例 #15
0
 public virtual AdRulePage getAdRulesByStatement(Statement statement) {
   object[] results = this.Invoke("getAdRulesByStatement", new object[] { statement });
   return ((AdRulePage) (results[0]));
 }
        public void TestGetLineItemCreativeAssociationsByStatement()
        {
            Statement statement = new Statement();
              statement.query = string.Format("WHERE lineItemId = '{0}' LIMIT 500", lineItemId3);

              LineItemCreativeAssociationPage page = null;
              Assert.DoesNotThrow(delegate() {
            page = licaService.getLineItemCreativeAssociationsByStatement(statement);
              });
              Assert.NotNull(page);
              Assert.NotNull(page.results);
              Assert.AreEqual(page.totalResultSetSize, 1);

              Assert.NotNull(page.results[0]);
              Assert.AreEqual(page.results[0].creativeId, lica1.creativeId);
              Assert.AreEqual(page.results[0].lineItemId, lica1.lineItemId);
        }
コード例 #17
0
 public virtual UpdateResult performAdRuleAction(AdRuleAction adRuleAction, Statement filterStatement) {
   object[] results = this.Invoke("performAdRuleAction", new object[] { adRuleAction, filterStatement });
   return ((UpdateResult) (results[0]));
 }
コード例 #18
0
        public void TestPerformLineItemAction()
        {
            Statement statement = new Statement();
              statement.query = string.Format("WHERE orderId = '{0}' and status = '{1}'",
              orderId, ComputedStatus.NEEDS_CREATIVES);

              ActivateLineItems action = new ActivateLineItems();
              UpdateResult result = null;

              Assert.DoesNotThrow(delegate() {
            result = lineItemService.performLineItemAction(action, statement);
              });

              Assert.NotNull(result);
        }
コード例 #19
0
 public virtual LineItemPage getLineItemsByStatement(Statement filterStatement) {
   object[] results = this.Invoke("getLineItemsByStatement", new object[] { filterStatement });
   return ((LineItemPage) (results[0]));
 }
コード例 #20
0
        public void TestGetPlacementsByStatement()
        {
            // Create a Statement to only select active placements.
              Statement statement = new Statement();
              statement.query = string.Format("WHERE id = '{0}'", placement.id);

              PlacementPage page = null;

              Assert.DoesNotThrow(delegate() {
            page = placementService.getPlacementsByStatement(statement);
              });

              Assert.NotNull(page);
              Assert.NotNull(page.results);
              Assert.AreEqual(page.results.Length, 1);

              Assert.AreEqual(page.results[0].id, placement.id);
              Assert.AreEqual(page.results[0].name, placement.name);
              Assert.AreEqual(page.results[0].description, placement.description);
              Assert.Contains(adUnit1.id, page.results[0].targetedAdUnitIds);
              Assert.Contains(adUnit2.id, page.results[0].targetedAdUnitIds);
        }
コード例 #21
0
 public virtual ResultSet select(Statement selectStatement) {
   object[] results = this.Invoke("select", new object[] { selectStatement });
   return ((ResultSet) (results[0]));
 }
コード例 #22
0
 public virtual UpdateResult performLineItemAction(LineItemAction lineItemAction, Statement filterStatement) {
   object[] results = this.Invoke("performLineItemAction", new object[] { lineItemAction, filterStatement });
   return ((UpdateResult) (results[0]));
 }
コード例 #23
0
        public void TestPerformPlacementAction()
        {
            Statement statement = new Statement();
              statement.query = string.Format("WHERE status = '{0}'", InventoryStatus.ACTIVE);

              DeactivatePlacements action = new DeactivatePlacements();

              UpdateResult result = null;

              Assert.DoesNotThrow(delegate() {
            result = placementService.performPlacementAction(action, statement);
              });

              Assert.NotNull(result);
              Assert.GreaterOrEqual(result.numChanges, 0);
        }
コード例 #24
0
 public virtual ContentMetadataKeyHierarchyPage getContentMetadataKeyHierarchiesByStatement(Statement filterStatement) {
   object[] results = this.Invoke("getContentMetadataKeyHierarchiesByStatement", new object[] { filterStatement });
   return ((ContentMetadataKeyHierarchyPage) (results[0]));
 }
コード例 #25
0
        public void TestGetLineItemsByStatement()
        {
            Statement statement = new Statement();
              statement.query = string.Format("WHERE id = '{0}' LIMIT 1", lineItem1.id);

              LineItemPage page = null;

              Assert.DoesNotThrow(delegate() {
            page = lineItemService.getLineItemsByStatement(statement);
              });

              Assert.NotNull(page);
              Assert.AreEqual(page.totalResultSetSize, 1);
              Assert.NotNull(page.results);
              Assert.AreEqual(page.results[0].id, lineItem1.id);
              Assert.AreEqual(page.results[0].name, lineItem1.name);
              Assert.AreEqual(page.results[0].orderId, lineItem1.orderId);
        }
コード例 #26
0
 public virtual UpdateResult performContentMetadataKeyHierarchyAction(ContentMetadataKeyHierarchyAction contentMetadataKeyHierarchyAction, Statement filterStatement) {
   object[] results = this.Invoke("performContentMetadataKeyHierarchyAction", new object[] { contentMetadataKeyHierarchyAction, filterStatement });
   return ((UpdateResult) (results[0]));
 }
コード例 #27
0
    /// <summary>
    /// Run the code example.
    /// </summary>
    /// <param name="user">The DFP user object running the code example.</param>
    public override void Run(DfpUser user) {
      // Get the InventoryService.
      InventoryService inventoryService =
          (InventoryService) user.GetService(DfpService.v201408.InventoryService);

      // Get the PlacementService.
      PlacementService placementService =
          (PlacementService) user.GetService(DfpService.v201408.PlacementService);

      // Create local placement object to store skyscraper ad units.
      Placement skyscraperAdUnitPlacement = new Placement();
      skyscraperAdUnitPlacement.name = string.Format("Skyscraper AdUnit Placement #{0}",
          this.GetTimeStamp());
      skyscraperAdUnitPlacement.description = "Contains ad units that can hold creatives " +
          "of size 120x600";

      // Create local placement object to store medium square ad units.
      Placement mediumSquareAdUnitPlacement = new Placement();
      mediumSquareAdUnitPlacement.name = string.Format("Medium Square AdUnit Placement #{0}",
          this.GetTimeStamp());
      mediumSquareAdUnitPlacement.description = "Contains ad units that can hold creatives " +
          "of size 300x250";

      // Create local placement object to store banner ad units.
      Placement bannerAdUnitPlacement = new Placement();
      bannerAdUnitPlacement.name = string.Format("Banner AdUnit Placement #{0}",
          this.GetTimeStamp());
      bannerAdUnitPlacement.description = "Contains ad units that can hold creatives " +
          "of size 468x60";

      List<Placement> placementList = new List<Placement>();

      // Get the first 500 ad units.
      Statement statement = new Statement();
      statement.query = "LIMIT 500";

      List<string> mediumSquareTargetedUnitIds = new List<string>();
      List<string> skyscraperTargetedUnitIds = new List<string>();
      List<string> bannerTargetedUnitIds = new List<string>();

      try {
        AdUnitPage page = inventoryService.getAdUnitsByStatement(statement);

        // Separate the ad units by size.
        if (page.results != null) {
          foreach (AdUnit adUnit in page.results) {
            if (adUnit.parentId != null && adUnit.adUnitSizes != null) {
              foreach (AdUnitSize adUnitSize in adUnit.adUnitSizes) {
                Size size = adUnitSize.size;
                if (size.width == 300 && size.height == 250) {
                  if (!mediumSquareTargetedUnitIds.Contains(adUnit.id)) {
                    mediumSquareTargetedUnitIds.Add(adUnit.id);
                  }
                } else if (size.width == 120 && size.height == 600) {
                  if (!skyscraperTargetedUnitIds.Contains(adUnit.id)) {
                    skyscraperTargetedUnitIds.Add(adUnit.id);
                  }
                } else if (size.width == 468 && size.height == 60) {
                  if (!bannerTargetedUnitIds.Contains(adUnit.id)) {
                    bannerTargetedUnitIds.Add(adUnit.id);
                  }
                }
              }
            }
          }
        }
        mediumSquareAdUnitPlacement.targetedAdUnitIds = mediumSquareTargetedUnitIds.ToArray();
        skyscraperAdUnitPlacement.targetedAdUnitIds = skyscraperTargetedUnitIds.ToArray();
        bannerAdUnitPlacement.targetedAdUnitIds = bannerTargetedUnitIds.ToArray();


        // Only create placements with one or more ad unit.
        if (mediumSquareAdUnitPlacement.targetedAdUnitIds.Length != 0) {
          placementList.Add(mediumSquareAdUnitPlacement);
        }

        if (skyscraperAdUnitPlacement.targetedAdUnitIds.Length != 0) {
          placementList.Add(skyscraperAdUnitPlacement);
        }

        if (bannerAdUnitPlacement.targetedAdUnitIds.Length != 0) {
          placementList.Add(bannerAdUnitPlacement);
        }

        Placement[] placements =
          placementService.createPlacements(placementList.ToArray());

        // Display results.
        if (placements != null) {
          foreach (Placement placement in placements) {
            Console.Write("A placement with ID = '{0}', name ='{1}', and containing " +
                "ad units {{", placement.id, placement.name);

            foreach (string adUnitId in placement.targetedAdUnitIds) {
              Console.Write("{0}, ", adUnitId);
            }
            Console.WriteLine("} was created.");
          }
        } else {
          Console.WriteLine("No placements created.");
        }

      } catch (Exception ex) {
        Console.WriteLine("Failed to create placements. Exception says \"{0}\"",
            ex.Message);
      }
    }
コード例 #28
0
 public virtual CustomTargetingValuePage getCustomTargetingValuesByStatement(Statement filterStatement) {
   object[] results = this.Invoke("getCustomTargetingValuesByStatement", new object[] { filterStatement });
   return ((CustomTargetingValuePage) (results[0]));
 }
        public void TestPerformLineItemCreativeAssociationAction()
        {
            Statement statement = new Statement();
              statement.query = string.Format("WHERE lineItemId = '{0}' LIMIT 1", lineItemId3);

              DeactivateLineItemCreativeAssociations action = new DeactivateLineItemCreativeAssociations();

              UpdateResult result = null;
              Assert.DoesNotThrow(delegate() {
            result = licaService.performLineItemCreativeAssociationAction(action, statement);
              });

              Assert.NotNull(result);
              Assert.AreEqual(result.numChanges, 1);
        }
コード例 #30
0
 public virtual UpdateResult performCustomTargetingValueAction(CustomTargetingValueAction customTargetingValueAction, Statement filterStatement) {
   object[] results = this.Invoke("performCustomTargetingValueAction", new object[] { customTargetingValueAction, filterStatement });
   return ((UpdateResult) (results[0]));
 }