Esempio n. 1
0
    public User GetUserByEmail(DfpUser user, string email) {
      UserService userService = (UserService) user.GetService(DfpService.v201411.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;
      }
    }
 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;
 }
Esempio n. 3
0
 public virtual UpdateResult performAdRuleAction(AdRuleAction adRuleAction, Statement filterStatement) {
   object[] results = this.Invoke("performAdRuleAction", new object[] { adRuleAction, filterStatement });
   return ((UpdateResult) (results[0]));
 }
Esempio n. 4
0
    public AdUnit FindRootAdUnit(DfpUser user) {
      // Get InventoryService.
      InventoryService inventoryService =
          (InventoryService)user.GetService(DfpService.v201411.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];
    }
    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);
    }
    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);
    }
    public void TestStatementBuilderIncludesKeywordPrefix() {
      StatementBuilder statementBuilder = new StatementBuilder()
          .Where("WHEREWITHALL = 1");

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

      Assert.True(StatementsAreEqual(expectedStatement,
        statementBuilder.ToStatement()));
    }
    public void TestStatementBuilderBlankStatement() {
      StatementBuilder statementBuilder = new StatementBuilder();

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

      Assert.True(StatementsAreEqual(expectedStatement,
                                     statementBuilder.ToStatement()));
    }
Esempio n. 9
0
 public virtual CreativeSetPage getCreativeSetsByStatement(Statement statement) {
   object[] results = this.Invoke("getCreativeSetsByStatement", new object[] { statement });
   return ((CreativeSetPage) (results[0]));
 }
Esempio n. 10
0
 public virtual UpdateResult performProposalLineItemAction(ProposalLineItemAction proposalLineItemAction, Statement filterStatement) {
   object[] results = this.Invoke("performProposalLineItemAction", new object[] { proposalLineItemAction, filterStatement });
   return ((UpdateResult) (results[0]));
 }
Esempio n. 11
0
 public virtual ProposalLineItemPage getProposalLineItemsByStatement(Statement filterStatement) {
   object[] results = this.Invoke("getProposalLineItemsByStatement", new object[] { filterStatement });
   return ((ProposalLineItemPage) (results[0]));
 }
Esempio n. 12
0
 public virtual UpdateResult performLineItemCreativeAssociationAction(LineItemCreativeAssociationAction lineItemCreativeAssociationAction, Statement filterStatement) {
   object[] results = this.Invoke("performLineItemCreativeAssociationAction", new object[] { lineItemCreativeAssociationAction, filterStatement });
   return ((UpdateResult) (results[0]));
 }
Esempio n. 13
0
 public virtual LineItemCreativeAssociationPage getLineItemCreativeAssociationsByStatement(Statement filterStatement) {
   object[] results = this.Invoke("getLineItemCreativeAssociationsByStatement", new object[] { filterStatement });
   return ((LineItemCreativeAssociationPage) (results[0]));
 }
Esempio n. 14
0
 public virtual UpdateResult performSharedAdUnitAction(SharedAdUnitAction sharedAdUnitAction, Statement filterStatement) {
   object[] results = this.Invoke("performSharedAdUnitAction", new object[] { sharedAdUnitAction, filterStatement });
   return ((UpdateResult) (results[0]));
 }
Esempio n. 15
0
 public virtual SharedAdUnitPage getSharedAdUnitsByStatement(Statement filterStatement) {
   object[] results = this.Invoke("getSharedAdUnitsByStatement", new object[] { filterStatement });
   return ((SharedAdUnitPage) (results[0]));
 }
    public void TestCreateOrders() {
      Order order1 = new Order();
      order1.name = string.Format("Order #{0}", new TestUtils().GetTimeStamp());
      order1.advertiserId = advertiserId;
      order1.traffickerId = traffickerId;
      order1.currencyCode = "USD";

      Order order2 = new Order();
      order2.name = string.Format("Order #{0}", new TestUtils().GetTimeStamp());
      order2.advertiserId = advertiserId;
      order2.traffickerId = traffickerId;
      order2.currencyCode = "USD";

      Order[] newOrders = null;

      Assert.DoesNotThrow(delegate() {
        newOrders = orderService.createOrders(new Order[] {order1, order2});
      });

      Statement statement = new Statement();
      statement.query = string.Format("WHERE advertiserId = '{0}' LIMIT 500", advertiserId);

      OrderPage page = orderService.getOrdersByStatement(statement);
      Assert.NotNull(newOrders);
      Assert.AreEqual(newOrders.Length, 2);

      Assert.AreEqual(order1.name, newOrders[0].name);
      Assert.AreEqual(order1.advertiserId, newOrders[0].advertiserId);
      Assert.AreEqual(order1.traffickerId, newOrders[0].traffickerId);
      Assert.AreEqual(order1.currencyCode, newOrders[0].currencyCode);

      Assert.AreEqual(order2.name, newOrders[1].name);
      Assert.AreEqual(order2.advertiserId, newOrders[1].advertiserId);
      Assert.AreEqual(order2.traffickerId, newOrders[1].traffickerId);
      Assert.AreEqual(order2.currencyCode, newOrders[1].currencyCode);
    }
    public void TestGetCompaniesByStatement() {
      Statement statement = new Statement();
      statement.query = string.Format("WHERE id = {0} ORDER BY name LIMIT 1", testCompany1.id);
      CompanyPage page = null;

      Assert.DoesNotThrow(delegate() {
        page = companyService.getCompaniesByStatement(statement);
      });

      Assert.NotNull(page);
      Assert.NotNull(page.results);
      Assert.AreEqual(page.results.Length, 1);
      Assert.NotNull(page.results[0]);
      Assert.AreEqual(page.results[0].id, testCompany1.id);
      Assert.AreEqual(page.results[0].name, testCompany1.name);
    }
