com.facebook.ads.sdk.CustomConversion.java Source code

Java tutorial

Introduction

Here is the source code for com.facebook.ads.sdk.CustomConversion.java

Source

/**
 * Copyright (c) 2015-present, Facebook, Inc. All rights reserved.
 *
 * You are hereby granted a non-exclusive, worldwide, royalty-free license to
 * use, copy, modify, and distribute this software in source code or binary
 * form for use in connection with the web services and APIs provided by
 * Facebook.
 *
 * As with any software that integrates with the Facebook platform, your use
 * of this software is subject to the Facebook Developer Principles and
 * Policies [http://developers.facebook.com/policy/]. This copyright notice
 * shall be included in all copies or substantial portions of the software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 *
 */

package com.facebook.ads.sdk;

import java.lang.reflect.Modifier;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
import com.facebook.ads.sdk.APIException.MalformedResponseException;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.annotations.SerializedName;

/**
 * This class is auto-genereated.
 *
 * For any issues or feature requests related to this class, please let us know
 * on github and we'll fix in our codegen framework. We'll not be able to accept
 * pull request for this class.
 *
 */
public class CustomConversion extends APINode {
    @SerializedName("account_id")
    private String mAccountId = null;
    @SerializedName("creation_time")
    private String mCreationTime = null;
    @SerializedName("custom_event_type")
    private EnumCustomEventType mCustomEventType = null;
    @SerializedName("default_conversion_value")
    private Long mDefaultConversionValue = null;
    @SerializedName("description")
    private String mDescription = null;
    @SerializedName("first_fired_time")
    private String mFirstFiredTime = null;
    @SerializedName("id")
    private String mId = null;
    @SerializedName("is_archived")
    private Boolean mIsArchived = null;
    @SerializedName("last_fired_time")
    private String mLastFiredTime = null;
    @SerializedName("name")
    private String mName = null;
    @SerializedName("pixel")
    private AdsPixel mPixel = null;
    @SerializedName("pixel_aggregation_rule")
    private String mPixelAggregationRule = null;
    @SerializedName("pixel_rule")
    private String mPixelRule = null;
    @SerializedName("retention_days")
    private Long mRetentionDays = null;
    protected static Gson gson = null;

    CustomConversion() {
    }

    public CustomConversion(Long id, APIContext context) {
        this(id.toString(), context);
    }

    public CustomConversion(String id, APIContext context) {
        this.mId = id;
        this.context = context;
    }

    public CustomConversion fetch() throws APIException {
        CustomConversion newInstance = fetchById(this.getPrefixedId().toString(), this.context);
        this.copyFrom(newInstance);
        return this;
    }

    public static CustomConversion fetchById(Long id, APIContext context) throws APIException {
        return fetchById(id.toString(), context);
    }

    public static CustomConversion fetchById(String id, APIContext context) throws APIException {
        CustomConversion customConversion = new APIRequestGet(id, context).requestAllFields().execute();
        return customConversion;
    }

    public static APINodeList<CustomConversion> fetchByIds(List<String> ids, List<String> fields,
            APIContext context) throws APIException {
        return (APINodeList<CustomConversion>) (new APIRequest<CustomConversion>(context, "", "/", "GET",
                CustomConversion.getParser()).setParam("ids", StringUtils.join(ids, ",")).requestFields(fields)
                        .execute());
    }

    private String getPrefixedId() {
        return getId();
    }

    public String getId() {
        return getFieldId().toString();
    }

    public static CustomConversion loadJSON(String json, APIContext context) {
        CustomConversion customConversion = getGson().fromJson(json, CustomConversion.class);
        if (context.isDebug()) {
            JsonParser parser = new JsonParser();
            JsonElement o1 = parser.parse(json);
            JsonElement o2 = parser.parse(customConversion.toString());
            if (o1.getAsJsonObject().get("__fb_trace_id__") != null) {
                o2.getAsJsonObject().add("__fb_trace_id__", o1.getAsJsonObject().get("__fb_trace_id__"));
            }
            if (!o1.equals(o2)) {
                context.log("[Warning] When parsing response, object is not consistent with JSON:");
                context.log("[JSON]" + o1);
                context.log("[Object]" + o2);
            }
            ;
        }
        customConversion.context = context;
        customConversion.rawValue = json;
        return customConversion;
    }

