package com.growthbeat.analytics.model;

import java.util.Date;

import org.json.JSONException;
import org.json.JSONObject;

import com.growthbeat.model.Model;
import com.growthbeat.utils.DateUtils;
import com.growthbeat.utils.JSONObjectUtils;

public class ClientTag extends Model {

	private String id;

	private String clientId;

	private String tagId;

	private String value;

	private Date created;

	public ClientTag() {
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getClientId() {
		return clientId;
	}

	public void setClientId(String clientId) {
		this.clientId = clientId;
	}

	public String getTagId() {
		return tagId;
	}

	public void setTagId(String tagId) {
		this.tagId = tagId;
	}

	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}

	public Date getCreated() {
		return created;
	}

	public void setCreated(Date created) {
		this.created = created;
	}

	@Override
	public JSONObject getJsonObject() {

		JSONObject jsonObject = new JSONObject();
		try {
			jsonObject.put("id", getId());
			jsonObject.put("clientId", clientId);
			jsonObject.put("tagId", tagId);
			jsonObject.put("value", value);
			jsonObject.put("created", DateUtils.formatToDateTimeString(getCreated()));
		} catch (JSONException e) {
			return null;
		}

		return jsonObject;

	}

	@Override
	public void setJsonObject(JSONObject jsonObject) {

		if (jsonObject == null)
			return;

		try {
			if (JSONObjectUtils.hasAndIsNotNull(jsonObject, "id"))
				setId(jsonObject.getString("id"));
			if (JSONObjectUtils.hasAndIsNotNull(jsonObject, "clientId"))
				setClientId(jsonObject.getString("clientId"));
			if (JSONObjectUtils.hasAndIsNotNull(jsonObject, "tagId"))
				setTagId(jsonObject.getString("tagId"));
			if (JSONObjectUtils.hasAndIsNotNull(jsonObject, "value"))
				setValue(jsonObject.getString("value"));
			if (JSONObjectUtils.hasAndIsNotNull(jsonObject, "created"))
				setCreated(DateUtils.parseFromDateTimeString(jsonObject.getString("created")));
		} catch (JSONException e) {
			throw new IllegalArgumentException("Failed to parse JSON.");
		}

	}
}

@@ -56,16 +56,64 @@
 il.Date;
+%0Aimport java.util.HashMap;%0Aimport java.util.Map;
 %0A%0Aimport
@@ -166,16 +166,65 @@
 bject;%0A%0A
+import com.growthbeat.analytics.GrowthAnalytics;%0A
 import c
@@ -495,16 +495,16 @@
 eated;%0A%0A
-
 %09public 
@@ -517,24 +517,435 @@
 Tag() %7B%0A%09%7D%0A%0A
+%09public ClientTag create(String clientId, String tagId, String value) %7B%0A%0A%09%09Map%3CString, Object%3E params = new HashMap%3CString, Object%3E();%0A%09%09params.put(%22clientId%22, clientId);%0A%09%09params.put(%22tagId%22, tagId);%0A%09%09params.put(%22value%22, value);%0A%09%09JSONObject jsonObject = GrowthAnalytics.getInstance().getHttpClient().post(%221/client_tags%22, params);%0A%09%09if (jsonObject != null)%0A%09%09%09setJsonObject(jsonObject);%0A%0A%09%09return this;%0A%0A%09%7D%0A%0A
 %09public Stri

Add ClientTag#create