// Path: src/main/com/sailthru/client/exceptions/ApiException.java
// @SuppressWarnings("serial")
// public class ApiException extends IOException {
// 
//     private static final String ERRORMSG = "errormsg";
// 
//     private static final Logger logger = LoggerFactory.getLogger(ApiException.class);
// 
//     private Map<String, Object> jsonResponse;
//     private int statusCode;
// 
//     public ApiException(int statusCode, String reason, Map<String, Object> jsonResponse) {
//         super(reason);
//         logger.warn("{}: {}", statusCode, reason);
//         this.jsonResponse = jsonResponse;
//         this.statusCode = statusCode;
//     }
// 
//     public Map<String, Object> getResponse() {
//         return jsonResponse;
//     }
// 
//     public int getStatusCode() {
//         return statusCode;
//     }
// 
//     @SuppressWarnings("unchecked")
//     public static ApiException create(StatusLine statusLine, Object jsonResponse) {
//         return create(statusLine, (Map<String, Object>)jsonResponse);
//     }
// 
//     public static ApiException create(StatusLine statusLine, Map<String, Object> jsonResponse) {
//         if (jsonResponse == null) {
//             jsonResponse = new HashMap<String, Object>();
//         }
// 
//         final String errorMessage = jsonResponse.get(ERRORMSG) == null ? "" :
//             jsonResponse.get(ERRORMSG).toString();
// 
//         return new ApiException(statusLine.getStatusCode(), errorMessage, jsonResponse);
//     }
// }
// 
// Path: src/main/com/sailthru/client/params/User.java
// public class User extends AbstractApiParams implements ApiParams {
//     public static final String PARAM_TEMPLATE = "user";
//     
//     protected String id;
//     protected String key;
//     protected Map<String, Object> fields;
//     protected Map<String, String> keys;
//     protected String keysconflict;
//     protected Map<String, Object> vars;
//     protected Map<String, Integer> lists;
//     protected String optout_email;
//     protected String optout_sms_status;
//     protected Map<String, Object> login;
//     
//     public User(String id) {
//         this.id = id;
//     }
// 
//     public User() {
//         // this will be used when new user_id is to be created
//     }
//     
//     public User setKey(String key) {
//         this.key = key;
//         return this;
//     }
//     
//     public User setFields(Map<String, Object> fields) {
//         this.fields = fields;
//         return this;
//     }
//     
//     public User setKeys(Map<String, String> keys) {
//         this.keys = keys;
//         return this;
//     }
// 
//     public User setKeysConflict(String keysConflict) {
//         this.keysconflict = keysConflict;
//         return this;
//     }
//     
//     public User setVars(Map<String, Object> vars) {
//         this.vars = vars;
//         return this;
//     }
//     
//     public User setLists(Map<String, Integer> lists) {
//         this.lists = lists;
//         return this;
//     }
//     
//     public User setOptoutEmail(String optoutEmail) {
//         this.optout_email = optoutEmail;
//         return this;
//     }
// 
//     public User setOptoutSmsStatus(String optoutSmsStatus) {
//         this.optout_sms_status = optoutSmsStatus;
//         return this;
//     }
// 
//     public User setLogin(Map<String, Object> login) {
//         this.login = login;
//         return this;
//     }
// 
//     public Type getType() {
//         java.lang.reflect.Type _type = new TypeToken<User>() {}.getType();
//         return _type;
//     }
// 
//     public ApiAction getApiCall() {
//         return ApiAction.user;
//     }
// }


import com.sailthru.client.exceptions.ApiException;
import com.sailthru.client.handler.response.JsonResponse;
import com.sailthru.client.params.User;
import java.io.IOException;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
package com.sailthru.client;