    public static APINodeList<CustomConversion> parseResponse(String json, APIContext context, APIRequest request)
            throws MalformedResponseException {
        APINodeList<CustomConversion> customConversions = new APINodeList<CustomConversion>(request, json);
        JsonArray arr;
        JsonObject obj;
        JsonParser parser = new JsonParser();
        Exception exception = null;
        try {
            JsonElement result = parser.parse(json);
            if (result.isJsonArray()) {
                // First, check if it's a pure JSON Array
                arr = result.getAsJsonArray();
                for (int i = 0; i < arr.size(); i++) {
                    customConversions.add(loadJSON(arr.get(i).getAsJsonObject().toString(), context));
                }
                ;
                return customConversions;
            } else if (result.isJsonObject()) {
                obj = result.getAsJsonObject();
                if (obj.has("data")) {
                    if (obj.has("paging")) {
                        JsonObject paging = obj.get("paging").getAsJsonObject().get("cursors").getAsJsonObject();
                        String before = paging.has("before") ? paging.get("before").getAsString() : null;
                        String after = paging.has("after") ? paging.get("after").getAsString() : null;
                        customConversions.setPaging(before, after);
                    }
                    if (obj.get("data").isJsonArray()) {
                        // Second, check if it's a JSON array with "data"
                        arr = obj.get("data").getAsJsonArray();
                        for (int i = 0; i < arr.size(); i++) {
                            customConversions.add(loadJSON(arr.get(i).getAsJsonObject().toString(), context));
                        }
                        ;
                    } else if (obj.get("data").isJsonObject()) {
                        // Third, check if it's a JSON object with "data"
                        obj = obj.get("data").getAsJsonObject();
                        boolean isRedownload = false;
                        for (String s : new String[] { "campaigns", "adsets", "ads" }) {
                            if (obj.has(s)) {
                                isRedownload = true;
                                obj = obj.getAsJsonObject(s);
                                for (Map.Entry<String, JsonElement> entry : obj.entrySet()) {
                                    customConversions.add(loadJSON(entry.getValue().toString(), context));
                                }
                                break;
                            }
                        }
                        if (!isRedownload) {
                            customConversions.add(loadJSON(obj.toString(), context));
                        }
                    }
                    return customConversions;
                } else if (obj.has("images")) {
                    // Fourth, check if it's a map of image objects
                    obj = obj.get("images").getAsJsonObject();
                    for (Map.Entry<String, JsonElement> entry : obj.entrySet()) {
                        customConversions.add(loadJSON(entry.getValue().toString(), context));
                    }
                    return customConversions;
                } else {
                    // Fifth, check if it's an array of objects indexed by id
                    boolean isIdIndexedArray = true;
                    for (Map.Entry entry : obj.entrySet()) {
                        String key = (String) entry.getKey();
                        if (key.equals("__fb_trace_id__")) {
                            continue;
                        }
                        JsonElement value = (JsonElement) entry.getValue();
                        if (value != null && value.isJsonObject() && value.getAsJsonObject().has("id")
                                && value.getAsJsonObject().get("id") != null
                                && value.getAsJsonObject().get("id").getAsString().equals(key)) {
                            customConversions.add(loadJSON(value.toString(), context));
                        } else {
                            isIdIndexedArray = false;
                            break;
                        }
                    }
                    if (isIdIndexedArray) {
                        return customConversions;
                    }

                    // Sixth, check if it's pure JsonObject
                    customConversions.clear();
                    customConversions.add(loadJSON(json, context));
                    return customConversions;
                }
            }
        } catch (Exception e) {
            exception = e;
        }
        throw new MalformedResponseException("Invalid response string: " + json, exception);
    }

    @Override
    public APIContext getContext() {
        return context;
    }

    @Override
    public void setContext(APIContext context) {
        this.context = context;
    }

    @Override
    public String toString() {
        return getGson().toJson(this);
    }

    public APIRequestGetActivities getActivities() {
        return new APIRequestGetActivities(this.getPrefixedId().toString(), context);
    }

