diff --git a/src/main/com/sailthru/client/SailthruClient.java b/src/main/com/sailthru/client/SailthruClient.java index b440a9f..3fcf6fb 100644 --- a/src/main/com/sailthru/client/SailthruClient.java +++ b/src/main/com/sailthru/client/SailthruClient.java @@ -1,13 +1,32 @@ package com.sailthru.client; -import com.sailthru.client.handler.response.JsonResponse; -import com.sailthru.client.params.*; -import com.sailthru.client.params.job.*; import java.io.IOException; import java.util.Date; import java.util.HashMap; import java.util.Map; +import com.sailthru.client.handler.response.JsonResponse; +import com.sailthru.client.params.Alert; +import com.sailthru.client.params.Blast; +import com.sailthru.client.params.BlastStat; +import com.sailthru.client.params.Content; +import com.sailthru.client.params.Email; +import com.sailthru.client.params.Event; +import com.sailthru.client.params.List; +import com.sailthru.client.params.ListStat; +import com.sailthru.client.params.MultiSend; +import com.sailthru.client.params.Purchase; +import com.sailthru.client.params.Send; +import com.sailthru.client.params.Stats; +import com.sailthru.client.params.Template; +import com.sailthru.client.params.User; +import com.sailthru.client.params.job.BlastQueryJob; +import com.sailthru.client.params.job.ExportListDataJob; +import com.sailthru.client.params.job.ImportJob; +import com.sailthru.client.params.job.Job; +import com.sailthru.client.params.job.SnapshotJob; +import com.sailthru.client.params.job.UpdateJob; + /** * Main class exposing API calls for Sailthru API as per http://docs.sailthru.com/api * @author Prajwal Tuladhar @@ -53,6 +72,7 @@ public SailthruClient(String apiKey, String apiSecret, SailthruHttpClientConfigu * @return singleton instance of SailthruClient * @deprecated */ + @Deprecated public static synchronized SailthruClient getInstance(String apiKey, String apiSecret) { if (_instance == null) { _instance = new SailthruClient(apiKey, apiSecret, DEFAULT_API_URL); @@ -68,6 +88,7 @@ public static synchronized SailthruClient getInstance(String apiKey, String apiS * @return singleton instance of SailthruClient * @deprecated */ + @Deprecated public static synchronized SailthruClient getInstance(String apiKey, String apiSecret, String apiUrl) { if (_instance == null) { _instance = new SailthruClient(apiKey, apiSecret, apiUrl); @@ -120,7 +141,7 @@ public JsonResponse send(Send send) throws IOException { * @param multiSend * @throws IOException */ - public JsonResponse multiSend(MultiSend multiSend) throws IOException { + public JsonResponse multiSend(MultiSend multiSend) throws IOException { return apiPost(multiSend); } @@ -135,7 +156,7 @@ public JsonResponse cancelSend(String sendId) throws IOException { data.put(Send.PARAM_SEND_ID, sendId); return apiDelete(ApiAction.send, data); } - + /** * Cancel a send that was scheduled for a future time. * @param send @@ -312,7 +333,7 @@ public JsonResponse deleteTemplate(String template) throws IOException { public JsonResponse pushContent(Content content) throws IOException { return apiPost(content); } - + /** * Push an event to Sailthru, triggering any applicable triggers. * @param event @@ -366,6 +387,30 @@ public JsonResponse purchase(Purchase purchase) throws IOException { return apiPost(purchase); } + /** + * Get Metadata info for all lists + * + * @return + * @throws IOException + */ + public JsonResponse getAllListsMetadata() throws IOException { + return getListMetadata(null); + } + + /** + * Get Metadata info of given listId + * @param listId list id + * @return + * @throws IOException + */ + public JsonResponse getListMetadata(String listId) throws IOException { + Map data = new HashMap(); + if ((listId != null) && (listId.trim().length() != 0)) { + data.put(List.PARAM_LIST_ID, listId); + } + return apiGet(ApiAction.list, data); + } + /** * Make stats API request * @param stats @@ -394,61 +439,61 @@ public Map listStats(ListStat stat) throws IOException { public Map blastStats(BlastStat stat) throws IOException { return (Map)this.stats(stat); } - - + + /** * Get status of a job * @param jobId * @return JsonResponse - * @throws IOException + * @throws IOException */ public JsonResponse getJobStatus(String jobId) throws IOException { Map params = new HashMap(); params.put(Job.JOB_ID, jobId); return apiGet(ApiAction.job, params); } - - + + /** * Process import job from given email string CSV or file path of a CSV or email per line file * @param job - * @throws IOException + * @throws IOException */ public JsonResponse processImportJob(ImportJob job) throws IOException { return apiPost(job, job); } - - + + /** * Query user data set and generate a detailed snapshot of their analytics similar to that shown in the Snapshot Report in the Sailthru interface. * @param job SnapshotJob - * @throws IOException + * @throws IOException */ public JsonResponse processSnapshotJob(SnapshotJob job) throws IOException { return apiPost(job); } - - + + /** * Export blast data in CSV format * @param job BlastQueryJob - * @throws IOException + * @throws IOException */ public JsonResponse processBlastQueryJob(BlastQueryJob job) throws IOException { return apiPost(job); } - - + + /** * Export user data from a list in CSV format * @param job ExportListDataJob - * @throws IOException + * @throws IOException */ public JsonResponse processExportListDataJob(ExportListDataJob job) throws IOException { return apiPost(job); } - - + + /** * Perform a bulk update of any number of user profiles * @param job UpdateJob diff --git a/src/main/com/sailthru/client/params/List.java b/src/main/com/sailthru/client/params/List.java index 0afc6b1..c7696ef 100644 --- a/src/main/com/sailthru/client/params/List.java +++ b/src/main/com/sailthru/client/params/List.java @@ -1,22 +1,23 @@ package com.sailthru.client.params; -import com.sailthru.client.ApiAction; +import java.lang.reflect.Type; + import com.google.gson.reflect.TypeToken; +import com.sailthru.client.ApiAction; import com.sailthru.client.params.query.Query; -import java.lang.reflect.Type; -import java.util.ArrayList; - /** * * @author Prajwal Tuladhar */ -public class List extends AbstractApiParams implements ApiParams { +public class List extends AbstractApiParams implements ApiParams { + public static final String PARAM_LIST_ID = "list_id"; + protected String list; protected Integer primary; protected ListType type; protected Query query; - + public List setQuery(Query query) { this.query = query; return this; @@ -31,16 +32,18 @@ public List setPrimary() { this.primary = 1; return this; } - + public List setListType(ListType listType) { this.type = listType; return this; } + @Override public ApiAction getApiCall() { return ApiAction.list; } + @Override public Type getType() { return new TypeToken() {}.getType(); }