Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

* Added new api end-points: getAllListsMetadata() & getListMetadata(String) #43

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 68 additions & 23 deletions src/main/com/sailthru/client/SailthruClient.java
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
}

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<String, Object> data = new HashMap<String, Object>();
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
Expand Down Expand Up @@ -394,61 +439,61 @@ public Map<String, Object> listStats(ListStat stat) throws IOException {
public Map<String, Object> blastStats(BlastStat stat) throws IOException {
return (Map<String, Object>)this.stats(stat);
}


/**
* Get status of a job
* @param jobId
* @return JsonResponse
* @throws IOException
* @throws IOException
*/
public JsonResponse getJobStatus(String jobId) throws IOException {
Map<String, Object> params = new HashMap<String, Object>();
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
Expand Down
17 changes: 10 additions & 7 deletions src/main/com/sailthru/client/params/List.java
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
*/
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;
Expand All @@ -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<List>() {}.getType();
}
Expand Down