    public APIRequestGetStats getStats() {
        return new APIRequestGetStats(this.getPrefixedId().toString(), context);
    }

    public APIRequestDelete delete() {
        return new APIRequestDelete(this.getPrefixedId().toString(), context);
    }

    public APIRequestGet get() {
        return new APIRequestGet(this.getPrefixedId().toString(), context);
    }

    public APIRequestUpdate update() {
        return new APIRequestUpdate(this.getPrefixedId().toString(), context);
    }

    public String getFieldAccountId() {
        return mAccountId;
    }

    public String getFieldCreationTime() {
        return mCreationTime;
    }

    public EnumCustomEventType getFieldCustomEventType() {
        return mCustomEventType;
    }

    public Long getFieldDefaultConversionValue() {
        return mDefaultConversionValue;
    }

    public String getFieldDescription() {
        return mDescription;
    }

    public String getFieldFirstFiredTime() {
        return mFirstFiredTime;
    }

    public String getFieldId() {
        return mId;
    }

    public Boolean getFieldIsArchived() {
        return mIsArchived;
    }

    public String getFieldLastFiredTime() {
        return mLastFiredTime;
    }

    public String getFieldName() {
        return mName;
    }

    public AdsPixel getFieldPixel() {
        if (mPixel != null) {
            mPixel.context = getContext();
        }
        return mPixel;
    }

    public String getFieldPixelAggregationRule() {
        return mPixelAggregationRule;
    }

    public String getFieldPixelRule() {
        return mPixelRule;
    }

    public Long getFieldRetentionDays() {
        return mRetentionDays;
    }

    public static class APIRequestGetActivities extends APIRequest<APINode> {

        APINodeList<APINode> lastResponse = null;

        @Override
        public APINodeList<APINode> getLastResponse() {
            return lastResponse;
        }

        public static final String[] PARAMS = { "end_time", "event_type", "start_time", };

        public static final String[] FIELDS = {};

        @Override
        public APINodeList<APINode> parseResponse(String response) throws APIException {
            return APINode.parseResponse(response, getContext(), this);
        }

        @Override
        public APINodeList<APINode> execute() throws APIException {
            return execute(new HashMap<String, Object>());
        }

        @Override
        public APINodeList<APINode> execute(Map<String, Object> extraParams) throws APIException {
            lastResponse = parseResponse(executeInternal(extraParams));
            return lastResponse;
        }

        public APIRequestGetActivities(String nodeId, APIContext context) {
            super(context, nodeId, "/activities", "GET", Arrays.asList(PARAMS));
        }

        @Override
        public APIRequestGetActivities setParam(String param, Object value) {
            setParamInternal(param, value);
            return this;
        }

        @Override
        public APIRequestGetActivities setParams(Map<String, Object> params) {
            setParamsInternal(params);
            return this;
        }

        public APIRequestGetActivities setEndTime(String endTime) {
            this.setParam("end_time", endTime);
            return this;
        }

        public APIRequestGetActivities setEventType(EnumEventType eventType) {
            this.setParam("event_type", eventType);
            return this;
        }

        public APIRequestGetActivities setEventType(String eventType) {
            this.setParam("event_type", eventType);
            return this;
        }

        public APIRequestGetActivities setStartTime(String startTime) {
            this.setParam("start_time", startTime);
            return this;
        }

        public APIRequestGetActivities requestAllFields() {
            return this.requestAllFields(true);
        }

        public APIRequestGetActivities requestAllFields(boolean value) {
            for (String field : FIELDS) {
                this.requestField(field, value);
            }
            return this;
        }

        @Override
        public APIRequestGetActivities requestFields(List<String> fields) {
            return this.requestFields(fields, true);
        }

        @Override
        public APIRequestGetActivities requestFields(List<String> fields, boolean value) {
            for (String field : fields) {
                this.requestField(field, value);
            }
            return this;
        }

        @Override
        public APIRequestGetActivities requestField(String field) {
            this.requestField(field, true);
            return this;
        }

        @Override
        public APIRequestGetActivities requestField(String field, boolean value) {
            this.requestFieldInternal(field, value);
            return this;
        }

    }

