package com.sailthru.client;

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.HashMap;
import java.util.Map;

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");

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

            template.setVars(vars);

            JsonResponse response = client.saveTemplate(template);

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

        } catch (ApiException e) {
            // handle exception
        } catch (IOException e) {
            // handle exception
        }
    }
}

@@ -868,433 +868,8 @@
 );%0A%0A
-            Map%3CString, Object%3E vars = new HashMap%3CString, Object%3E();%0A            vars.put(%22name%22, %22Prajwal Tuladhar%22);%0A            Map%3CString, String%3E addressVars = new HashMap%3CString, String%3E();%0A            addressVars.put(%22state%22, %22NY%22);%0A            addressVars.put(%22city%22, %22Jackson Heights%22);%0A            addressVars.put(%22zip%22, %2211372%22);%0A            vars.put(%22address%22, addressVars);%0A%0A            template.setVars(vars);%0A
 %0A   

remove vars from example template call