Skip to content
This repository has been archived by the owner on Dec 16, 2021. It is now read-only.

Commit

Permalink
Updated queries to use the new QueryDate to assure correct date formats
Browse files Browse the repository at this point in the history
  • Loading branch information
Gyuri Grell committed Jan 12, 2017
1 parent df327ed commit 8bb27a9
Show file tree
Hide file tree
Showing 12 changed files with 202 additions and 106 deletions.
29 changes: 29 additions & 0 deletions components/src/main/java/com/constantcontact/v2/QueryDate.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.constantcontact.v2;

import java.util.Date;

import static com.constantcontact.v2.converter.jackson.JacksonConverterFactory.ISO_8601_DATE_FORMAT;

/**
* A date wrapper to Constant Contact API specific ISO-8601 date format for query parameters.
*/
public class QueryDate {
private final Date date;

public QueryDate() {
date = new Date();
}

public QueryDate(long dateInMilliseconds) {
date = new Date(dateInMilliseconds);
}

public QueryDate(Date date) {
this.date = date;
}

@Override
public String toString() {
return ISO_8601_DATE_FORMAT.format(date);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
* The converter factory used for Jackson JSON conversion
*/
public class JacksonConverterFactory extends Converter.Factory {
private final static String DATE_FORMAT = "yyyy-MM-dd'T'hh:mm:ss.ss'Z'";
public final static String ISO_8601_DATE_PATTERN = "yyyy-MM-dd'T'hh:mm:ss.ss'Z'";

public final static SimpleDateFormat ISO_8601_DATE_FORMAT = new SimpleDateFormat(ISO_8601_DATE_PATTERN);

private static String[] CAMPAIGN_CREATE_UPDATE_FIELDS = {
"name",
Expand Down Expand Up @@ -66,7 +68,7 @@ private JacksonConverterFactory(ObjectMapper mapper) {
}
this.mapper = mapper;
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS).disable(SerializationFeature.WRITE_DATE_KEYS_AS_TIMESTAMPS);
mapper.getSerializationConfig().with(new SimpleDateFormat(DATE_FORMAT));
mapper.getSerializationConfig().with(ISO_8601_DATE_FORMAT);

final SimpleBeanPropertyFilter campaignCreateUpdateFilter = SimpleBeanPropertyFilter.filterOutAllExcept(CAMPAIGN_CREATE_UPDATE_FIELDS);
this.writerFilterProvider = new SimpleFilterProvider().addFilter("CampaignCreateUpdateFilter", campaignCreateUpdateFilter);
Expand Down
6 changes: 0 additions & 6 deletions lib-rx/src/main/java/com/constantcontact/v2/CCApi2.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@
/**
*/
public class CCApi2 {
/**
* Deprecated. The correct formatting of a Date using SimpleDateFormat
*/
@Deprecated
public final static String DATE_FORMAT = "yyyy-MM-dd'T'hh:mm:ss.ss'Z'";

/**
* Deprecated. Please use {@link DefaultOkHttpClientBuilderFactory} instead.
*/
Expand Down
12 changes: 11 additions & 1 deletion lib-rx/src/main/java/com/constantcontact/v2/CampaignService.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@
*
*/
public interface CampaignService {
/**
* The maximum page size for tracking queries.
*/
int MAX_PAGE_LIMIT = 50;

/**
* The default page size for tracking queries.
*/
int DEFAULT_PAGE_LIMIT = 50;

/**
* Get a {@link Campaign}
*
Expand Down Expand Up @@ -44,7 +54,7 @@ public interface CampaignService {
* @return an Observable that emits Paged Campaigns
*/
@GET("v2/emailmarketing/campaigns")
Observable<Paged<Campaign>> getCampaigns(@Query("limit") int limit, @Query("modified_since") String date,
Observable<Paged<Campaign>> getCampaigns(@Query("limit") int limit, @Query("modified_since") QueryDate date,
@Query("status") CampaignStatus status);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@
*
*/
public interface CampaignTrackingService {
/**
* The maximum page size for tracking queries.
*/
int MAX_PAGE_LIMIT = 500;

/**
* The default page size for tracking queries.
*/
int DEFAULT_PAGE_LIMIT = 500;

/**
* Get the {@link TrackingSummary} of a {@link Campaign}
*
Expand All @@ -34,7 +44,7 @@ public interface CampaignTrackingService {
* @return an Observable that emits Paged BounceReports
*/
@GET("v2/emailmarketing/campaigns/{campaignId}/tracking/bounces")
Observable<Paged<BounceReport>> getBounceReports(@Path("campaignId") String campaignId, @Query("created_since") String createdSinceDate,
Observable<Paged<BounceReport>> getBounceReports(@Path("campaignId") String campaignId, @Query("created_since") QueryDate createdSinceDate,
@Query("limit") int limit);

/**
Expand All @@ -57,7 +67,7 @@ Observable<Paged<BounceReport>> getBounceReports(@Path("campaignId") String camp
* @return an Observable that emits Paged ClickReports
*/
@GET("v2/emailmarketing/campaigns/{campaignId}/tracking/clicks")
Observable<Paged<ClickReport>> getClickReports(@Path("campaignId") String campaignId, @Query("created_since") String createdSinceDate,
Observable<Paged<ClickReport>> getClickReports(@Path("campaignId") String campaignId, @Query("created_since") QueryDate createdSinceDate,
@Query("limit") int limit);

/**
Expand All @@ -72,7 +82,7 @@ Observable<Paged<ClickReport>> getClickReports(@Path("campaignId") String campai
*/
@GET("v2/emailmarketing/campaigns/{campaignId}/tracking/clicks/{linkId}")
Observable<Paged<ClickReport>> getClickReports(@Path("campaignId") String campaignId, @Path("linkId") String linkId,
@Query("created_since") String createdSinceDate, @Query("limit") int limit);
@Query("created_since") QueryDate createdSinceDate, @Query("limit") int limit);

/**
* Get a {@link Paged} collection of {@link ClickReport} from a {@link Campaign} from a previous call's
Expand All @@ -95,7 +105,7 @@ Observable<Paged<ClickReport>> getClickReports(@Path("campaignId") String campai
*/
@GET("v2/emailmarketing/campaigns/{campaignId}/tracking/forwards")
Observable<Paged<ForwardReport>> getForwardReports(@Path("campaignId") String campaignId,
@Query("created_since") String createdSinceDate, @Query("limit") int limit);
@Query("created_since") QueryDate createdSinceDate, @Query("limit") int limit);

/**
* Get a {@link Paged} collection of {@link ForwardReport} from a {@link Campaign} from a previous call's
Expand All @@ -117,7 +127,7 @@ Observable<Paged<ForwardReport>> getForwardReports(@Path("campaignId") String ca
* @return an Observable that emits Paged OpenReports
*/
@GET("v2/emailmarketing/campaigns/{campaignId}/tracking/opens")
Observable<Paged<OpenReport>> getOpenReports(@Path("campaignId") String campaignId, @Query("created_since") String createdSinceDate,
Observable<Paged<OpenReport>> getOpenReports(@Path("campaignId") String campaignId, @Query("created_since") QueryDate createdSinceDate,
@Query("limit") int limit);

/**
Expand All @@ -140,7 +150,7 @@ Observable<Paged<OpenReport>> getOpenReports(@Path("campaignId") String campaign
* @return an Observable that emits Paged SendReports
*/
@GET("v2/emailmarketing/campaigns/{campaignId}/tracking/sends")
Observable<Paged<SendReport>> getSendReports(@Path("campaignId") String campaignId, @Query("created_since") String createdSinceDate,
Observable<Paged<SendReport>> getSendReports(@Path("campaignId") String campaignId, @Query("created_since") QueryDate createdSinceDate,
@Query("limit") int limit);

/**
Expand All @@ -163,7 +173,7 @@ Observable<Paged<SendReport>> getSendReports(@Path("campaignId") String campaign
* @return an Observable that emits Paged OptOutReports
*/
@GET("v2/emailmarketing/campaigns/{campaignId}/tracking/unsubscribes")
Observable<Paged<OptOutReport>> getOptOutReports(@Path("campaignId") String campaignId, @Query("created_since") String createdSinceDate,
Observable<Paged<OptOutReport>> getOptOutReports(@Path("campaignId") String campaignId, @Query("created_since") QueryDate createdSinceDate,
@Query("limit") int limit);

/**
Expand Down
53 changes: 31 additions & 22 deletions lib-rx/src/main/java/com/constantcontact/v2/ContactService.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,23 @@
* <p>
* See <a href="http://developer.constantcontact.com/docs/contacts-api/contacts-index.html">Working With Contacts</a>
* on the Constant Contact Developer Website
*
*/
public interface ContactService {
/**
* The maximum page size for tracking queries.
*/
int MAX_PAGE_LIMIT = 500;

/**
* The default page size for tracking queries.
*/
int DEFAULT_PAGE_LIMIT = 50;

/**
* Get a {@link Paged} collection of {@link Contact}
*
* @param email Email to search for
* @return an Observable that emits Paged Contacts
* @return an Observable that emits Paged Contacts
*/
@GET("v2/contacts")
Observable<Paged<Contact>> getContactsByEmail(@Query("email") String email);
Expand All @@ -29,7 +38,7 @@ public interface ContactService {
*
* @param limit Size of page to return (1-500)
* @param status Retrieve contacts with only the chosen {@link ContactStatus}
* @return an Observable that emits Paged Contacts
* @return an Observable that emits Paged Contacts
*/
@GET("v2/contacts")
Observable<Paged<Contact>> getContacts(@Query("limit") int limit, @Query("status") ContactStatus status);
Expand All @@ -40,10 +49,10 @@ public interface ContactService {
* @param limit Size of page to return (1-500)
* @param date Date to specify retrieval of contacts that have been modified since then, in ISO-8601 format
* @param status Retrieve contacts with only the chosen {@link ContactStatus}
* @return an Observable that emits Paged Contacts
* @return an Observable that emits Paged Contacts
*/
@GET("v2/contacts")
Observable<Paged<Contact>> getContacts(@Query("limit") int limit, @Query("modified_since") String date,
Observable<Paged<Contact>> getContacts(@Query("limit") int limit, @Query("modified_since") QueryDate date,
@Query("status") ContactStatus status);

/**
Expand All @@ -52,18 +61,18 @@ Observable<Paged<Contact>> getContacts(@Query("limit") int limit, @Query("modifi
* @param listId ID of the ContactList to get Contacts from
* @param limit Size of page to return (1-500)
* @param date Date to specify retrieval of contacts that have been modified since then, in ISO-8601 format
* @return an Observable that emits Paged Contacts
* @return an Observable that emits Paged Contacts
*/
@GET("v2/lists/{listId}/contacts")
Observable<Paged<Contact>> getContacts(@Path("listId") String listId, @Query("limit") int limit, @Query("modified_since") String date);
Observable<Paged<Contact>> getContacts(@Path("listId") String listId, @Query("limit") int limit, @Query("modified_since") QueryDate date);

/**
* Get a {@link Paged} collection of {@link Contact} from a previous call's
* next link.
*
* @param nextLink Value of the path found in the meta of the original call
* @return an Observable that emits Paged Contacts
* @see Paged
* @return an Observable that emits Paged Contacts
* @see Paged
*/
@GET
Observable<Paged<Contact>> getContacts(@Url String nextLink);
Expand All @@ -73,7 +82,7 @@ Observable<Paged<Contact>> getContacts(@Query("limit") int limit, @Query("modifi
*
* @param contact Contact
* @param optInSource Specify who is creating this contact with {@link OptInSource}
* @return an Observable that emits a new Contact object, with changes by the server, such as adding an ID
* @return an Observable that emits a new Contact object, with changes by the server, such as adding an ID
*/
@POST("v2/contacts")
Observable<Contact> createContact(@Body Contact contact, @Query("action_by") OptInSource optInSource);
Expand All @@ -82,7 +91,7 @@ Observable<Paged<Contact>> getContacts(@Query("limit") int limit, @Query("modifi
* Get an individual {@link Contact}
*
* @param contactId Contact's ID
* @return an Observable that emits a Contact
* @return an Observable that emits a Contact
*/
@GET("v2/contacts/{contactId}")
Observable<Contact> getContact(@Path("contactId") String contactId);
Expand All @@ -93,7 +102,7 @@ Observable<Paged<Contact>> getContacts(@Query("limit") int limit, @Query("modifi
* @param contact Contact object with updated information
* @param contactId Contact's ID
* @param optInSource Specify who is updating this contact with {@link OptInSource}
* @return an Observable that emits an updated Contact
* @return an Observable that emits an updated Contact
*/
@PUT("v2/contacts/{contactId}")
Observable<Contact> updateContact(@Body Contact contact, @Path("contactId") String contactId,
Expand All @@ -103,25 +112,25 @@ Observable<Contact> updateContact(@Body Contact contact, @Path("contactId") Stri
* Opt out an individual {@link Contact}
*
* @param contactId Contact's ID
* @return an Observable that emits a {@link retrofit2.Response}
* @return an Observable that emits a {@link retrofit2.Response}
*/
@DELETE("v2/contacts/{contactId}")
Observable<Response<Void>> unsubscribeContact(@Path("contactId") String contactId);

/**
* Get all {@link ContactList} in the account
*
* @param date Date to specify retrieval of contact lists that have been modified since then, in ISO-8601 format
* @return an Observable that emits a List of ContactLists
* @param modifiedSince optional date to specify latest modified lists, or null for all lists
* @return an Observable that emits a list of contact lists
*/
@GET("v2/lists")
Observable<List<ContactList>> getContactLists(@Query("modified_since") String date);
Observable<List<ContactList>> getContactLists(@Query("modified_since") QueryDate modifiedSince);

/**
* Create a new {@link ContactList}
*
* @param contactList ContactList object (requires only name and status to create)
* @return an Observable that emits a new ContactList object, with changes by the server, such as adding an ID
* @return an Observable that emits a new ContactList object, with changes by the server, such as adding an ID
*/
@POST("v2/lists")
Observable<ContactList> createContactList(@Body ContactList contactList);
Expand All @@ -130,7 +139,7 @@ Observable<Contact> updateContact(@Body Contact contact, @Path("contactId") Stri
* Get a specific {@link ContactList}
*
* @param listId ID of the list
* @return an Observable that emits a ContactList
* @return an Observable that emits a ContactList
*/
@GET("v2/lists/{listId}")
Observable<ContactList> getContactList(@Path("listId") String listId);
Expand All @@ -140,7 +149,7 @@ Observable<Contact> updateContact(@Body Contact contact, @Path("contactId") Stri
*
* @param contactList ContactList
* @param listId ID of the list
* @return an Observable that emits an updated ContactList
* @return an Observable that emits an updated ContactList
*/
@PUT("v2/lists/{listId}")
Observable<ContactList> updateContactList(@Body ContactList contactList, @Path("listId") String listId);
Expand All @@ -149,7 +158,7 @@ Observable<Contact> updateContact(@Body Contact contact, @Path("contactId") Stri
* Delete a {@link ContactList}
*
* @param listId ID of the list
* @return an Observable that emits a {@link retrofit2.Response}
* @return an Observable that emits a {@link retrofit2.Response}
*/
@DELETE("v2/lists/{listId}")
Observable<Response<Void>> deleteContactList(@Path("listId") String listId);
Expand All @@ -158,8 +167,8 @@ Observable<Contact> updateContact(@Body Contact contact, @Path("contactId") Stri
* Create a custom signup form
*
* @param signupFormRequest object that contains params for the signup form
* @return an Observable that emits a signup form response
* @see <a href="http://developer.constantcontact.com/docs/signup-forms-tools/signup-form-creation.html">Signup Form Creation</a>
* @return an Observable that emits a signup form response
* @see <a href="http://developer.constantcontact.com/docs/signup-forms-tools/signup-form-creation.html">Signup Form Creation</a>
*/
@POST("v2/signupform")
Observable<SignupFormResponse> createCustomSignupForm(@Body SignupFormRequest signupFormRequest);
Expand Down
Loading

0 comments on commit 8bb27a9

Please sign in to comment.