    public static class APIRequestGetStats extends APIRequest<AdsPixelStatsResult> {

        APINodeList<AdsPixelStatsResult> lastResponse = null;

        @Override
        public APINodeList<AdsPixelStatsResult> getLastResponse() {
            return lastResponse;
        }

        public static final String[] PARAMS = { "aggregation", "end_time", "start_time", };

        public static final String[] FIELDS = { "aggregation", "data", "timestamp", };

        @Override
        public APINodeList<AdsPixelStatsResult> parseResponse(String response) throws APIException {
            return AdsPixelStatsResult.parseResponse(response, getContext(), this);
        }

        @Override
        public APINodeList<AdsPixelStatsResult> execute() throws APIException {
            return execute(new HashMap<String, Object>());
        }

        @Override
        public APINodeList<AdsPixelStatsResult> execute(Map<String, Object> extraParams) throws APIException {
            lastResponse = parseResponse(executeInternal(extraParams));
            return lastResponse;
        }

        public APIRequestGetStats(String nodeId, APIContext context) {
            super(context, nodeId, "/stats", "GET", Arrays.asList(PARAMS));
        }

        @Override
        public APIRequestGetStats setParam(String param, Object value) {
            setParamInternal(param, value);
            return this;
        }

        @Override
        public APIRequestGetStats setParams(Map<String, Object> params) {
            setParamsInternal(params);
            return this;
        }

        public APIRequestGetStats setAggregation(AdsPixelStatsResult.EnumAggregation aggregation) {
            this.setParam("aggregation", aggregation);
            return this;
        }

        public APIRequestGetStats setAggregation(String aggregation) {
            this.setParam("aggregation", aggregation);
            return this;
        }

        public APIRequestGetStats setEndTime(String endTime) {
            this.setParam("end_time", endTime);
            return this;
        }

        public APIRequestGetStats setStartTime(String startTime) {
            this.setParam("start_time", startTime);
            return this;
        }

        public APIRequestGetStats requestAllFields() {
            return this.requestAllFields(true);
        }

        public APIRequestGetStats requestAllFields(boolean value) {
            for (String field : FIELDS) {
                this.requestField(field, value);
            }
            return this;
        }

        @Override
        public APIRequestGetStats requestFields(List<String> fields) {
            return this.requestFields(fields, true);
        }

        @Override
        public APIRequestGetStats requestFields(List<String> fields, boolean value) {
            for (String field : fields) {
                this.requestField(field, value);
            }
            return this;
        }

        @Override
        public APIRequestGetStats requestField(String field) {
            this.requestField(field, true);
            return this;
        }

        @Override
        public APIRequestGetStats requestField(String field, boolean value) {
            this.requestFieldInternal(field, value);
            return this;
        }

        public APIRequestGetStats requestAggregationField() {
            return this.requestAggregationField(true);
        }

        public APIRequestGetStats requestAggregationField(boolean value) {
            this.requestField("aggregation", value);
            return this;
        }

        public APIRequestGetStats requestDataField() {
            return this.requestDataField(true);
        }

        public APIRequestGetStats requestDataField(boolean value) {
            this.requestField("data", value);
            return this;
        }

        public APIRequestGetStats requestTimestampField() {
            return this.requestTimestampField(true);
        }

        public APIRequestGetStats requestTimestampField(boolean value) {
            this.requestField("timestamp", value);
            return this;
        }
    }

    public static class APIRequestDelete extends APIRequest<APINode> {

        APINode lastResponse = null;

        @Override
        public APINode getLastResponse() {
            return lastResponse;
        }

        public static final String[] PARAMS = {};

        public static final String[] FIELDS = {};

        @Override
        public APINode parseResponse(String response) throws APIException {
            return APINode.parseResponse(response, getContext(), this).head();
        }

        @Override
        public APINode execute() throws APIException {
            return execute(new HashMap<String, Object>());
        }

        @Override
        public APINode execute(Map<String, Object> extraParams) throws APIException {
            lastResponse = parseResponse(executeInternal(extraParams));
            return lastResponse;
        }

        public APIRequestDelete(String nodeId, APIContext context) {
            super(context, nodeId, "/", "DELETE", Arrays.asList(PARAMS));
        }

