/// <summary> /// Run the code example. /// </summary> public void Run(DfpUser user) { // Get the PremiumRateService. PremiumRateService premiumRateService = (PremiumRateService)user.GetService(DfpService.v201602.PremiumRateService); long premiumRateId = long.Parse(_T("INSERT_PREMIUM_RATE_ID_HERE")); // Create a statement to get the premium rate. StatementBuilder statementBuilder = new StatementBuilder() .Where("id = :id") .OrderBy("id ASC") .Limit(1) .AddValue("id", premiumRateId); try { // Get premium rates by statement. PremiumRatePage page = premiumRateService.getPremiumRatesByStatement(statementBuilder.ToStatement()); PremiumRate premiumRate = page.results[0]; // Create a flat fee based premium rate value with a 10% increase. PremiumRateValue flatFeePremiumRateValue = new PremiumRateValue(); flatFeePremiumRateValue.premiumFeature = premiumRate.premiumFeature; flatFeePremiumRateValue.rateType = RateType.CPM; flatFeePremiumRateValue.adjustmentSize = 10000L; flatFeePremiumRateValue.adjustmentType = PremiumAdjustmentType.PERCENTAGE; // Update the premium rate's values to include a flat fee premium rate. List <PremiumRateValue> existingPremiumRateValues = (premiumRate.premiumRateValues != null) ? new List <PremiumRateValue>(premiumRate.premiumRateValues) : new List <PremiumRateValue>(); existingPremiumRateValues.Add(flatFeePremiumRateValue); premiumRate.premiumRateValues = existingPremiumRateValues.ToArray(); // Update the premium rates on the server. PremiumRate[] premiumRates = premiumRateService.updatePremiumRates(new PremiumRate[] { premiumRate }); if (premiumRates != null) { foreach (PremiumRate updatedPremiumRate in premiumRates) { Console.WriteLine("Premium rate with ID '{1}' associated with rate card ID '{2}' " + "was updated.", updatedPremiumRate.id, updatedPremiumRate.premiumFeature.GetType().Name, updatedPremiumRate.rateCardId); } } else { Console.WriteLine("No premium rates updated."); } } catch (Exception e) { Console.WriteLine("Failed to update premium rates. Exception says \"{0}\"", e.Message); } }
/// <summary> /// Run the code example. /// </summary> public void Run(DfpUser dfpUser, long rateCardId) { PremiumRateService premiumRateService = (PremiumRateService)dfpUser.GetService(DfpService.v201611.PremiumRateService); // Create a statement to select premium rates. int pageSize = StatementBuilder.SUGGESTED_PAGE_LIMIT; StatementBuilder statementBuilder = new StatementBuilder() .Where("rateCardId = :rateCardId") .OrderBy("id ASC") .Limit(pageSize) .AddValue("rateCardId", rateCardId); // Retrieve a small amount of premium rates at a time, paging through until all // premium rates have been retrieved. int totalResultSetSize = 0; do { PremiumRatePage page = premiumRateService.getPremiumRatesByStatement( statementBuilder.ToStatement()); // Print out some information for each premium rate. if (page.results != null) { totalResultSetSize = page.totalResultSetSize; int i = page.startIndex; foreach (PremiumRate premiumRate in page.results) { Console.WriteLine( "{0}) Premium rate with ID {1}, " + "premium feature \"{2}\", " + "and rate card ID {3} was found.", i++, premiumRate.id, premiumRate.GetType().Name, premiumRate.rateCardId ); } } statementBuilder.IncreaseOffsetBy(pageSize); } while (statementBuilder.GetOffset() < totalResultSetSize); Console.WriteLine("Number of results found: {0}", totalResultSetSize); }
/// <summary> /// Run the code example. /// </summary> /// <param name="user">The DFP user object running the code example.</param> public void Run(DfpUser user, long rateCardId) { PremiumRateService premiumRateService = (PremiumRateService)user.GetService(DfpService.v201608.PremiumRateService); // Create a statement to select premium rates. StatementBuilder statementBuilder = new StatementBuilder() .Where("rateCardId = :rateCardId") .OrderBy("id ASC") .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT) .AddValue("rateCardId", rateCardId); // Retrieve a small amount of premium rates at a time, paging through // until all premium rates have been retrieved. PremiumRatePage page = new PremiumRatePage(); try { do { page = premiumRateService.getPremiumRatesByStatement(statementBuilder.ToStatement()); if (page.results != null) { // Print out some information for each premium rate. int i = page.startIndex; foreach (PremiumRate premiumRate in page.results) { Console.WriteLine("{0}) Premium rate with ID \"{1}\", premium feature \"{2}\", " + "and rate card ID \"{3}\" was found.", i++, premiumRate.id, premiumRate.GetType().Name, premiumRate.rateCardId); } } statementBuilder.IncreaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT); } while (statementBuilder.GetOffset() < page.totalResultSetSize); Console.WriteLine("Number of results found: {0}", page.totalResultSetSize); } catch (Exception e) { Console.WriteLine("Failed to get premium rates. Exception says \"{0}\"", e.Message); } }
/// <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 PremiumRateService. PremiumRateService premiumRateService = (PremiumRateService)user.GetService(DfpService.v201411.PremiumRateService); // Set the ID of the rate card to get premium rates for. long rateCardId = long.Parse(_T("INSERT_RATE_CARD_ID_HERE")); // Create a statement to get all premium rates belonging to a specific rate card. StatementBuilder statementBuilder = new StatementBuilder() .Where("rateCardId = :rateCardId") .OrderBy("id ASC") .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT) .AddValue("rateCardId", rateCardId); // Set default for page. PremiumRatePage page = new PremiumRatePage(); try { do { // Get premium rates by statement. page = premiumRateService.getPremiumRatesByStatement(statementBuilder.ToStatement()); if (page.results != null && page.results.Length > 0) { int i = page.startIndex; foreach (PremiumRate premiumRate in page.results) { Console.WriteLine("{0}) Premium rate with ID '{1}' of type '{2}' assigned to rate " + "card with ID '{3}' was found.", i++, premiumRate.id, premiumRate.premiumFeature.PremiumFeatureType, premiumRate.rateCardId); } } statementBuilder.IncreaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT); } while (statementBuilder.GetOffset() < page.totalResultSetSize); Console.WriteLine("Number of results found: {0}", page.totalResultSetSize); } catch (Exception e) { Console.WriteLine("Failed to get premium rates by statement. Exception says \"{0}\"", e.Message); } }
/// <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 PremiumRateService. PremiumRateService premiumRateService = (PremiumRateService)user.GetService(DfpService.v201505.PremiumRateService); // Create a statement to get all premium rates. StatementBuilder statementBuilder = new StatementBuilder() .OrderBy("id ASC") .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT); // Sets default for page. PremiumRatePage page = new PremiumRatePage(); try { do { // Get premium rates by statement. page = premiumRateService.getPremiumRatesByStatement(statementBuilder.ToStatement()); if (page.results != null && page.results.Length > 0) { int i = page.startIndex; foreach (PremiumRate premiumRate in page.results) { Console.WriteLine("{0}) Premium rate with ID '{1}' of type '{2}' assigned to rate " + "card with ID '{3}' was found.", i++, premiumRate.id, premiumRate.premiumFeature.GetType().Name, premiumRate.rateCardId); } } statementBuilder.IncreaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT); } while (statementBuilder.GetOffset() < page.totalResultSetSize); Console.WriteLine("Number of results found: {0}", page.totalResultSetSize); } catch (Exception ex) { Console.WriteLine("Failed to get premium rates. Exception says \"{0}\"", ex.Message); } }