// 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);
//     }
// }


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



public class TemplateExample {
    public static void main(String[] args) {
        String apiKey = "****";
        String apiSecret = "****";
        SailthruClient client = new SailthruClient(apiKey, apiSecret);
        try {
            Template template = new Template();
            template.setTemplate("my-template");
            template.setFromEmail("no-reply@example.com");
            template.setFromName("Example Example");
            template.setSubject("Hello {name}!");
            template.setContentHtml("HTML content goes here");
            template.setContentText("Text content goes here");

            JsonResponse response = client.saveTemplate(template);

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

            // optionally get the rate limit information for the corresponding API endpoint/method
            LastRateLimitInfo lastRateLimitInfo = client.getLastRateLimitInfo(ApiAction.template, 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: examples/com/sailthru/client/TemplateExample.java
import com.sailthru.client.exceptions.ApiException;
import com.sailthru.client.handler.response.JsonResponse;
import com.sailthru.client.params.Template;
import java.io.IOException;
import java.util.Date;

package com.sailthru.client;



public class TemplateExample {
    public static void main(String[] args) {
        String apiKey = "****";
        String apiSecret = "****";
        SailthruClient client = new SailthruClient(apiKey, apiSecret);
        try {
            Template template = new Template();
            template.setTemplate("my-template");
            template.setFromEmail("no-reply@example.com");
            template.setFromName("Example Example");
            template.setSubject("Hello {name}!");
            template.setContentHtml("HTML content goes here");
            template.setContentText("Text content goes here");

            JsonResponse response = client.saveTemplate(template);

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

            // optionally get the rate limit information for the corresponding API endpoint/method
            LastRateLimitInfo lastRateLimitInfo = client.getLastRateLimitInfo(ApiAction.template, 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) {