        @Override
        public APIRequestDelete setParam(String param, Object value) {
            setParamInternal(param, value);
            return this;
        }

        @Override
        public APIRequestDelete setParams(Map<String, Object> params) {
            setParamsInternal(params);
            return this;
        }

        public APIRequestDelete requestAllFields() {
            return this.requestAllFields(true);
        }

        public APIRequestDelete requestAllFields(boolean value) {
            for (String field : FIELDS) {
                this.requestField(field, value);
            }
            return this;
        }

        @Override
        public APIRequestDelete requestFields(List<String> fields) {
            return this.requestFields(fields, true);
        }

        @Override
        public APIRequestDelete requestFields(List<String> fields, boolean value) {
            for (String field : fields) {
                this.requestField(field, value);
            }
            return this;
        }

        @Override
        public APIRequestDelete requestField(String field) {
            this.requestField(field, true);
            return this;
        }

        @Override
        public APIRequestDelete requestField(String field, boolean value) {
            this.requestFieldInternal(field, value);
            return this;
        }

    }

    public static class APIRequestGet extends APIRequest<CustomConversion> {

        CustomConversion lastResponse = null;

        @Override
        public CustomConversion getLastResponse() {
            return lastResponse;
        }

        public static final String[] PARAMS = {};

        public static final String[] FIELDS = { "account_id", "creation_time", "custom_event_type",
                "default_conversion_value", "description", "first_fired_time", "id", "is_archived",
                "last_fired_time", "name", "pixel", "pixel_aggregation_rule", "pixel_rule", "retention_days", };

        @Override
        public CustomConversion parseResponse(String response) throws APIException {
            return CustomConversion.parseResponse(response, getContext(), this).head();
        }

        @Override
        public CustomConversion execute() throws APIException {
            return execute(new HashMap<String, Object>());
        }

        @Override
        public CustomConversion execute(Map<String, Object> extraParams) throws APIException {
            lastResponse = parseResponse(executeInternal(extraParams));
            return lastResponse;
        }

        public APIRequestGet(String nodeId, APIContext context) {
            super(context, nodeId, "/", "GET", Arrays.asList(PARAMS));
        }

        @Override
        public APIRequestGet setParam(String param, Object value) {
            setParamInternal(param, value);
            return this;
        }

        @Override
        public APIRequestGet setParams(Map<String, Object> params) {
            setParamsInternal(params);
            return this;
        }

        public APIRequestGet requestAllFields() {
            return this.requestAllFields(true);
        }

        public APIRequestGet requestAllFields(boolean value) {
            for (String field : FIELDS) {
                this.requestField(field, value);
            }
            return this;
        }

        @Override
        public APIRequestGet requestFields(List<String> fields) {
            return this.requestFields(fields, true);
        }

        @Override
        public APIRequestGet requestFields(List<String> fields, boolean value) {
            for (String field : fields) {
                this.requestField(field, value);
            }
            return this;
        }

        @Override
        public APIRequestGet requestField(String field) {
            this.requestField(field, true);
            return this;
        }

        @Override
        public APIRequestGet requestField(String field, boolean value) {
            this.requestFieldInternal(field, value);
            return this;
        }

        public APIRequestGet requestAccountIdField() {
            return this.requestAccountIdField(true);
        }

        public APIRequestGet requestAccountIdField(boolean value) {
            this.requestField("account_id", value);
            return this;
        }

        public APIRequestGet requestCreationTimeField() {
            return this.requestCreationTimeField(true);
        }

        public APIRequestGet requestCreationTimeField(boolean value) {
            this.requestField("creation_time", value);
            return this;
        }

        public APIRequestGet requestCustomEventTypeField() {
            return this.requestCustomEventTypeField(true);
        }

        public APIRequestGet requestCustomEventTypeField(boolean value) {
            this.requestField("custom_event_type", value);
            return this;
        }

        public APIRequestGet requestDefaultConversionValueField() {
            return this.requestDefaultConversionValueField(true);
        }

        public APIRequestGet requestDefaultConversionValueField(boolean value) {
            this.requestField("default_conversion_value", value);
            return this;
        }

