use of com.google.api.ads.admanager.axis.v202205.Value in project googleads-java-lib by googleads.
the class PqlTest method testCreateValue_commaTextSet.
@Test
public void testCreateValue_commaTextSet() {
Set<String> textSet = new LinkedHashSet<String>();
textSet.add("value1");
textSet.add("comma \",\" separated");
Value value1 = ((SetValue) Pql.createValue(textSet)).getValues().get(0);
Value value2 = ((SetValue) Pql.createValue(textSet)).getValues().get(1);
assertEquals("value1", ((TextValue) value1).getValue());
assertEquals("comma \",\" separated", ((TextValue) value2).getValue());
}
use of com.google.api.ads.admanager.axis.v202205.Value in project googleads-java-lib by googleads.
the class PqlTest method testCreateValue_textSet.
@Test
public void testCreateValue_textSet() {
Set<String> textSet = new LinkedHashSet<String>();
textSet.add("value1");
Value value1 = ((SetValue) Pql.createValue(textSet)).getValues().get(0);
assertEquals("value1", ((TextValue) value1).getValue());
}
use of com.google.api.ads.admanager.axis.v202205.Value in project googleads-java-lib by googleads.
the class PqlTest method testCreateValue_dateSet.
@Test
public void testCreateValue_dateSet() {
Set<Date> numberSet = new LinkedHashSet<Date>();
numberSet.add(date1);
Value value1 = ((SetValue) Pql.createValue(numberSet)).getValues().get(0);
assertEquals("2012-12-02", DateTimes.toString(((DateValue) value1).getValue()));
}
use of com.google.api.ads.admanager.axis.v202205.Value in project googleads-java-lib by googleads.
the class Pql method getApiValue.
/**
* Gets the underlying value of the {@code Value} object that's comparable to what would be
* returned in any other API object (i.e. DateTimeValue will return an API DateTime, not a Joda
* DateTime).
*
* @param value the value to convert
* @return the native value of {@code Value} or {@code null} if the underlying value is null
* @throws IllegalArgumentException if value cannot be converted
*/
public static Object getApiValue(Value value) {
if (value instanceof BooleanValue) {
return ((BooleanValue) value).isValue();
} else if (value instanceof NumberValue) {
if (((NumberValue) value).getValue() == null) {
return null;
} else {
try {
return NumberFormat.getInstance().parse(((NumberValue) value).getValue());
} catch (ParseException e) {
throw new IllegalStateException("Received invalid number format from API: " + ((NumberValue) value).getValue());
}
}
} else if (value instanceof TextValue) {
return ((TextValue) value).getValue();
} else if (value instanceof DateTimeValue) {
return ((DateTimeValue) value).getValue();
} else if (value instanceof DateValue) {
return ((DateValue) value).getValue();
} else if (value instanceof TargetingValue) {
return ((TargetingValue) value).getValue();
} else if (value instanceof SetValue) {
List<Value> setValues = ((SetValue) value).getValues();
Set<Object> apiValue = new LinkedHashSet<Object>();
if (setValues != null) {
for (Value setValue : setValues) {
validateSetValueEntryForSet(getApiValue(setValue), apiValue);
apiValue.add(getApiValue(setValue));
}
}
return apiValue;
} else {
throw new IllegalArgumentException("Unsupported Value type [" + value.getClass() + "]");
}
}
use of com.google.api.ads.admanager.axis.v202205.Value in project googleads-java-lib by googleads.
the class UpdateLabels method main.
public static void main(String[] args) {
AdManagerSession session;
try {
// Generate a refreshable OAuth2 credential.
Credential oAuth2Credential = new OfflineCredentials.Builder().forApi(Api.AD_MANAGER).fromFile().build().generateCredential();
// Construct a AdManagerSession.
session = new AdManagerSession.Builder().fromFile().withOAuth2Credential(oAuth2Credential).build();
} catch (ConfigurationLoadException cle) {
System.err.printf("Failed to load configuration from the %s file. Exception: %s%n", DEFAULT_CONFIGURATION_FILENAME, cle);
return;
} catch (ValidationException ve) {
System.err.printf("Invalid configuration in the %s file. Exception: %s%n", DEFAULT_CONFIGURATION_FILENAME, ve);
return;
} catch (OAuthException oe) {
System.err.printf("Failed to create OAuth credentials. Check OAuth settings in the %s file. " + "Exception: %s%n", DEFAULT_CONFIGURATION_FILENAME, oe);
return;
}
AdManagerServices adManagerServices = new AdManagerServices();
UpdateLabelsParams params = new UpdateLabelsParams();
if (!params.parseArguments(args)) {
// Either pass the required parameters for this example on the command line, or insert them
// into the code here. See the parameter class definition above for descriptions.
params.labelId = Long.parseLong("INSERT_LABEL_ID_HERE");
}
try {
runExample(adManagerServices, session, params.labelId);
} catch (ApiException apiException) {
// ApiException is the base class for most exceptions thrown by an API request. Instances
// of this exception have a message and a collection of ApiErrors that indicate the
// type and underlying cause of the exception. Every exception object in the admanager.axis
// packages will return a meaningful value from toString
//
// ApiException extends RemoteException, so this catch block must appear before the
// catch block for RemoteException.
System.err.println("Request failed due to ApiException. Underlying ApiErrors:");
if (apiException.getErrors() != null) {
int i = 0;
for (ApiError apiError : apiException.getErrors()) {
System.err.printf(" Error %d: %s%n", i++, apiError);
}
}
} catch (RemoteException re) {
System.err.printf("Request failed unexpectedly due to RemoteException: %s%n", re);
}
}
Aggregations