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

Commit

Permalink
Merge pull request #84 from constantcontact/refactor-and-fix
Browse files Browse the repository at this point in the history
Refactor and fix
  • Loading branch information
ggrell authored Jan 12, 2017
2 parents cf240ae + 8bb27a9 commit d7fdfd6
Show file tree
Hide file tree
Showing 101 changed files with 552 additions and 315 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ allprojects {
apply plugin: 'java'

dependencies {
compile 'javax.inject:javax.inject:1'
compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile 'com.squareup.retrofit2:converter-jackson:2.1.0'
compile 'com.squareup.okhttp3:logging-interceptor:3.4.1'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public Response intercept(Chain chain) throws IOException {
.addHeader("Authorization", "Bearer " + _token)
.addHeader("Content-Type", "application/json")
.addHeader("User-Agent",
"Constant Contact Java Library v5.1.1") // TODO: Add version # dynamically
"Constant Contact Java Library v5.1.6") // TODO: Add version # dynamically
.build();
return chain.proceed(newRequest);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.constantcontact.v2;

import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;

import javax.inject.Inject;
import java.util.concurrent.TimeUnit;

/**
*/
public class DefaultOkHttpClientBuilderFactory {

@Inject
public DefaultOkHttpClientBuilderFactory() {
}

public OkHttpClient.Builder create(String apiKey, String token) {
return create(apiKey, token, HttpLoggingInterceptor.Level.NONE);
}

public OkHttpClient.Builder create(String apiKey, String token, HttpLoggingInterceptor.Level loggingLevel) {
OkHttpClient.Builder
builder =
new OkHttpClient().newBuilder()
.readTimeout(10, TimeUnit.SECONDS)
.connectTimeout(5, TimeUnit.SECONDS)
.addInterceptor(new CCApiInterceptor(apiKey, token));

if (loggingLevel != HttpLoggingInterceptor.Level.NONE) {
HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
interceptor.setLevel(loggingLevel);
builder.addInterceptor(interceptor);
}

return builder;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package com.constantcontact.v2;

import com.constantcontact.v2.converter.jackson.JacksonConverterFactory;
import com.fasterxml.jackson.databind.ObjectMapper;
import okhttp3.OkHttpClient;
import retrofit2.Retrofit;

import javax.inject.Inject;
import javax.inject.Named;

/**
* A factory for creating the default {@link Retrofit.Builder}.
* <p>
* NOTE: Can be used with dependency injection since the constructor
* is marked with {@code @Inject}, and requires a {@link OkHttpClient} dependency named "ccapi2". If you aren't using DI
* then the annotations will not affect you.
*/
public class DefaultRetrofitBuilderFactory {
public static final String BASE_URL = "https://api.constantcontact.com/";

private final OkHttpClient _okHttpClient;

/**
* Creates an instance of the factory.
*
* @param client the client used to initialize the created builder
*/
@Inject
public DefaultRetrofitBuilderFactory(@Named("ccapi2") OkHttpClient client) {
_okHttpClient = client;
}

/**
* Creates a new builder instance with the default base url. Initialized with a default Jackson JSON converter.
*
* @return a builder instance initialized for use with service classes
*/
public Retrofit.Builder create() {
return create(BASE_URL);
}

/**
* Creates a new builder instance with the provided base url. Initialized with a default Jackson JSON converter.
*
* @param baseUrl the base url
* @return a builder instance initialized for use with service classes
*/
public Retrofit.Builder create(String baseUrl) {
return create(baseUrl, new ObjectMapper());
}

/**
* Creates a new builder instance with the provided base url. Initialized with a Jackson JSON converter using the
* provided object mapper.
*
* @param baseUrl the base url
* @param objectMapper the object mapper
* @return a builder instance initialized for use with service classes
*/
public Retrofit.Builder create(String baseUrl, ObjectMapper objectMapper) {
return new Retrofit.Builder()
.baseUrl(baseUrl)
.client(_okHttpClient)
.addConverterFactory(JacksonConverterFactory.create(objectMapper));
}
}
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 @@ -25,7 +25,6 @@
/**
* Account Address, which is part of the {@link AccountSummaryInformation}
*
* @author woogienoogie
*/
@JsonAutoDetect(fieldVisibility = Visibility.ANY, getterVisibility = Visibility.NONE, setterVisibility = Visibility.NONE)
public class AccountAddress implements Serializable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import java.io.Serializable;

/**
* @author woogienoogie
*/
@JsonAutoDetect(fieldVisibility = Visibility.ANY, getterVisibility = Visibility.NONE, setterVisibility = Visibility.NONE)
public class AccountEmailAddress implements Serializable {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.constantcontact.v2.account;

/**
* @author woogienoogie
*/
public enum AccountEmailAddressStatus {
CONFIRMED,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import java.io.Serializable;

/**
* @author woogienoogie
*/
@JsonAutoDetect(fieldVisibility = Visibility.ANY, getterVisibility = Visibility.NONE, setterVisibility = Visibility.NONE)
public class AccountSummaryInformation implements Serializable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import java.util.Date;

/**
* @author woogienoogie
*/
@JsonFilter("CampaignCreateUpdateFilter")
@JsonInclude(JsonInclude.Include.NON_NULL)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import java.io.Serializable;

/**
* @author woogienoogie
*/
@JsonAutoDetect(fieldVisibility = Visibility.ANY, getterVisibility = Visibility.NONE, setterVisibility = Visibility.NONE)
public class CampaignPreview implements Serializable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
Expand All @@ -10,8 +11,8 @@
import java.util.Date;

/**
* @author woogienoogie
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonAutoDetect(fieldVisibility = Visibility.ANY, getterVisibility = Visibility.NONE, setterVisibility = Visibility.NONE)
public class CampaignSchedule implements Serializable {
@JsonProperty("id")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import java.util.Comparator;

/**
* @author woogienoogie
*/
@JsonAutoDetect(fieldVisibility = Visibility.ANY, getterVisibility = Visibility.NONE, setterVisibility = Visibility.NONE)
public class ClickThroughDetail implements Serializable {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.constantcontact.v2.campaigns;

/**
* @author woogienoogie
*/
public enum EmailFormat {
HTML,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import java.io.Serializable;

/**
* @author woogienoogie
*/
@JsonAutoDetect(fieldVisibility = Visibility.ANY, getterVisibility = Visibility.NONE, setterVisibility = Visibility.NONE)
public class MessageFooter implements Serializable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import java.io.Serializable;

/**
* @author woogienoogie
*/
@JsonAutoDetect(fieldVisibility = Visibility.ANY, getterVisibility = Visibility.NONE, setterVisibility = Visibility.NONE)
public class SentToContactList implements Serializable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import java.io.Serializable;

/**
* @author woogienoogie
*/
@JsonAutoDetect(fieldVisibility = Visibility.ANY, getterVisibility = Visibility.NONE, setterVisibility = Visibility.NONE)
public class TestSend implements Serializable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import java.io.Serializable;

/**
* @author woogienoogie
*/
@JsonAutoDetect(fieldVisibility = Visibility.ANY, getterVisibility = Visibility.NONE, setterVisibility = Visibility.NONE)
public class Address implements Serializable {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.constantcontact.v2.contacts;

/**
* @author woogienoogie
*/
public enum AddressType {
PERSONAL,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.constantcontact.v2.contacts;

/**
* @author woogienoogie
*/
public enum ConfirmStatus {
CONFIRMED,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import java.util.Date;

/**
* @author woogienoogie
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonAutoDetect(fieldVisibility = Visibility.ANY, getterVisibility = Visibility.NONE, setterVisibility = Visibility.NONE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import java.util.Date;

/**
* @author woogienoogie
*/
@JsonAutoDetect(fieldVisibility = Visibility.ANY, getterVisibility = Visibility.NONE, setterVisibility = Visibility.NONE)
public class ContactList implements Serializable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import java.io.Serializable;

/**
* @author woogienoogie
*/
@JsonAutoDetect(fieldVisibility = Visibility.ANY, getterVisibility = Visibility.NONE, setterVisibility = Visibility.NONE)
public class ContactListMetaData implements Serializable {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.constantcontact.v2.contacts;

/**
* @author woogienoogie
*/
public enum ContactListStatus {
ACTIVE,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.constantcontact.v2.contacts;

/**
* @author woogienoogie
*/
public enum ContactStatus {
ALL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import java.io.Serializable;

/**
* @author woogienoogie
*/
@JsonAutoDetect(fieldVisibility = Visibility.ANY, getterVisibility = Visibility.NONE, setterVisibility = Visibility.NONE)
public class CustomField implements Serializable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import java.util.Date;

/**
* @author woogienoogie
*/
@JsonAutoDetect(fieldVisibility = Visibility.ANY, getterVisibility = Visibility.NONE, setterVisibility = Visibility.NONE)
public class EmailAddress implements Serializable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import java.util.Date;

/**
* @author woogienoogie
*/
@JsonAutoDetect(fieldVisibility = Visibility.ANY, getterVisibility = Visibility.NONE, setterVisibility = Visibility.NONE)
public class Note implements Serializable {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.constantcontact.v2.contacts;

/**
* @author woogienoogie
*/
public enum OptInSource {
ACTION_BY_VISITOR,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
* Payload to give the server when requesting a signup form
* @see <a href="http://developer.constantcontact.com/docs/signup-forms-tools/signup-form-creation.html">Signup Form Creation</a>
*
* @author woogienoogie
*/
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY, getterVisibility = JsonAutoDetect.Visibility.NONE, setterVisibility = JsonAutoDetect.Visibility.NONE)
public class SignupFormRequest implements Serializable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
* Generated response from the server after requesting a signup form.
* @see <a href="http://developer.constantcontact.com/docs/signup-forms-tools/signup-form-creation.html">Signup Form Creation</a>
*
* @author woogienoogie
*/
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY, getterVisibility = JsonAutoDetect.Visibility.NONE, setterVisibility = JsonAutoDetect.Visibility.NONE)
public class SignupFormResponse implements Serializable {
Expand Down
Loading

0 comments on commit d7fdfd6

Please sign in to comment.