        public APIRequestGet requestDescriptionField() {
            return this.requestDescriptionField(true);
        }

        public APIRequestGet requestDescriptionField(boolean value) {
            this.requestField("description", value);
            return this;
        }

        public APIRequestGet requestFirstFiredTimeField() {
            return this.requestFirstFiredTimeField(true);
        }

        public APIRequestGet requestFirstFiredTimeField(boolean value) {
            this.requestField("first_fired_time", value);
            return this;
        }

        public APIRequestGet requestIdField() {
            return this.requestIdField(true);
        }

        public APIRequestGet requestIdField(boolean value) {
            this.requestField("id", value);
            return this;
        }

        public APIRequestGet requestIsArchivedField() {
            return this.requestIsArchivedField(true);
        }

        public APIRequestGet requestIsArchivedField(boolean value) {
            this.requestField("is_archived", value);
            return this;
        }

        public APIRequestGet requestLastFiredTimeField() {
            return this.requestLastFiredTimeField(true);
        }

        public APIRequestGet requestLastFiredTimeField(boolean value) {
            this.requestField("last_fired_time", value);
            return this;
        }

        public APIRequestGet requestNameField() {
            return this.requestNameField(true);
        }

        public APIRequestGet requestNameField(boolean value) {
            this.requestField("name", value);
            return this;
        }

        public APIRequestGet requestPixelField() {
            return this.requestPixelField(true);
        }

        public APIRequestGet requestPixelField(boolean value) {
            this.requestField("pixel", value);
            return this;
        }

        public APIRequestGet requestPixelAggregationRuleField() {
            return this.requestPixelAggregationRuleField(true);
        }

        public APIRequestGet requestPixelAggregationRuleField(boolean value) {
            this.requestField("pixel_aggregation_rule", value);
            return this;
        }

        public APIRequestGet requestPixelRuleField() {
            return this.requestPixelRuleField(true);
        }

        public APIRequestGet requestPixelRuleField(boolean value) {
            this.requestField("pixel_rule", value);
            return this;
        }

        public APIRequestGet requestRetentionDaysField() {
            return this.requestRetentionDaysField(true);
        }

        public APIRequestGet requestRetentionDaysField(boolean value) {
            this.requestField("retention_days", value);
            return this;
        }
    }

    public static class APIRequestUpdate extends APIRequest<CustomConversion> {

        CustomConversion lastResponse = null;

        @Override
        public CustomConversion getLastResponse() {
            return lastResponse;
        }

        public static final String[] PARAMS = { "default_conversion_value", "description", "name", };

        public static final String[] FIELDS = {};

        @Override
        public CustomConversion parseResponse(String response) throws APIException {
            return CustomConversion.parseResponse(response, getContext(), this).head();
        }

        @Override
        public CustomConversion execute() throws APIException {
            return execute(new HashMap<String, Object>());
        }

        @Override
        public CustomConversion execute(Map<String, Object> extraParams) throws APIException {
            lastResponse = parseResponse(executeInternal(extraParams));
            return lastResponse;
        }

        public APIRequestUpdate(String nodeId, APIContext context) {
            super(context, nodeId, "/", "POST", Arrays.asList(PARAMS));
        }

        @Override
        public APIRequestUpdate setParam(String param, Object value) {
            setParamInternal(param, value);
            return this;
        }

        @Override
        public APIRequestUpdate setParams(Map<String, Object> params) {
            setParamsInternal(params);
            return this;
        }

        public APIRequestUpdate setDefaultConversionValue(Double defaultConversionValue) {
            this.setParam("default_conversion_value", defaultConversionValue);
            return this;
        }

        public APIRequestUpdate setDefaultConversionValue(String defaultConversionValue) {
            this.setParam("default_conversion_value", defaultConversionValue);
            return this;
        }

        public APIRequestUpdate setDescription(String description) {
            this.setParam("description", description);
            return this;
        }

        public APIRequestUpdate setName(String name) {
            this.setParam("name", name);
            return this;
        }

        public APIRequestUpdate requestAllFields() {
            return this.requestAllFields(true);
        }