public class UserExample {
    public static void main(String[] args) {
        String apiKey = "****";
        String apiSecret = "****";
        SailthruClient client = new SailthruClient(apiKey, apiSecret);
        try {
            String sailthruId = "4d371896cc0c1adbb079b8d0";
            User user = new User(sailthruId);

            Map<String, Object> vars = new HashMap<String, Object>();
            vars.put("name", "Prajwal Tuladhar");
            Map<String, String> addressVars = new HashMap<String, String>();
            addressVars.put("state", "NY");
            addressVars.put("city", "Jackson Heights");
            addressVars.put("zip", "11372");
            vars.put("address", addressVars);
            user.setVars(vars);

            JsonResponse response1 = client.getUser(user); // GET

            JsonResponse response2 = client.saveUser(user);

            if (response1.isOK()) {
                System.out.println(response1.getResponse());
            } else {
                System.out.println(response1.getResponse().get("error").toString());
            }

            // optionally get the rate limit information for the corresponding API endpoint/method
            LastRateLimitInfo lastRateLimitInfo = client.getLastRateLimitInfo(ApiAction.user, AbstractSailthruClient.HttpRequestMethod.POST);
            if (lastRateLimitInfo != null) {
                // examine rate limit information
                int limit = lastRateLimitInfo.getLimit();
                int remaining = lastRateLimitInfo.getRemaining();
                Date reset = lastRateLimitInfo.getReset();
                // ...
            }
// Path: src/main/com/sailthru/client/exceptions/ApiException.java
// @SuppressWarnings("serial")
// public class ApiException extends IOException {
// 
//     private static final String ERRORMSG = "errormsg";
// 
//     private static final Logger logger = LoggerFactory.getLogger(ApiException.class);
// 
//     private Map<String, Object> jsonResponse;
//     private int statusCode;
// 
//     public ApiException(int statusCode, String reason, Map<String, Object> jsonResponse) {
//         super(reason);
//         logger.warn("{}: {}", statusCode, reason);
//         this.jsonResponse = jsonResponse;
//         this.statusCode = statusCode;
//     }
// 
//     public Map<String, Object> getResponse() {
//         return jsonResponse;
//     }
// 
//     public int getStatusCode() {
//         return statusCode;
//     }
// 
//     @SuppressWarnings("unchecked")
//     public static ApiException create(StatusLine statusLine, Object jsonResponse) {
//         return create(statusLine, (Map<String, Object>)jsonResponse);
//     }
// 
//     public static ApiException create(StatusLine statusLine, Map<String, Object> jsonResponse) {
//         if (jsonResponse == null) {
//             jsonResponse = new HashMap<String, Object>();
//         }
// 
//         final String errorMessage = jsonResponse.get(ERRORMSG) == null ? "" :
//             jsonResponse.get(ERRORMSG).toString();
// 
//         return new ApiException(statusLine.getStatusCode(), errorMessage, jsonResponse);
//     }
// }
// 
// Path: src/main/com/sailthru/client/params/User.java
// public class User extends AbstractApiParams implements ApiParams {
//     public static final String PARAM_TEMPLATE = "user";
//     
//     protected String id;
//     protected String key;
//     protected Map<String, Object> fields;
//     protected Map<String, String> keys;
//     protected String keysconflict;
//     protected Map<String, Object> vars;
//     protected Map<String, Integer> lists;
//     protected String optout_email;
//     protected String optout_sms_status;
//     protected Map<String, Object> login;
//     
//     public User(String id) {
//         this.id = id;
//     }
// 
//     public User() {
//         // this will be used when new user_id is to be created
//     }
//     
//     public User setKey(String key) {
//         this.key = key;
//         return this;
//     }
//     
//     public User setFields(Map<String, Object> fields) {
//         this.fields = fields;
//         return this;
//     }
//     
//     public User setKeys(Map<String, String> keys) {
//         this.keys = keys;
//         return this;
//     }
// 
//     public User setKeysConflict(String keysConflict) {
//         this.keysconflict = keysConflict;
//         return this;
//     }
//     
//     public User setVars(Map<String, Object> vars) {
//         this.vars = vars;
//         return this;
//     }
//     
//     public User setLists(Map<String, Integer> lists) {
//         this.lists = lists;
//         return this;
//     }
//     
//     public User setOptoutEmail(String optoutEmail) {
//         this.optout_email = optoutEmail;
//         return this;
//     }
// 
//     public User setOptoutSmsStatus(String optoutSmsStatus) {
//         this.optout_sms_status = optoutSmsStatus;
//         return this;
//     }
// 
//     public User setLogin(Map<String, Object> login) {
//         this.login = login;
//         return this;
//     }
// 
//     public Type getType() {
//         java.lang.reflect.Type _type = new TypeToken<User>() {}.getType();
//         return _type;
//     }
// 
//     public ApiAction getApiCall() {
//         return ApiAction.user;
//     }
// }


// Path: examples/com/sailthru/client/UserExample.java
import com.sailthru.client.exceptions.ApiException;
import com.sailthru.client.handler.response.JsonResponse;
import com.sailthru.client.params.User;
import java.io.IOException;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

package com.sailthru.client;



public class UserExample {
    public static void main(String[] args) {
        String apiKey = "****";
        String apiSecret = "****";
        SailthruClient client = new SailthruClient(apiKey, apiSecret);
        try {
            String sailthruId = "4d371896cc0c1adbb079b8d0";
            User user = new User(sailthruId);

            Map<String, Object> vars = new HashMap<String, Object>();
            vars.put("name", "Prajwal Tuladhar");
            Map<String, String> addressVars = new HashMap<String, String>();
            addressVars.put("state", "NY");
            addressVars.put("city", "Jackson Heights");
            addressVars.put("zip", "11372");
            vars.put("address", addressVars);
            user.setVars(vars);

            JsonResponse response1 = client.getUser(user); // GET

            JsonResponse response2 = client.saveUser(user);

            if (response1.isOK()) {
                System.out.println(response1.getResponse());
            } else {
                System.out.println(response1.getResponse().get("error").toString());
            }

            // optionally get the rate limit information for the corresponding API endpoint/method
            LastRateLimitInfo lastRateLimitInfo = client.getLastRateLimitInfo(ApiAction.user, AbstractSailthruClient.HttpRequestMethod.POST);
            if (lastRateLimitInfo != null) {
                // examine rate limit information
                int limit = lastRateLimitInfo.getLimit();
                int remaining = lastRateLimitInfo.getRemaining();
                Date reset = lastRateLimitInfo.getReset();
                // ...
            }
        } catch (ApiException e) {