diff --git a/src/main/com/sailthru/client/AbstractSailthruClient.java b/src/main/com/sailthru/client/AbstractSailthruClient.java index 8a50375..fdf8bfc 100644 --- a/src/main/com/sailthru/client/AbstractSailthruClient.java +++ b/src/main/com/sailthru/client/AbstractSailthruClient.java @@ -9,16 +9,6 @@ import com.sailthru.client.http.SailthruHttpClient; import com.sailthru.client.params.ApiFileParams; import com.sailthru.client.params.ApiParams; -import java.io.IOException; -import java.lang.reflect.Type; -import java.net.URI; -import java.net.URISyntaxException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; import org.apache.http.HttpVersion; import org.apache.http.conn.scheme.PlainSocketFactory; import org.apache.http.conn.scheme.Scheme; @@ -29,10 +19,20 @@ import org.apache.http.params.HttpConnectionParams; import org.apache.http.params.HttpParams; import org.apache.http.params.HttpProtocolParams; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.lang.reflect.Type; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.*; +import java.util.Map.Entry; /** - * Abstract class exposing genric API calls for Sailthru API as per http://docs.sailthru.com/api - * @author Prajwal Tuladhar + * Abstract class exposing genric API calls for Sailthru API + * @author Prajwal Tuladhar praj@sailthru.com + * @see http://docs.sailthru.com/api */ public abstract class AbstractSailthruClient { @@ -45,7 +45,7 @@ public abstract class AbstractSailthruClient { public static final String DEFAULT_ENCODING = "UTF-8"; //HTTP methods supported by Sailthru API - public static enum HttpRequestMethod { + public enum HttpRequestMethod { GET, POST, DELETE @@ -63,11 +63,14 @@ public static enum HttpRequestMethod { private final SailthruHttpClientConfiguration sailthruHttpClientConfiguration; + private static final Logger logger = LoggerFactory.getLogger(AbstractSailthruClient.class); + + /** * Main constructor class for setting up the client - * @param apiKey - * @param apiSecret - * @param apiUrl + * @param apiKey description // TODO add description + * @param apiSecret description // TODO add description + * @param apiUrl description // TODO add description */ public AbstractSailthruClient(String apiKey, String apiSecret, String apiUrl) { this(apiKey, apiSecret, apiUrl, new DefaultSailthruHttpClientConfiguration()); @@ -75,10 +78,10 @@ public AbstractSailthruClient(String apiKey, String apiSecret, String apiUrl) { /** * - * @param apiKey - * @param apiSecret - * @param apiUrl - * @param sailthruHttpClientConfiguration + * @param apiKey description // TODO add description + * @param apiSecret description // TODO add description + * @param apiUrl description // TODO add description + * @param sailthruHttpClientConfiguration description // TODO add description */ public AbstractSailthruClient(String apiKey, String apiSecret, String apiUrl, SailthruHttpClientConfiguration sailthruHttpClientConfiguration) { this.apiKey = apiKey; @@ -92,6 +95,7 @@ public AbstractSailthruClient(String apiKey, String apiSecret, String apiUrl, Sa /** * Create SailthruHttpClient + * @return SailthruHttpClient */ private SailthruHttpClient create() { HttpParams params = new BasicHttpParams(); @@ -114,6 +118,7 @@ private SailthruHttpClient create() { /** * Getter for SailthruHttpClient + * @return SailthruHttpClient */ public SailthruHttpClient getSailthruHttpClient() { return httpClient; @@ -122,6 +127,7 @@ public SailthruHttpClient getSailthruHttpClient() { /** * Get Scheme Object + * @return Scheme */ protected Scheme getScheme() { String scheme; @@ -141,11 +147,11 @@ protected Scheme getScheme() { /** * Make Http request to Sailthru API for given resource with given method and data - * @param action - * @param method + * @param action action to call on the Sailthru API + * @param method request method (e.g,, GET or POST) * @param data parameter data * @return Object - * @throws IOException + * @throws IOException description // TODO add description */ protected Object httpRequest(ApiAction action, HttpRequestMethod method, Map data) throws IOException { String url = this.apiUrl + "/" + action.toString(); @@ -158,9 +164,9 @@ protected Object httpRequest(ApiAction action, HttpRequestMethod method, Map buildPayload(String jsonPayload) { /** * Get Signature Hash from given Map + * @param parameters description // TODO add description + * @return String */ protected String getSignatureHash(Map parameters) { List values = new ArrayList(); @@ -236,7 +244,8 @@ protected String getSignatureHash(Map parameters) { * HTTP GET Request with Map * @param action API action * @param data Parameter data - * @throws IOException + * @return JsonResponse + * @throws IOException description // TODO add description */ public JsonResponse apiGet(ApiAction action, Map data) throws IOException { return httpRequestJson(action, HttpRequestMethod.GET, data); @@ -244,8 +253,9 @@ public JsonResponse apiGet(ApiAction action, Map data) throws IO /** * HTTP GET Request with Interface implementation of ApiParams - * @param data - * @throws IOException + * @param data description // TODO add description + * @return JsonResponse + * @throws IOException description // TODO add description */ public JsonResponse apiGet(ApiParams data) throws IOException { return httpRequestJson(HttpRequestMethod.GET, data); @@ -253,9 +263,10 @@ public JsonResponse apiGet(ApiParams data) throws IOException { /** * HTTP POST Request with Map - * @param action - * @param data - * @throws IOException + * @param action description // TODO add description + * @param data description // TODO add description + * @return JsonResponse + * @throws IOException description // TODO add description */ public JsonResponse apiPost(ApiAction action, Map data) throws IOException { return httpRequestJson(action, HttpRequestMethod.POST, data); @@ -263,8 +274,9 @@ public JsonResponse apiPost(ApiAction action, Map data) throws I /** * HTTP POST Request with Interface implementation of ApiParams - * @param data - * @throws IOException + * @param data description // TODO add description + * @return JsonResponse + * @throws IOException description // TODO add description */ public JsonResponse apiPost(ApiParams data) throws IOException { return httpRequestJson(HttpRequestMethod.POST, data); @@ -273,9 +285,10 @@ public JsonResponse apiPost(ApiParams data) throws IOException { /** * HTTP POST Request with Interface implementation of ApiParams and ApiFileParams - * @param data - * @param fileParams - * @throws IOException + * @param data description // TODO add description + * @param fileParams description // TODO add description + * @return JsonResponse + * @throws IOException description // TODO add description */ public JsonResponse apiPost(ApiParams data, ApiFileParams fileParams) throws IOException { return httpRequestJson(HttpRequestMethod.POST, data, fileParams); @@ -284,9 +297,10 @@ public JsonResponse apiPost(ApiParams data, ApiFileParams fileParams) throws IOE /** * HTTP DELETE Request - * @param action - * @param data - * @throws IOException + * @param action description // TODO add description + * @param data description // TODO add description + * @return JsonResponse + * @throws IOException description // TODO add description */ public JsonResponse apiDelete(ApiAction action, Map data) throws IOException { return httpRequestJson(action, HttpRequestMethod.DELETE, data); @@ -294,8 +308,9 @@ public JsonResponse apiDelete(ApiAction action, Map data) throws /** * HTTP DELETE Request with Interface implementation of ApiParams - * @param data - * @throws IOException + * @param data description // TODO add description + * @return JsonResponse + * @throws IOException description // TODO add description */ public JsonResponse apiDelete(ApiParams data) throws IOException { return httpRequestJson(HttpRequestMethod.DELETE, data); @@ -303,7 +318,7 @@ public JsonResponse apiDelete(ApiParams data) throws IOException { /** * Set response Handler, currently only JSON is supported but XML can also be supported later on - * @param responseHandler + * @param responseHandler description // TODO add description */ public void setResponseHandler(SailthruResponseHandler responseHandler) { this.handler.setSailthruResponseHandler(responseHandler); diff --git a/src/main/com/sailthru/client/ApiAction.java b/src/main/com/sailthru/client/ApiAction.java index 1ff6479..725e360 100644 --- a/src/main/com/sailthru/client/ApiAction.java +++ b/src/main/com/sailthru/client/ApiAction.java @@ -2,7 +2,7 @@ /** * API calls - * @author Prajwal Tuladhar + * @author Prajwal Tuladhar praj@sailthru.com */ public enum ApiAction { event, diff --git a/src/main/com/sailthru/client/SailthruClient.java b/src/main/com/sailthru/client/SailthruClient.java index b440a9f..75e13bc 100644 --- a/src/main/com/sailthru/client/SailthruClient.java +++ b/src/main/com/sailthru/client/SailthruClient.java @@ -9,8 +9,9 @@ import java.util.Map; /** - * Main class exposing API calls for Sailthru API as per http://docs.sailthru.com/api - * @author Prajwal Tuladhar + * Main class exposing API calls for Sailthru API + * @author Prajwal Tuladhar praj@sailthru.com + * @see http://docs.sailthru.com/api */ public class SailthruClient extends AbstractSailthruClient { @@ -77,8 +78,9 @@ public static synchronized SailthruClient getInstance(String apiKey, String apiS /** * Get information about one of your users. - * @param email - * @throws IOException + * @param email description // TODO add description + * @return JsonResponse + * @throws IOException description // TODO add description */ public JsonResponse getEmail(String email) throws IOException { Email emailObj = new Email(); @@ -88,8 +90,9 @@ public JsonResponse getEmail(String email) throws IOException { /** * Update information about one of your users, including adding and removing the user from lists. - * @param email - * @throws IOException + * @param email description // TODO add description + * @return JsonResponse + * @throws IOException description // TODO add description */ public JsonResponse setEmail(Email email) throws IOException { return apiPost(email); @@ -98,7 +101,8 @@ public JsonResponse setEmail(Email email) throws IOException { /** * Get the status of a transational send * @param sendId Unique send id - * @throws IOException + * @return JsonResponse + * @throws IOException description // TODO add description */ public JsonResponse getSend(String sendId) throws IOException { Map data = new HashMap(); @@ -109,7 +113,8 @@ public JsonResponse getSend(String sendId) throws IOException { /** * send an email template to a single email address. * @param send Send Object - * @throws IOException + * @return JsonResponse + * @throws IOException description // TODO add description */ public JsonResponse send(Send send) throws IOException { return apiPost(send); @@ -117,8 +122,9 @@ public JsonResponse send(Send send) throws IOException { /** * send an email template to multiple email addresses - * @param multiSend - * @throws IOException + * @param multiSend description // TODO add description + * @return JsonResponse + * @throws IOException description // TODO add description */ public JsonResponse multiSend(MultiSend multiSend) throws IOException { return apiPost(multiSend); @@ -126,9 +132,9 @@ public JsonResponse multiSend(MultiSend multiSend) throws IOException { /** * Cancel a send that was scheduled for a future time. - * @param sendId + * @param sendId description // TODO add description * @return JsonResponse - * @throws IOException + * @throws IOException description // TODO add description */ public JsonResponse cancelSend(String sendId) throws IOException { Map data = new HashMap(); @@ -138,9 +144,9 @@ public JsonResponse cancelSend(String sendId) throws IOException { /** * Cancel a send that was scheduled for a future time. - * @param send + * @param send description // TODO add description * @return JsonResponse - * @throws IOException + * @throws IOException description // TODO add description */ public JsonResponse cancelSend(Send send) throws IOException { return apiDelete(send); @@ -148,9 +154,9 @@ public JsonResponse cancelSend(Send send) throws IOException { /** * get information about a blast - * @param blastId + * @param blastId description // TODO add description * @return JsonResponse - * @throws IOException + * @throws IOException description // TODO add description */ public JsonResponse getBlast(Integer blastId) throws IOException { Blast blast = new Blast(); @@ -160,9 +166,9 @@ public JsonResponse getBlast(Integer blastId) throws IOException { /** * Schedule a mass mail blast - * @param blast + * @param blast description // TODO add description * @return JsonResponse - * @throws IOException + * @throws IOException description // TODO add description */ public JsonResponse scheduleBlast(Blast blast) throws IOException { return apiPost(blast); @@ -174,7 +180,8 @@ public JsonResponse scheduleBlast(Blast blast) throws IOException { * @param list list name * @param scheduleTime schedule time for the blast * @param blast Blast Object - * @throws IOException + * @return JsonResponse + * @throws IOException description // TODO add description */ public JsonResponse scheduleBlastFromTemplate(String template, String list, Date scheduleTime, Blast blast) throws IOException { blast.setCopyTemplate(template); @@ -189,7 +196,7 @@ public JsonResponse scheduleBlastFromTemplate(String template, String list, Date * @param list list name * @param scheduleTime schedule time for the blast * @return JsonResponse - * @throws IOException + * @throws IOException description // TODO add description */ public JsonResponse scheduleBlastFromTemplate(String template, String list, Date scheduleTime) throws IOException { Blast blast = new Blast(); @@ -205,7 +212,7 @@ public JsonResponse scheduleBlastFromTemplate(String template, String list, Date * @param scheduleTime schedule time for the blast * @param blast Blast object * @return JsonResponse - * @throws IOException + * @throws IOException description // TODO add description */ public JsonResponse scheduleBlastFromBlast(Integer blastId, Date scheduleTime, Blast blast) throws IOException { blast.setCopyBlast(blastId); @@ -217,7 +224,8 @@ public JsonResponse scheduleBlastFromBlast(Integer blastId, Date scheduleTime, B * Schedule a mass mail blast from previous blast * @param blastId blast ID * @param scheduleTime schedule time for the blast - * @throws IOException + * @return JsonResponse + * @throws IOException description // TODO add description */ public JsonResponse scheduleBlastFromBlast(Integer blastId, Date scheduleTime) throws IOException { Blast blast = new Blast(); @@ -228,8 +236,9 @@ public JsonResponse scheduleBlastFromBlast(Integer blastId, Date scheduleTime) t /** * Update existing blast - * @param blastId - * @throws IOException + * @param blastId description // TODO add description + * @return JsonResponse + * @throws IOException description // TODO add description */ public JsonResponse updateBlast(Integer blastId) throws IOException { Blast blast = new Blast(); @@ -239,9 +248,10 @@ public JsonResponse updateBlast(Integer blastId) throws IOException { /** * Update existing blast - * @param blastId - * @param blast - * @throws IOException + * @param blastId description // TODO add description + * @param blast description // TODO add description + * @return JsonResponse + * @throws IOException description // TODO add description */ public JsonResponse updateBlast(Integer blastId, Blast blast) throws IOException { blast.setBlastId(blastId); @@ -250,8 +260,9 @@ public JsonResponse updateBlast(Integer blastId, Blast blast) throws IOException /** * Delete existing blast - * @param blastId - * @throws IOException + * @param blastId description // TODO add description + * @return JsonResponse + * @throws IOException description // TODO add description */ public JsonResponse deleteBlast(Integer blastId) throws IOException { Blast blast = new Blast(); @@ -262,7 +273,8 @@ public JsonResponse deleteBlast(Integer blastId) throws IOException { /** * Cancel a scheduled Blast * @param blastId Unique Blast ID - * @throws IOException + * @return JsonResponse + * @throws IOException description // TODO add description */ public JsonResponse cancelBlast(Integer blastId) throws IOException { Blast blast = new Blast(); @@ -276,7 +288,8 @@ public JsonResponse cancelBlast(Integer blastId) throws IOException { /** * Get template information * @param template template name - * @throws IOException + * @return JsonResponse + * @throws IOException description // TODO add description */ public JsonResponse getTemplate(String template) throws IOException { Map data = new HashMap(); @@ -287,7 +300,8 @@ public JsonResponse getTemplate(String template) throws IOException { /** * Save / update a template * @param template template name - * @throws IOException + * @return JsonResponse + * @throws IOException description // TODO add description */ public JsonResponse saveTemplate(Template template) throws IOException { return apiPost(template); @@ -296,7 +310,8 @@ public JsonResponse saveTemplate(Template template) throws IOException { /** * Delete existing template * @param template template name - * @throws IOException + * @return JsonResponse + * @throws IOException description // TODO add description */ public JsonResponse deleteTemplate(String template) throws IOException { Map data = new HashMap(); @@ -306,8 +321,9 @@ public JsonResponse deleteTemplate(String template) throws IOException { /** * Push a new piece of content to Sailthru, triggering any applicable alerts. - * @param content - * @throws IOException + * @param content description // TODO add description + * @return JsonResponse + * @throws IOException description // TODO add description */ public JsonResponse pushContent(Content content) throws IOException { return apiPost(content); @@ -315,8 +331,9 @@ public JsonResponse pushContent(Content content) throws IOException { /** * Push an event to Sailthru, triggering any applicable triggers. - * @param event - * @throws IOException + * @param event description // TODO add description + * @return JsonResponse + * @throws IOException description // TODO add description */ public JsonResponse pushEvent(Event event) throws IOException { return apiPost(event); @@ -324,9 +341,9 @@ public JsonResponse pushEvent(Event event) throws IOException { /** * Retrieve a user's alert settings - * @param email + * @param email description // TODO add description * @return JsonResponse - * @throws IOException + * @throws IOException description // TODO add description */ public JsonResponse getAlert(String email) throws IOException { Map data = new HashMap(); @@ -336,9 +353,9 @@ public JsonResponse getAlert(String email) throws IOException { /** * Add a new alert to a user. You can add either a realtime or a summary alert (daily/weekly). - * @param alert + * @param alert description // TODO add description * @return JsonResponse - * @throws IOException + * @throws IOException description // TODO add description */ public JsonResponse saveAlert(Alert alert) throws IOException { return apiPost(alert); @@ -348,7 +365,8 @@ public JsonResponse saveAlert(Alert alert) throws IOException { * Delete existing user alert * @param email User.java Email * @param alertId Alert ID - * @throws IOException + * @return JsonResponse + * @throws IOException description // TODO add description */ public JsonResponse deleteAlert(String email, String alertId) throws IOException { Map data = new HashMap(); @@ -359,8 +377,9 @@ public JsonResponse deleteAlert(String email, String alertId) throws IOException /** * Record that a user has made a purchase, or has added items to their purchase total - * @param purchase - * @throws IOException + * @param purchase description // TODO add description + * @return JsonResponse + * @throws IOException description // TODO add description */ public JsonResponse purchase(Purchase purchase) throws IOException { return apiPost(purchase); @@ -368,8 +387,9 @@ public JsonResponse purchase(Purchase purchase) throws IOException { /** * Make stats API request - * @param stats - * @throws IOException + * @param stats description // TODO add description + * @return JsonResponse + * @throws IOException description // TODO add description */ protected JsonResponse stats(Stats stats) throws IOException { return apiGet(stats); @@ -377,30 +397,30 @@ protected JsonResponse stats(Stats stats) throws IOException { /** * get list stats information - * @param stat + * @param stat description // TODO add description * @return JsonResponse - * @throws IOException + * @throws IOException description // TODO add description */ - public Map listStats(ListStat stat) throws IOException { - return (Map)this.stats(stat); + public JsonResponse listStats(ListStat stat) throws IOException { + return this.stats(stat); } /** * get blast stats information - * @param stat + * @param stat description // TODO add description * @return JsonResponse - * @throws IOException + * @throws IOException description // TODO add description */ - public Map blastStats(BlastStat stat) throws IOException { - return (Map)this.stats(stat); + public JsonResponse blastStats(BlastStat stat) throws IOException { + return this.stats(stat); } /** * Get status of a job - * @param jobId + * @param jobId description // TODO add description * @return JsonResponse - * @throws IOException + * @throws IOException description // TODO add description */ public JsonResponse getJobStatus(String jobId) throws IOException { Map params = new HashMap(); @@ -411,8 +431,9 @@ public JsonResponse getJobStatus(String jobId) throws IOException { /** * Process import job from given email string CSV or file path of a CSV or email per line file - * @param job - * @throws IOException + * @param job description // TODO add description + * @return JsonResponse + * @throws IOException description // TODO add description */ public JsonResponse processImportJob(ImportJob job) throws IOException { return apiPost(job, job); @@ -422,7 +443,8 @@ public JsonResponse processImportJob(ImportJob job) throws IOException { /** * 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 + * @return JsonResponse + * @throws IOException description // TODO add description */ public JsonResponse processSnapshotJob(SnapshotJob job) throws IOException { return apiPost(job); @@ -432,7 +454,8 @@ public JsonResponse processSnapshotJob(SnapshotJob job) throws IOException { /** * Export blast data in CSV format * @param job BlastQueryJob - * @throws IOException + * @return JsonResponse + * @throws IOException description // TODO add description */ public JsonResponse processBlastQueryJob(BlastQueryJob job) throws IOException { return apiPost(job); @@ -442,7 +465,8 @@ public JsonResponse processBlastQueryJob(BlastQueryJob job) throws IOException { /** * Export user data from a list in CSV format * @param job ExportListDataJob - * @throws IOException + * @return JsonResponse + * @throws IOException description // TODO add description */ public JsonResponse processExportListDataJob(ExportListDataJob job) throws IOException { return apiPost(job); @@ -452,16 +476,27 @@ public JsonResponse processExportListDataJob(ExportListDataJob job) throws IOExc /** * Perform a bulk update of any number of user profiles * @param job UpdateJob - * @throws IOException + * @return JsonResponse + * @throws IOException description // TODO add description */ public JsonResponse processUpdateJob(UpdateJob job) throws IOException { return apiPost(job, job); } + /** + * @param user User + * @return JsonResponse + * @throws IOException description // TODO add description + */ public JsonResponse getUser(User user) throws IOException { return apiGet(user); } + /** + * @param user User + * @return JsonResponse + * @throws IOException description // TODO add description + */ public JsonResponse saveUser(User user) throws IOException { return apiPost(user); } diff --git a/src/main/com/sailthru/client/SailthruHttpClientConfiguration.java b/src/main/com/sailthru/client/SailthruHttpClientConfiguration.java index 9c7dd23..ace34d0 100644 --- a/src/main/com/sailthru/client/SailthruHttpClientConfiguration.java +++ b/src/main/com/sailthru/client/SailthruHttpClientConfiguration.java @@ -6,25 +6,25 @@ public interface SailthruHttpClientConfiguration { /** * get connection timeout in milli seconds - * @return + * @return int */ int getConnectionTimeout(); /** * get socket timeout in milli seconds - * @return + * @return int */ int getSoTimeout(); /** * get socket reuse address boolean flag - * @return + * @return boolean */ boolean getSoReuseaddr(); /** * get tcp no delay boolean flag - * @return + * @return boolean */ boolean getTcpNoDelay(); } diff --git a/src/main/com/sailthru/client/SailthruUtil.java b/src/main/com/sailthru/client/SailthruUtil.java index db91395..abe98ff 100644 --- a/src/main/com/sailthru/client/SailthruUtil.java +++ b/src/main/com/sailthru/client/SailthruUtil.java @@ -3,14 +3,14 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; import org.apache.commons.codec.digest.DigestUtils; + import java.io.UnsupportedEncodingException; -import java.util.HashMap; import java.util.List; import java.util.Map; /** * few static utility methods - * @author Prajwal Tuladhar + * @author Prajwal Tuladhar praj@sailthru.com */ public class SailthruUtil { diff --git a/src/main/com/sailthru/client/exceptions/ApiException.java b/src/main/com/sailthru/client/exceptions/ApiException.java index 9470af7..679f4a1 100644 --- a/src/main/com/sailthru/client/exceptions/ApiException.java +++ b/src/main/com/sailthru/client/exceptions/ApiException.java @@ -1,16 +1,16 @@ package com.sailthru.client.exceptions; -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; - import org.apache.http.StatusLine; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + /** * Handle API related Exceptions - * @author Prajwal Tuladhar + * @author Prajwal Tuladhar praj@sailthru.com */ @SuppressWarnings("serial") public class ApiException extends IOException { diff --git a/src/main/com/sailthru/client/exceptions/ResourceNotFoundException.java b/src/main/com/sailthru/client/exceptions/ResourceNotFoundException.java index bf63c17..484df99 100644 --- a/src/main/com/sailthru/client/exceptions/ResourceNotFoundException.java +++ b/src/main/com/sailthru/client/exceptions/ResourceNotFoundException.java @@ -4,7 +4,7 @@ /** * - * @author Prajwal Tuladhar + * @author Prajwal Tuladhar praj@sailthru.com */ public class ResourceNotFoundException extends ApiException { public ResourceNotFoundException(int statusCode, String reason, diff --git a/src/main/com/sailthru/client/exceptions/UnAuthorizedException.java b/src/main/com/sailthru/client/exceptions/UnAuthorizedException.java index ed93756..7389d24 100644 --- a/src/main/com/sailthru/client/exceptions/UnAuthorizedException.java +++ b/src/main/com/sailthru/client/exceptions/UnAuthorizedException.java @@ -4,7 +4,7 @@ /** * - * @author Prajwal Tuladhar + * @author Prajwal Tuladhar praj@sailthru.com */ public class UnAuthorizedException extends ApiException { public UnAuthorizedException(int statusCode, String reason, Map jsonResponse) { diff --git a/src/main/com/sailthru/client/handler/JsonHandler.java b/src/main/com/sailthru/client/handler/JsonHandler.java index 48aa749..bb72601 100644 --- a/src/main/com/sailthru/client/handler/JsonHandler.java +++ b/src/main/com/sailthru/client/handler/JsonHandler.java @@ -18,7 +18,7 @@ /** * handles JSON response from server * - * @author Prajwal Tuladhar + * @author Prajwal Tuladhar praj@sailthru.com */ public class JsonHandler implements SailthruResponseHandler { diff --git a/src/main/com/sailthru/client/handler/SailthruResponseHandler.java b/src/main/com/sailthru/client/handler/SailthruResponseHandler.java index 7e6328f..80fe35c 100644 --- a/src/main/com/sailthru/client/handler/SailthruResponseHandler.java +++ b/src/main/com/sailthru/client/handler/SailthruResponseHandler.java @@ -2,9 +2,9 @@ /** * Interface for Handling Server Response - * @author Prajwal Tuladhar + * @author Prajwal Tuladhar praj@sailthru.com */ public interface SailthruResponseHandler { public Object parseResponse (String response); public String getFormat(); -} \ No newline at end of file +} diff --git a/src/main/com/sailthru/client/handler/response/JsonResponse.java b/src/main/com/sailthru/client/handler/response/JsonResponse.java index 7d24c5e..57dedd0 100644 --- a/src/main/com/sailthru/client/handler/response/JsonResponse.java +++ b/src/main/com/sailthru/client/handler/response/JsonResponse.java @@ -1,13 +1,14 @@ package com.sailthru.client.handler.response; -import java.util.Map; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.Map; + /** * - * @author Prajwal Tuladhar + * @author Prajwal Tuladhar praj@sailthru.com */ public class JsonResponse implements Response { diff --git a/src/main/com/sailthru/client/handler/response/Response.java b/src/main/com/sailthru/client/handler/response/Response.java index 790097d..68fd512 100644 --- a/src/main/com/sailthru/client/handler/response/Response.java +++ b/src/main/com/sailthru/client/handler/response/Response.java @@ -4,7 +4,7 @@ /** * - * @author Prajwal Tuladhar + * @author Prajwal Tuladhar praj@sailthru.com */ public interface Response { public boolean isOK(); diff --git a/src/main/com/sailthru/client/http/SailthruHandler.java b/src/main/com/sailthru/client/http/SailthruHandler.java index 9b34a72..fc2290f 100644 --- a/src/main/com/sailthru/client/http/SailthruHandler.java +++ b/src/main/com/sailthru/client/http/SailthruHandler.java @@ -4,7 +4,6 @@ import com.sailthru.client.exceptions.ResourceNotFoundException; import com.sailthru.client.exceptions.UnAuthorizedException; import com.sailthru.client.handler.SailthruResponseHandler; -import java.io.IOException; import org.apache.http.HttpResponse; import org.apache.http.StatusLine; import org.apache.http.client.ClientProtocolException; @@ -13,9 +12,11 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.io.IOException; + /** * - * @author Prajwal Tuladhar + * @author Prajwal Tuladhar praj@sailthru.com */ public class SailthruHandler implements ResponseHandler { diff --git a/src/main/com/sailthru/client/http/SailthruHttpClient.java b/src/main/com/sailthru/client/http/SailthruHttpClient.java index 01520fc..f0577f5 100644 --- a/src/main/com/sailthru/client/http/SailthruHttpClient.java +++ b/src/main/com/sailthru/client/http/SailthruHttpClient.java @@ -28,7 +28,7 @@ /** * - * @author Prajwal Tuladhar + * @author Prajwal Tuladhar praj@sailthru.com */ public class SailthruHttpClient extends DefaultHttpClient { diff --git a/src/main/com/sailthru/client/params/AbstractApiParams.java b/src/main/com/sailthru/client/params/AbstractApiParams.java index e8d5bf5..bee7a61 100644 --- a/src/main/com/sailthru/client/params/AbstractApiParams.java +++ b/src/main/com/sailthru/client/params/AbstractApiParams.java @@ -3,12 +3,12 @@ import com.google.gson.Gson; import com.sailthru.client.SailthruUtil; import com.sailthru.client.handler.JsonHandler; -import java.util.HashMap; + import java.util.Map; /** * - * @author Prajwal Tuladhar + * @author Prajwal Tuladhar praj@sailthru.com */ public abstract class AbstractApiParams { public Map toHashMap() { diff --git a/src/main/com/sailthru/client/params/Alert.java b/src/main/com/sailthru/client/params/Alert.java index 338045f..8606678 100644 --- a/src/main/com/sailthru/client/params/Alert.java +++ b/src/main/com/sailthru/client/params/Alert.java @@ -8,16 +8,17 @@ /** * - * @author Prajwal Tuladhar + * @author Prajwal Tuladhar praj@sailthru.com */ public class Alert extends AbstractApiParams implements ApiParams { public static final String PARAM_EMAIL = "email"; public static final String PARAM_ALERT_ID = "alert_id"; + protected static final Type _type = new TypeToken() {}.getType(); protected String email; - public static enum TypeMode {realtime, daily, weekly}; + public enum TypeMode {realtime, daily, weekly}; protected String type; protected String template; protected String when; @@ -68,8 +69,7 @@ public Alert setWhen(String when) { } public Type getType() { - java.lang.reflect.Type _type = new TypeToken() {}.getType(); - return _type; + return Alert._type; } @Override @@ -77,4 +77,4 @@ public ApiAction getApiCall() { return ApiAction.alert; } -} \ No newline at end of file +} diff --git a/src/main/com/sailthru/client/params/ApiFileParams.java b/src/main/com/sailthru/client/params/ApiFileParams.java index 95fd4d4..6df72e9 100644 --- a/src/main/com/sailthru/client/params/ApiFileParams.java +++ b/src/main/com/sailthru/client/params/ApiFileParams.java @@ -5,7 +5,7 @@ /** * -* @author Prajwal Tuladhar + * @author Prajwal Tuladhar praj@sailthru.com */ public interface ApiFileParams { public Map getFileParams(); diff --git a/src/main/com/sailthru/client/params/ApiParams.java b/src/main/com/sailthru/client/params/ApiParams.java index 7b4051a..5c4379f 100644 --- a/src/main/com/sailthru/client/params/ApiParams.java +++ b/src/main/com/sailthru/client/params/ApiParams.java @@ -1,11 +1,12 @@ package com.sailthru.client.params; -import java.lang.reflect.Type; import com.sailthru.client.ApiAction; +import java.lang.reflect.Type; + /** * - * @author Prajwal Tuladhar + * @author Prajwal Tuladhar praj@sailthru.com */ public interface ApiParams { public Type getType(); diff --git a/src/main/com/sailthru/client/params/Blast.java b/src/main/com/sailthru/client/params/Blast.java index 5a97bd6..a87e2c6 100644 --- a/src/main/com/sailthru/client/params/Blast.java +++ b/src/main/com/sailthru/client/params/Blast.java @@ -2,15 +2,15 @@ import com.google.gson.reflect.TypeToken; import com.sailthru.client.ApiAction; + import java.lang.reflect.Type; import java.net.URI; import java.util.Date; -import java.util.HashMap; import java.util.Map; /** * - * @author Prajwal Tuladhar + * @author Prajwal Tuladhar praj@sailthru.com */ public class Blast extends AbstractApiParams implements ApiParams { @@ -41,6 +41,8 @@ public class Blast extends AbstractApiParams implements ApiParams { protected String setup; protected Map vars; + protected static final Type type = new TypeToken() {}.getType(); + public Blast(String name, String list, String scheduleTime, String fromName, String fromEmail, String subject, String contentHtml, String contentText) { this.name = name; this.list = list; @@ -192,9 +194,9 @@ public Blast setVars(Map vars){ return this; } + @Override public Type getType() { - Type type = new TypeToken() {}.getType(); - return type; + return Blast.type; } @Override diff --git a/src/main/com/sailthru/client/params/BlastStat.java b/src/main/com/sailthru/client/params/BlastStat.java index 34dabe7..eda095f 100644 --- a/src/main/com/sailthru/client/params/BlastStat.java +++ b/src/main/com/sailthru/client/params/BlastStat.java @@ -1,12 +1,14 @@ package com.sailthru.client.params; import com.google.gson.reflect.TypeToken; +import com.sailthru.client.ApiAction; + import java.lang.reflect.Type; import java.util.Date; /** * - * @author Prajwal Tuladhar + * @author Prajwal Tuladhar praj@sailthru.com */ public class BlastStat extends Stats { protected Integer blast_id; @@ -22,6 +24,8 @@ public class BlastStat extends Stats { protected Integer subject; protected Integer urls; + protected static final Type type = new TypeToken() {}.getType(); + public BlastStat() { super(MODE_BLAST); } @@ -96,8 +100,13 @@ public BlastStat enableUrls() { return this; } + @Override + public ApiAction getApiCall() { + return ApiAction.blast; + } + + @Override public Type getType() { - Type type = new TypeToken() {}.getType(); - return type; + return BlastStat.type; } } diff --git a/src/main/com/sailthru/client/params/Content.java b/src/main/com/sailthru/client/params/Content.java index bf94069..47d14e7 100644 --- a/src/main/com/sailthru/client/params/Content.java +++ b/src/main/com/sailthru/client/params/Content.java @@ -11,7 +11,7 @@ /** * - * @author Prajwal Tuladhar + * @author Prajwal Tuladhar praj@sailthru.com */ public class Content extends AbstractApiParams implements ApiParams { // required @@ -31,17 +31,9 @@ public class Content extends AbstractApiParams implements ApiParams { protected String author; protected Integer spider; - @Override - public ApiAction getApiCall() { - return ApiAction.content; - } + protected static final Type type = new TypeToken() {}.getType(); - public static enum ContentSpecialVar {PRICE, DESCRIPTION, BRAND}; - - public Type getType() { - Type type = new TypeToken() {}.getType(); - return type; - } + public enum ContentSpecialVar {PRICE, DESCRIPTION, BRAND} public Content setTitle(String title) { this.title = title; @@ -179,4 +171,14 @@ public Content enableSpider() { this.spider = 1; return this; } + + @Override + public ApiAction getApiCall() { + return ApiAction.content; + } + + @Override + public Type getType() { + return Content.type; + } } diff --git a/src/main/com/sailthru/client/params/Email.java b/src/main/com/sailthru/client/params/Email.java index 4dd5852..f5206a1 100644 --- a/src/main/com/sailthru/client/params/Email.java +++ b/src/main/com/sailthru/client/params/Email.java @@ -2,14 +2,14 @@ import com.google.gson.reflect.TypeToken; import com.sailthru.client.ApiAction; + import java.lang.reflect.Type; -import java.util.ArrayList; import java.util.HashMap; import java.util.Map; /** * - * @author Prajwal Tuladhar + * @author Prajwal Tuladhar praj@sailthru.com */ public class Email extends AbstractApiParams implements ApiParams { protected String email; @@ -23,6 +23,8 @@ public class Email extends AbstractApiParams implements ApiParams { protected Map send_vars; protected Map vars; + protected static final Type type = new TypeToken() {}.getType(); + public Email() { this.vars = new HashMap(); this.send_vars = new HashMap(); @@ -97,13 +99,14 @@ public Email setTextOnly() { return this; } - public Type getType() { - Type type = new TypeToken() {}.getType(); - return type; - } - @Override public ApiAction getApiCall() { return ApiAction.email; } + + @Override + public Type getType() { + return Email.type; + } + } diff --git a/src/main/com/sailthru/client/params/Event.java b/src/main/com/sailthru/client/params/Event.java index 4519018..ceb04e9 100644 --- a/src/main/com/sailthru/client/params/Event.java +++ b/src/main/com/sailthru/client/params/Event.java @@ -7,7 +7,7 @@ /** * Event params - * @author Ben Bartholomew + * @author Ben Bartholomew bbartholomew@sailthru.com */ public class Event extends AbstractApiParams implements ApiParams { protected String id; @@ -15,6 +15,8 @@ public class Event extends AbstractApiParams implements ApiParams { protected Map vars; protected String event; protected String schedule_time; + + protected static final Type type = new TypeToken() {}.getType(); public Event(String id) { this.id = id; @@ -44,12 +46,14 @@ public Event setScheduleTime(String scheduleTime) { return this; } - public Type getType() { - java.lang.reflect.Type _type = new TypeToken() {}.getType(); - return _type; - } - + @Override public ApiAction getApiCall() { return ApiAction.event; } + + @Override + public Type getType() { + return Event.type; + } + } diff --git a/src/main/com/sailthru/client/params/List.java b/src/main/com/sailthru/client/params/List.java index 0afc6b1..6231f8b 100644 --- a/src/main/com/sailthru/client/params/List.java +++ b/src/main/com/sailthru/client/params/List.java @@ -1,21 +1,22 @@ package com.sailthru.client.params; -import com.sailthru.client.ApiAction; 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 + * @author Prajwal Tuladhar praj@sailthru.com */ public class List extends AbstractApiParams implements ApiParams { protected String list; protected Integer primary; protected ListType type; protected Query query; + + protected static final Type _type = new TypeToken() {}.getType(); public List setQuery(Query query) { this.query = query; @@ -37,12 +38,14 @@ public List setListType(ListType listType) { return this; } + @Override public ApiAction getApiCall() { return ApiAction.list; } + @Override public Type getType() { - return new TypeToken() {}.getType(); + return List._type; } public enum ListType { diff --git a/src/main/com/sailthru/client/params/ListStat.java b/src/main/com/sailthru/client/params/ListStat.java index 2bcedc4..cf927e1 100644 --- a/src/main/com/sailthru/client/params/ListStat.java +++ b/src/main/com/sailthru/client/params/ListStat.java @@ -1,17 +1,21 @@ package com.sailthru.client.params; import com.google.gson.reflect.TypeToken; +import com.sailthru.client.ApiAction; + import java.lang.reflect.Type; import java.util.Date; /** * - * @author Prajwal Tuladhar + * @author Prajwal Tuladhar praj@sailthru.com */ public class ListStat extends Stats { protected String list; protected String date; + protected static final Type type = new TypeToken() {}.getType(); + public ListStat() { super(MODE_LIST); } @@ -31,8 +35,13 @@ public ListStat setDate(String date) { return this; } + @Override + public ApiAction getApiCall() { + return ApiAction.list; + } + + @Override public Type getType() { - Type type = new TypeToken() {}.getType(); - return type; + return ListStat.type; } } diff --git a/src/main/com/sailthru/client/params/MultiSend.java b/src/main/com/sailthru/client/params/MultiSend.java index eef5df0..1d62154 100644 --- a/src/main/com/sailthru/client/params/MultiSend.java +++ b/src/main/com/sailthru/client/params/MultiSend.java @@ -2,18 +2,19 @@ import com.google.gson.reflect.TypeToken; import com.sailthru.client.SailthruUtil; + import java.lang.reflect.Type; -import java.util.ArrayList; import java.util.HashMap; import java.util.Map; /** * - * @author Prajwal Tuladhar + * @author Prajwal Tuladhar praj@sailthru.com */ public class MultiSend extends Send { protected Map evars; + protected static final Type type = new TypeToken() {}.getType(); public MultiSend() { this.options = new HashMap(); @@ -31,7 +32,6 @@ public MultiSend setEvars(Map evars) { @Override public Type getType() { - Type type = new TypeToken() {}.getType(); - return type; + return MultiSend.type; } } diff --git a/src/main/com/sailthru/client/params/Purchase.java b/src/main/com/sailthru/client/params/Purchase.java index 7765a39..19756a9 100644 --- a/src/main/com/sailthru/client/params/Purchase.java +++ b/src/main/com/sailthru/client/params/Purchase.java @@ -12,12 +12,13 @@ /** * - * @author Prajwal Tuladhar + * @author Prajwal Tuladhar praj@sailthru.com */ public class Purchase extends AbstractApiParams implements ApiParams { protected String email; protected List> items; protected Integer incomplete; + protected static final Type type = new TypeToken() {}.getType(); @SerializedName("message_id") protected String messageId; @@ -105,13 +106,14 @@ public Purchase setPurchaseLevelVars(Map vars) { return this; } - public Type getType() { - Type type = new TypeToken() {}.getType(); - return type; - } - @Override public ApiAction getApiCall() { return ApiAction.purchase; } + + @Override + public Type getType() { + return Purchase.type; + } + } diff --git a/src/main/com/sailthru/client/params/PurchaseItem.java b/src/main/com/sailthru/client/params/PurchaseItem.java index 5ed5a40..913c597 100644 --- a/src/main/com/sailthru/client/params/PurchaseItem.java +++ b/src/main/com/sailthru/client/params/PurchaseItem.java @@ -9,7 +9,7 @@ /** * - * @author Prajwal Tuladhar + * @author Prajwal Tuladhar praj@sailthru.com */ public class PurchaseItem { protected String qty; diff --git a/src/main/com/sailthru/client/params/Send.java b/src/main/com/sailthru/client/params/Send.java index 9d3e095..53bf76f 100644 --- a/src/main/com/sailthru/client/params/Send.java +++ b/src/main/com/sailthru/client/params/Send.java @@ -9,7 +9,7 @@ /** * - * @author Prajwal Tuladhar + * @author Prajwal Tuladhar praj@sailthru.com */ public class Send extends AbstractApiParams implements ApiParams { @@ -23,6 +23,8 @@ public class Send extends AbstractApiParams implements ApiParams { protected Map options; protected Map limit; + protected static final Type type = new TypeToken() {}.getType(); + public Send() { this.options = new HashMap(); } @@ -122,12 +124,7 @@ public Send setScheduleTime(Object startTime, Object endTime) { return this; } - public Type getType() { - Type type = new TypeToken() {}.getType(); - return type; - } - - public Send setBehalfEmail(String email) { + public Send setBehalfEmail(String email) { this.options.put("behalf_email", email); return this; } @@ -137,6 +134,11 @@ public Send setOptions(Map options) { return this; } + @Override + public Type getType() { + return Send.type; + } + @Override public ApiAction getApiCall() { return ApiAction.send; diff --git a/src/main/com/sailthru/client/params/Stats.java b/src/main/com/sailthru/client/params/Stats.java index d6d7269..0cb6847 100644 --- a/src/main/com/sailthru/client/params/Stats.java +++ b/src/main/com/sailthru/client/params/Stats.java @@ -4,7 +4,7 @@ /** * - * @author Prajwal Tuladhar + * @author Prajwal Tuladhar praj@sailthru.com */ public abstract class Stats implements ApiParams { protected String stat; @@ -16,7 +16,5 @@ public Stats(String stat) { this.stat = stat; } - public ApiAction getApiCall() { - return ApiAction.blast; - } + public abstract ApiAction getApiCall(); } diff --git a/src/main/com/sailthru/client/params/Template.java b/src/main/com/sailthru/client/params/Template.java index 3abe80d..3c3b687 100644 --- a/src/main/com/sailthru/client/params/Template.java +++ b/src/main/com/sailthru/client/params/Template.java @@ -2,13 +2,13 @@ import com.google.gson.reflect.TypeToken; import com.sailthru.client.ApiAction; + import java.lang.reflect.Type; -import java.util.HashMap; import java.util.Map; /** * - * @author Prajwal Tuladhar + * @author Prajwal Tuladhar praj@sailthru.com */ public class Template extends AbstractApiParams implements ApiParams { @@ -27,6 +27,8 @@ public class Template extends AbstractApiParams implements ApiParams { protected String verify_post_url; protected Map link_params; + protected static final Type type = new TypeToken