        public APIRequestUpdate requestAllFields(boolean value) {
            for (String field : FIELDS) {
                this.requestField(field, value);
            }
            return this;
        }

        @Override
        public APIRequestUpdate requestFields(List<String> fields) {
            return this.requestFields(fields, true);
        }

        @Override
        public APIRequestUpdate requestFields(List<String> fields, boolean value) {
            for (String field : fields) {
                this.requestField(field, value);
            }
            return this;
        }

        @Override
        public APIRequestUpdate requestField(String field) {
            this.requestField(field, true);
            return this;
        }

        @Override
        public APIRequestUpdate requestField(String field, boolean value) {
            this.requestFieldInternal(field, value);
            return this;
        }

    }

    public static enum EnumCustomEventType {
        @SerializedName("ADD_PAYMENT_INFO")
        VALUE_ADD_PAYMENT_INFO("ADD_PAYMENT_INFO"), @SerializedName("ADD_TO_CART")
        VALUE_ADD_TO_CART("ADD_TO_CART"), @SerializedName("ADD_TO_WISHLIST")
        VALUE_ADD_TO_WISHLIST("ADD_TO_WISHLIST"), @SerializedName("COMPLETE_REGISTRATION")
        VALUE_COMPLETE_REGISTRATION("COMPLETE_REGISTRATION"), @SerializedName("CONTENT_VIEW")
        VALUE_CONTENT_VIEW("CONTENT_VIEW"), @SerializedName("INITIATED_CHECKOUT")
        VALUE_INITIATED_CHECKOUT("INITIATED_CHECKOUT"), @SerializedName("LEAD")
        VALUE_LEAD("LEAD"), @SerializedName("OTHER")
        VALUE_OTHER("OTHER"), @SerializedName("PURCHASE")
        VALUE_PURCHASE("PURCHASE"), @SerializedName("SEARCH")
        VALUE_SEARCH("SEARCH"), NULL(null);

        private String value;

        private EnumCustomEventType(String value) {
            this.value = value;
        }

        @Override
        public String toString() {
            return value;
        }
    }

    public static enum EnumEventType {
        @SerializedName("conversion_create")
        VALUE_CONVERSION_CREATE("conversion_create"), @SerializedName("conversion_delete")
        VALUE_CONVERSION_DELETE("conversion_delete"), @SerializedName("conversion_update")
        VALUE_CONVERSION_UPDATE("conversion_update"), NULL(null);

        private String value;

        private EnumEventType(String value) {
            this.value = value;
        }

        @Override
        public String toString() {
            return value;
        }
    }

    synchronized /*package*/ static Gson getGson() {
        if (gson != null) {
            return gson;
        } else {
            gson = new GsonBuilder().excludeFieldsWithModifiers(Modifier.STATIC)
                    .excludeFieldsWithModifiers(Modifier.PROTECTED).disableHtmlEscaping().create();
        }
        return gson;
    }

    public CustomConversion copyFrom(CustomConversion instance) {
        this.mAccountId = instance.mAccountId;
        this.mCreationTime = instance.mCreationTime;
        this.mCustomEventType = instance.mCustomEventType;
        this.mDefaultConversionValue = instance.mDefaultConversionValue;
        this.mDescription = instance.mDescription;
        this.mFirstFiredTime = instance.mFirstFiredTime;
        this.mId = instance.mId;
        this.mIsArchived = instance.mIsArchived;
        this.mLastFiredTime = instance.mLastFiredTime;
        this.mName = instance.mName;
        this.mPixel = instance.mPixel;
        this.mPixelAggregationRule = instance.mPixelAggregationRule;
        this.mPixelRule = instance.mPixelRule;
        this.mRetentionDays = instance.mRetentionDays;
        this.context = instance.context;
        this.rawValue = instance.rawValue;
        return this;
    }

    public static APIRequest.ResponseParser<CustomConversion> getParser() {
        return new APIRequest.ResponseParser<CustomConversion>() {
            public APINodeList<CustomConversion> parseResponse(String response, APIContext context,
                    APIRequest<CustomConversion> request) throws MalformedResponseException {
                return CustomConversion.parseResponse(response, context, request);
            }
        };
    }
}