Esempio n. 18
0
 public virtual CompanyPage getCompaniesByStatement(Statement filterStatement) {
   object[] results = this.Invoke("getCompaniesByStatement", new object[] { filterStatement });
   return ((CompanyPage) (results[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()));
    }
Esempio n. 20
0
 public virtual CreativeWrapperPage getCreativeWrappersByStatement(Statement filterStatement) {
   object[] results = this.Invoke("getCreativeWrappersByStatement", new object[] { filterStatement });
   return ((CreativeWrapperPage) (results[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()));
    }
Esempio n. 22
0
 public virtual UpdateResult performCreativeWrapperAction(CreativeWrapperAction creativeWrapperAction, Statement filterStatement) {
   object[] results = this.Invoke("performCreativeWrapperAction", new object[] { creativeWrapperAction, filterStatement });
   return ((UpdateResult) (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);
    }
Esempio n. 24
0
 public virtual PlacementPage getPlacementsByStatement(Statement filterStatement) {
   object[] results = this.Invoke("getPlacementsByStatement", new object[] { filterStatement });
   return ((PlacementPage) (results[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);
    }
Esempio n. 26
0
 public virtual UpdateResult performPlacementAction(PlacementAction placementAction, Statement filterStatement) {
   object[] results = this.Invoke("performPlacementAction", new object[] { placementAction, filterStatement });
   return ((UpdateResult) (results[0]));
 }
 /// <summary>
 /// Gets the <see cref="Statement"/> representing the state of this
 /// statement builder.
 /// </summary>
 /// <returns>The statement.</returns>
 public Statement ToStatement() {
   Statement statement = new Statement();
   statement.query = BuildQuery();
   statement.values = valueEntries.ToArray();
   return statement;
 }
    public void TestPerformOrderAction() {
      Statement statement = new Statement();
      statement.query = string.Format("WHERE status IN ('{0}', '{1}')",
          OrderStatus.DRAFT, OrderStatus.PENDING_APPROVAL);

      ApproveOrders action = new ApproveOrders();

      UpdateResult result = null;

      Assert.DoesNotThrow(delegate() {
        result = orderService.performOrderAction(action, statement);
      });

      Assert.NotNull(result);
      Assert.GreaterOrEqual(result.numChanges, 0);
    }
    public void TestUpdateOrders() {
      Statement statement = new Statement();
      statement.query = String.Format("WHERE id = {0} LIMIT 1", orderId);
      Order order = orderService.getOrdersByStatement(statement).results[0];
      order.notes = "Spoke to advertiser. All is well.";

      Order[] newOrders = null;

      Assert.DoesNotThrow(delegate() {
        newOrders = orderService.updateOrders(new Order[] {order});
      });

      Assert.NotNull(newOrders);
      Assert.AreEqual(newOrders.Length, 1);

      Assert.AreEqual(order.id, newOrders[0].id);
      Assert.AreEqual(order.name, newOrders[0].name);
      Assert.AreEqual(order.notes, newOrders[0].notes);
      Assert.AreEqual(order.advertiserId, newOrders[0].advertiserId);
      Assert.AreEqual(order.traffickerId, newOrders[0].traffickerId);
      Assert.AreEqual(order.currencyCode, newOrders[0].currencyCode);
    } 
Esempio n. 30
0
 public virtual AdRulePage getAdRulesByStatement(Statement statement) {
   object[] results = this.Invoke("getAdRulesByStatement", new object[] { statement });
   return ((AdRulePage) (results[0]));
 }