Search in sources :

Example 6 with Date

use of com.google.api.ads.admanager.axis.v202105.Date in project googleads-java-lib by googleads.

the class Pql method createValue.

/**
 * Creates a {@link Value} from the value i.e. a {@link TextValue} for a value of type {@code
 * String}, {@link BooleanValue} for type {@code Boolean}, {@link NumberValue} for type {@code
 * Double}, {@code Long}, or {@code Integer}, and {@link DateTimeValue} for type {@link DateTime}.
 * If the value is a {@code Value}, the value is returned. If the value is {@code null}, an empty
 * {@link TextValue} is returned.
 *
 * @param value the value to convert
 * @return the constructed value of the appropriate type
 * @throws IllegalArgumentException if value cannot be converted
 */
public static Value createValue(Object value) {
    if (value instanceof Value) {
        return (Value) value;
    } else if (value == null) {
        return new TextValue();
    } else {
        if (value instanceof Boolean) {
            BooleanValue booleanValue = new BooleanValue();
            booleanValue.setValue((Boolean) value);
            return booleanValue;
        } else if (value instanceof Double || value instanceof Long || value instanceof Integer) {
            NumberValue numberValue = new NumberValue();
            numberValue.setValue(value.toString());
            return numberValue;
        } else if (value instanceof String) {
            TextValue textValue = new TextValue();
            textValue.setValue((String) value);
            return textValue;
        } else if (value instanceof DateTime) {
            DateTimeValue dateTimeValue = new DateTimeValue();
            dateTimeValue.setValue((DateTime) value);
            return dateTimeValue;
        } else if (value instanceof Date) {
            DateValue dateValue = new DateValue();
            dateValue.setValue((Date) value);
            return dateValue;
        } else if (value instanceof Targeting) {
            TargetingValue targetingValue = new TargetingValue();
            targetingValue.setValue((Targeting) value);
            return targetingValue;
        } else if (value instanceof Set<?>) {
            SetValue setValue = new SetValue();
            Set<Value> values = new LinkedHashSet<Value>();
            for (Object entry : (Set<?>) value) {
                validateSetValueEntryForSet(createValue(entry), values);
                values.add(createValue(entry));
            }
            setValue.getValues().addAll(values);
            return setValue;
        } else {
            throw new IllegalArgumentException("Unsupported Value type [" + value.getClass() + "]");
        }
    }
}
Also used : Set(java.util.Set) ResultSet(com.google.api.ads.admanager.jaxws.v202108.ResultSet) LinkedHashSet(java.util.LinkedHashSet) DateTimeValue(com.google.api.ads.admanager.jaxws.v202108.DateTimeValue) Targeting(com.google.api.ads.admanager.jaxws.v202108.Targeting) DateTime(com.google.api.ads.admanager.jaxws.v202108.DateTime) Date(com.google.api.ads.admanager.jaxws.v202108.Date) NumberValue(com.google.api.ads.admanager.jaxws.v202108.NumberValue) TextValue(com.google.api.ads.admanager.jaxws.v202108.TextValue) DateValue(com.google.api.ads.admanager.jaxws.v202108.DateValue) BooleanValue(com.google.api.ads.admanager.jaxws.v202108.BooleanValue) DateTimeValue(com.google.api.ads.admanager.jaxws.v202108.DateTimeValue) NumberValue(com.google.api.ads.admanager.jaxws.v202108.NumberValue) TextValue(com.google.api.ads.admanager.jaxws.v202108.TextValue) SetValue(com.google.api.ads.admanager.jaxws.v202108.SetValue) BooleanValue(com.google.api.ads.admanager.jaxws.v202108.BooleanValue) DateValue(com.google.api.ads.admanager.jaxws.v202108.DateValue) TargetingValue(com.google.api.ads.admanager.jaxws.v202108.TargetingValue) Value(com.google.api.ads.admanager.jaxws.v202108.Value) TargetingValue(com.google.api.ads.admanager.jaxws.v202108.TargetingValue) SetValue(com.google.api.ads.admanager.jaxws.v202108.SetValue)

Example 7 with Date

use of com.google.api.ads.admanager.axis.v202105.Date in project googleads-java-lib by googleads.

the class Pql method createValue.

/**
 * Creates a {@link Value} from the value i.e. a {@link TextValue} for a value of type {@code
 * String}, {@link BooleanValue} for type {@code Boolean}, {@link NumberValue} for type {@code
 * Double}, {@code Long}, or {@code Integer}, {@link DateTimeValue} for type {@link DateTime}, and
 * {@link DateValue} for type {@link Date}. If the value is a {@code Value}, the value is
 * returned. If the value is {@code null}, an empty {@link TextValue} is returned.
 *
 * @param value the value to convert
 * @return the constructed value of the appropriate type
 * @throws IllegalArgumentException if value cannot be converted
 */
public static Value createValue(Object value) {
    if (value instanceof Value) {
        return (Value) value;
    } else if (value == null) {
        return new TextValue();
    } else {
        if (value instanceof Boolean) {
            BooleanValue booleanValue = new BooleanValue();
            booleanValue.setValue((Boolean) value);
            return booleanValue;
        } else if (value instanceof Double || value instanceof Long || value instanceof Integer) {
            NumberValue numberValue = new NumberValue();
            numberValue.setValue(value.toString());
            return numberValue;
        } else if (value instanceof String) {
            TextValue textValue = new TextValue();
            textValue.setValue((String) value);
            return textValue;
        } else if (value instanceof DateTime) {
            DateTimeValue dateTimeValue = new DateTimeValue();
            dateTimeValue.setValue((DateTime) value);
            return dateTimeValue;
        } else if (value instanceof Date) {
            DateValue dateValue = new DateValue();
            dateValue.setValue((Date) value);
            return dateValue;
        } else if (value instanceof Targeting) {
            TargetingValue targetingValue = new TargetingValue();
            targetingValue.setValue((Targeting) value);
            return targetingValue;
        } else if (value instanceof Set<?>) {
            SetValue setValue = new SetValue();
            Set<Value> values = new LinkedHashSet<Value>();
            for (Object entry : (Set<?>) value) {
                validateSetValueEntryForSet(createValue(entry), values);
                values.add(createValue(entry));
            }
            setValue.setValues(values.toArray(new Value[] {}));
            return setValue;
        } else {
            throw new IllegalArgumentException("Unsupported Value type [" + value.getClass() + "]");
        }
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ResultSet(com.google.api.ads.admanager.axis.v202105.ResultSet) Set(java.util.Set) DateTimeValue(com.google.api.ads.admanager.axis.v202105.DateTimeValue) Targeting(com.google.api.ads.admanager.axis.v202105.Targeting) DateTime(com.google.api.ads.admanager.axis.v202105.DateTime) Date(com.google.api.ads.admanager.axis.v202105.Date) NumberValue(com.google.api.ads.admanager.axis.v202105.NumberValue) TextValue(com.google.api.ads.admanager.axis.v202105.TextValue) DateValue(com.google.api.ads.admanager.axis.v202105.DateValue) BooleanValue(com.google.api.ads.admanager.axis.v202105.BooleanValue) TextValue(com.google.api.ads.admanager.axis.v202105.TextValue) BooleanValue(com.google.api.ads.admanager.axis.v202105.BooleanValue) DateTimeValue(com.google.api.ads.admanager.axis.v202105.DateTimeValue) Value(com.google.api.ads.admanager.axis.v202105.Value) DateValue(com.google.api.ads.admanager.axis.v202105.DateValue) TargetingValue(com.google.api.ads.admanager.axis.v202105.TargetingValue) NumberValue(com.google.api.ads.admanager.axis.v202105.NumberValue) SetValue(com.google.api.ads.admanager.axis.v202105.SetValue) TargetingValue(com.google.api.ads.admanager.axis.v202105.TargetingValue) SetValue(com.google.api.ads.admanager.axis.v202105.SetValue)

Example 8 with Date

use of com.google.api.ads.admanager.axis.v202105.Date in project googleads-java-lib by googleads.

the class Pql method createValue.

/**
 * Creates a {@link Value} from the value i.e. a {@link TextValue} for a value of type {@code
 * String}, {@link BooleanValue} for type {@code Boolean}, {@link NumberValue} for type {@code
 * Double}, {@code Long}, or {@code Integer}, {@link DateTimeValue} for type {@link DateTime}, and
 * {@link DateValue} for type {@link Date}. If the value is a {@code Value}, the value is
 * returned. If the value is {@code null}, an empty {@link TextValue} is returned.
 *
 * @param value the value to convert
 * @return the constructed value of the appropriate type
 * @throws IllegalArgumentException if value cannot be converted
 */
public static Value createValue(Object value) {
    if (value instanceof Value) {
        return (Value) value;
    } else if (value == null) {
        return new TextValue();
    } else {
        if (value instanceof Boolean) {
            BooleanValue booleanValue = new BooleanValue();
            booleanValue.setValue((Boolean) value);
            return booleanValue;
        } else if (value instanceof Double || value instanceof Long || value instanceof Integer) {
            NumberValue numberValue = new NumberValue();
            numberValue.setValue(value.toString());
            return numberValue;
        } else if (value instanceof String) {
            TextValue textValue = new TextValue();
            textValue.setValue((String) value);
            return textValue;
        } else if (value instanceof DateTime) {
            DateTimeValue dateTimeValue = new DateTimeValue();
            dateTimeValue.setValue((DateTime) value);
            return dateTimeValue;
        } else if (value instanceof Date) {
            DateValue dateValue = new DateValue();
            dateValue.setValue((Date) value);
            return dateValue;
        } else if (value instanceof Targeting) {
            TargetingValue targetingValue = new TargetingValue();
            targetingValue.setValue((Targeting) value);
            return targetingValue;
        } else if (value instanceof Set<?>) {
            SetValue setValue = new SetValue();
            Set<Value> values = new LinkedHashSet<Value>();
            for (Object entry : (Set<?>) value) {
                validateSetValueEntryForSet(createValue(entry), values);
                values.add(createValue(entry));
            }
            setValue.setValues(values.toArray(new Value[] {}));
            return setValue;
        } else {
            throw new IllegalArgumentException("Unsupported Value type [" + value.getClass() + "]");
        }
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ResultSet(com.google.api.ads.admanager.axis.v202111.ResultSet) Set(java.util.Set) DateTimeValue(com.google.api.ads.admanager.axis.v202111.DateTimeValue) Targeting(com.google.api.ads.admanager.axis.v202111.Targeting) DateTime(com.google.api.ads.admanager.axis.v202111.DateTime) Date(com.google.api.ads.admanager.axis.v202111.Date) NumberValue(com.google.api.ads.admanager.axis.v202111.NumberValue) TextValue(com.google.api.ads.admanager.axis.v202111.TextValue) DateValue(com.google.api.ads.admanager.axis.v202111.DateValue) BooleanValue(com.google.api.ads.admanager.axis.v202111.BooleanValue) DateTimeValue(com.google.api.ads.admanager.axis.v202111.DateTimeValue) TextValue(com.google.api.ads.admanager.axis.v202111.TextValue) Value(com.google.api.ads.admanager.axis.v202111.Value) NumberValue(com.google.api.ads.admanager.axis.v202111.NumberValue) TargetingValue(com.google.api.ads.admanager.axis.v202111.TargetingValue) BooleanValue(com.google.api.ads.admanager.axis.v202111.BooleanValue) DateValue(com.google.api.ads.admanager.axis.v202111.DateValue) SetValue(com.google.api.ads.admanager.axis.v202111.SetValue) TargetingValue(com.google.api.ads.admanager.axis.v202111.TargetingValue) SetValue(com.google.api.ads.admanager.axis.v202111.SetValue)

Example 9 with Date

use of com.google.api.ads.admanager.axis.v202105.Date in project googleads-java-lib by googleads.

the class CreateForecastAdjustments method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @param trafficForecastSegmentId the ID of the traffic forecast segment to create the adjustment
 *  for.
 * @throws ApiException if the API request failed with one or more service errors.
 * @throws RemoteException if the API request failed due to other errors.
 */
public static void runExample(AdManagerServices adManagerServices, AdManagerSession session, long trafficForecastSegmentId) throws RemoteException {
    // Get the adjustment service.
    AdjustmentServiceInterface adjustmentService = adManagerServices.get(session, AdjustmentServiceInterface.class);
    ForecastAdjustment forecastAdjustment = new ForecastAdjustment();
    forecastAdjustment.setName("Forecast adjustment #" + new Random().nextInt(Integer.MAX_VALUE));
    forecastAdjustment.setTrafficForecastSegmentId(trafficForecastSegmentId);
    // Set the date range that this adjustment will be applied to.
    Date startDate = new Date(org.joda.time.DateTime.now().plusYears(1).getYear(), 1, 1);
    Date endDate = new Date(org.joda.time.DateTime.now().plusYears(1).getYear(), 1, 1);
    DateRange dateRange = new DateRange();
    dateRange.setStartDate(startDate);
    dateRange.setEndDate(endDate);
    forecastAdjustment.setDateRange(dateRange);
    // Set the adjustment type to be a historical basis.
    forecastAdjustment.setVolumeType(ForecastAdjustmentVolumeType.HISTORICAL_BASIS_VOLUME);
    HistoricalBasisVolumeSettings settings = new HistoricalBasisVolumeSettings();
    settings.setUseParentTrafficForecastSegmentTargeting(true);
    Date historicalStartDate = new Date(org.joda.time.DateTime.now().getYear(), 1, 1);
    Date historicalEndDate = new Date(org.joda.time.DateTime.now().getYear(), 1, 1);
    DateRange historicalDateRange = new DateRange();
    historicalDateRange.setStartDate(historicalStartDate);
    historicalDateRange.setEndDate(historicalEndDate);
    settings.setHistoricalDateRange(historicalDateRange);
    settings.setMultiplierMilliPercent(110000L);
    forecastAdjustment.setHistoricalBasisVolumeSettings(settings);
    forecastAdjustment.setStatus(ForecastAdjustmentStatus.ACTIVE);
    // Update the forecast adjustment on the server.
    ForecastAdjustment[] forecastAdjustments = adjustmentService.createForecastAdjustments(new ForecastAdjustment[] { forecastAdjustment });
    for (ForecastAdjustment createdForecastAdjustment : forecastAdjustments) {
        System.out.printf("Forecast adjustment with ID %d and name '%s' was created.%n", createdForecastAdjustment.getId(), createdForecastAdjustment.getName());
    }
}
Also used : DateRange(com.google.api.ads.admanager.axis.v202108.DateRange) Random(java.util.Random) HistoricalBasisVolumeSettings(com.google.api.ads.admanager.axis.v202108.HistoricalBasisVolumeSettings) AdjustmentServiceInterface(com.google.api.ads.admanager.axis.v202108.AdjustmentServiceInterface) ForecastAdjustment(com.google.api.ads.admanager.axis.v202108.ForecastAdjustment) Date(com.google.api.ads.admanager.axis.v202108.Date)

Example 10 with Date

use of com.google.api.ads.admanager.axis.v202105.Date in project googleads-java-lib by googleads.

the class GetTrafficData method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @param advertiserId the ID of the advertiser (company) to forecast for. Setting an advertiser
 *     will cause the forecast to apply the appropriate unified blocking rules.
 * @throws ApiException if the API request failed with one or more service errors.
 * @throws RemoteException if the API request failed due to other errors.
 */
public static void runExample(AdManagerServices adManagerServices, AdManagerSession session) throws RemoteException {
    // Get the ForecastService.
    ForecastServiceInterface forecastService = adManagerServices.get(session, ForecastServiceInterface.class);
    // Get the NetworkService.
    NetworkServiceInterface networkService = adManagerServices.get(session, NetworkServiceInterface.class);
    // Get the root ad unit ID used to target the whole site.
    String rootAdUnitId = networkService.getCurrentNetwork().getEffectiveRootAdUnitId();
    // Create inventory targeting.
    InventoryTargeting inventoryTargeting = new InventoryTargeting();
    // Create ad unit targeting for the root ad unit.
    AdUnitTargeting adUnitTargeting = new AdUnitTargeting();
    adUnitTargeting.setAdUnitId(rootAdUnitId);
    adUnitTargeting.setIncludeDescendants(true);
    inventoryTargeting.setTargetedAdUnits(new AdUnitTargeting[] { adUnitTargeting });
    // Create targeting.
    Targeting targeting = new Targeting();
    targeting.setInventoryTargeting(inventoryTargeting);
    // Create the date range. Include the previous and next 7 days.
    Interval interval = new Interval(Instant.now().plus(Duration.standardDays(-7)), Instant.now().plus(Duration.standardDays(7)));
    DateRange dateRange = new DateRange();
    dateRange.setStartDate(DateTimes.toDateTime(interval.getStart()).getDate());
    dateRange.setEndDate(DateTimes.toDateTime(interval.getEnd()).getDate());
    // Request the traffic data.
    TrafficDataRequest trafficDataRequest = new TrafficDataRequest();
    trafficDataRequest.setRequestedDateRange(dateRange);
    trafficDataRequest.setTargeting(targeting);
    TrafficDataResponse trafficData = forecastService.getTrafficData(trafficDataRequest);
    // Read the historical traffic data.
    TimeSeries historicalTimeSeries = trafficData.getHistoricalTimeSeries();
    if (historicalTimeSeries != null) {
        Date historicalStartDate = historicalTimeSeries.getTimeSeriesDateRange().getStartDate();
        DateTime historicalStart = new DateTime(historicalStartDate.getYear(), historicalStartDate.getMonth(), historicalStartDate.getDay(), 0, 0, 0);
        for (int i = 0; i < historicalTimeSeries.getValues().length; i++) {
            System.out.printf("%s: %d historical ad opportunities%n", historicalStart.plus(Duration.standardDays(i)).toString(DateTimeFormat.longDate()), historicalTimeSeries.getValues()[i]);
        }
    }
    // Read the forecasted traffic data.
    TimeSeries forecastedTimeSeries = trafficData.getForecastedTimeSeries();
    if (forecastedTimeSeries != null) {
        Date forecastedStartDate = forecastedTimeSeries.getTimeSeriesDateRange().getStartDate();
        DateTime forecastedStart = new DateTime(forecastedStartDate.getYear(), forecastedStartDate.getMonth(), forecastedStartDate.getDay(), 0, 0, 0);
        for (int i = 0; i < forecastedTimeSeries.getValues().length; i++) {
            System.out.printf("%s: %d forecasted ad opportunities%n", forecastedStart.plus(Duration.standardDays(i)).toString(DateTimeFormat.longDate()), forecastedTimeSeries.getValues()[i]);
        }
    }
}
Also used : TrafficDataResponse(com.google.api.ads.admanager.axis.v202202.TrafficDataResponse) NetworkServiceInterface(com.google.api.ads.admanager.axis.v202202.NetworkServiceInterface) TimeSeries(com.google.api.ads.admanager.axis.v202202.TimeSeries) AdUnitTargeting(com.google.api.ads.admanager.axis.v202202.AdUnitTargeting) InventoryTargeting(com.google.api.ads.admanager.axis.v202202.InventoryTargeting) Targeting(com.google.api.ads.admanager.axis.v202202.Targeting) InventoryTargeting(com.google.api.ads.admanager.axis.v202202.InventoryTargeting) Date(com.google.api.ads.admanager.axis.v202202.Date) DateTime(org.joda.time.DateTime) ForecastServiceInterface(com.google.api.ads.admanager.axis.v202202.ForecastServiceInterface) DateRange(com.google.api.ads.admanager.axis.v202202.DateRange) AdUnitTargeting(com.google.api.ads.admanager.axis.v202202.AdUnitTargeting) TrafficDataRequest(com.google.api.ads.admanager.axis.v202202.TrafficDataRequest) Interval(org.joda.time.Interval)

Aggregations

LinkedHashSet (java.util.LinkedHashSet)16 Set (java.util.Set)8 Before (org.junit.Before)8 Test (org.junit.Test)8 Date (edu.princeton.cs.algs4.Date)7 Date (com.google.api.ads.admanager.axis.v202108.Date)5 Date (com.google.api.ads.admanager.axis.v202111.Date)5 Date (com.google.api.ads.admanager.axis.v202202.Date)5 BooleanValue (com.google.api.ads.admanager.axis.v202105.BooleanValue)3 Date (com.google.api.ads.admanager.axis.v202105.Date)3 DateTimeValue (com.google.api.ads.admanager.axis.v202105.DateTimeValue)3 DateValue (com.google.api.ads.admanager.axis.v202105.DateValue)3 BooleanValue (com.google.api.ads.admanager.axis.v202108.BooleanValue)3 DateTimeValue (com.google.api.ads.admanager.axis.v202108.DateTimeValue)3 DateValue (com.google.api.ads.admanager.axis.v202108.DateValue)3 NumberValue (com.google.api.ads.admanager.axis.v202108.NumberValue)3 SetValue (com.google.api.ads.admanager.axis.v202108.SetValue)3 TargetingValue (com.google.api.ads.admanager.axis.v202108.TargetingValue)3 TextValue (com.google.api.ads.admanager.axis.v202108.TextValue)3 NumberValue (com.google.api.ads.admanager.axis.v202105.NumberValue)2