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

Configurable Root url #82

Merged
merged 2 commits into from
Nov 29, 2017
Merged
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
10 changes: 5 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,15 @@
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.2.2</version>
<version>2.8.2</version>
<scope>compile</scope>
</dependency>

<!-- Apache Http Client -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.3.3</version>
<version>4.5.3</version>
<scope>compile</scope>
<exclusions>
<exclusion>
Expand All @@ -166,9 +166,9 @@
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-io</artifactId>
<version>1.3.2</version>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.5</version> <!-- 2.5 is the last version to support java 1.6 -->
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this might be able to be switched to a test only dependency. It could also be a runtime dependency of the HttpClient though so I didn't change it.

<scope>compile</scope>
<exclusions>
<exclusion>
Expand Down
37 changes: 23 additions & 14 deletions src/main/java/com/microtripit/mandrillapp/lutung/MandrillApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
* @since Mar 17, 2013
*/
public class MandrillApi {
public static final String rootUrl = "https://mandrillapp.com/api/1.0/";
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is public because we need to default it here as well as in the other classes for backwards compatibility reasons. See below comment.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok


private String key;
private final MandrillUsersApi users;
private final MandrillMessagesApi messages;
Expand All @@ -38,25 +40,32 @@ public class MandrillApi {
private final MandrillIpsApi ips;

public MandrillApi(final String key) {
this(key, rootUrl);
}

public MandrillApi(final String key, final String rootUrl) {
if(key == null) {
throw new NullPointerException(
"'key' is null; please provide Mandrill API key");

}
if(rootUrl == null) {
throw new NullPointerException(
String.format("'rootUrl' is null; please provide Mandrill URL (default: %s)", rootUrl));
}
this.key = key;
users = new MandrillUsersApi(key);
messages = new MandrillMessagesApi(key);
tags = new MandrillTagsApi(key);
rejects = new MandrillRejectsApi(key);
whitelists = new MandrillWhitelistsApi(key);
senders = new MandrillSendersApi(key);
urls = new MandrillUrlsApi(key);
templates = new MandrillTemplatesApi(key);
webhooks = new MandrillWebhooksApi(key);
subaccounts = new MandrillSubaccountsApi(key);
inbound = new MandrillInboundApi(key);
exports = new MandrillExportsApi(key);
ips = new MandrillIpsApi(key);
users = new MandrillUsersApi(key, rootUrl);
messages = new MandrillMessagesApi(key, rootUrl);
tags = new MandrillTagsApi(key, rootUrl);
rejects = new MandrillRejectsApi(key, rootUrl);
whitelists = new MandrillWhitelistsApi(key, rootUrl);
senders = new MandrillSendersApi(key, rootUrl);
urls = new MandrillUrlsApi(key, rootUrl);
templates = new MandrillTemplatesApi(key, rootUrl);
webhooks = new MandrillWebhooksApi(key, rootUrl);
subaccounts = new MandrillSubaccountsApi(key, rootUrl);
inbound = new MandrillInboundApi(key, rootUrl);
exports = new MandrillExportsApi(key, rootUrl);
ips = new MandrillIpsApi(key, rootUrl);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.Date;
import java.util.HashMap;

import com.microtripit.mandrillapp.lutung.MandrillApi;
import com.microtripit.mandrillapp.lutung.model.MandrillApiError;
import com.microtripit.mandrillapp.lutung.view.MandrillExportJobInfo;

Expand All @@ -17,11 +18,16 @@
*
*/
public class MandrillExportsApi {
private static final String rootUrl = MandrillUtil.rootUrl;
private final String key;
private final String rootUrl;

public MandrillExportsApi(final String key, final String url) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to modify the original constructor but since this is a public class with a public constructor that would break backwards compatibility which is why I chose overloading.

this.key = key;
this.rootUrl = url;
}

public MandrillExportsApi(final String key) {
this.key = key;
this(key, MandrillApi.rootUrl);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.Collection;
import java.util.HashMap;

import com.microtripit.mandrillapp.lutung.MandrillApi;
import com.microtripit.mandrillapp.lutung.model.MandrillApiError;
import com.microtripit.mandrillapp.lutung.view.MandrillInboundDomain;
import com.microtripit.mandrillapp.lutung.view.MandrillInboundRecipient;
Expand All @@ -17,11 +18,16 @@
* @since Mar 19, 2013
*/
public class MandrillInboundApi {
private static final String rootUrl = MandrillUtil.rootUrl;
private final String key;
private final String rootUrl;

public MandrillInboundApi(final String key, final String url) {
this.key = key;
this.rootUrl = url;
}

public MandrillInboundApi(final String key) {
this.key = key;
this(key, MandrillApi.rootUrl);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.Date;
import java.util.HashMap;

import com.microtripit.mandrillapp.lutung.MandrillApi;
import com.microtripit.mandrillapp.lutung.model.MandrillApiError;
import com.microtripit.mandrillapp.lutung.view.MandrillDedicatedIp;
import com.microtripit.mandrillapp.lutung.view.MandrillDedicatedIp.MandrillDnsCheck;
Expand All @@ -17,11 +18,16 @@
*
*/
public class MandrillIpsApi {
private static final String rootUrl = MandrillUtil.rootUrl;
private final String key;
private final String rootUrl;

public MandrillIpsApi(final String key, final String url) {
this.key = key;
this.rootUrl = url;
}

public MandrillIpsApi(final String key) {
this.key = key;
this(key, MandrillApi.rootUrl);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.HashMap;
import java.util.Map;

import com.microtripit.mandrillapp.lutung.MandrillApi;
import com.microtripit.mandrillapp.lutung.model.MandrillApiError;
import com.microtripit.mandrillapp.lutung.view.*;

Expand All @@ -18,11 +19,16 @@
* @since Mar 19, 2013
*/
public class MandrillMessagesApi {
private static final String rootUrl = MandrillUtil.rootUrl;
private final String key;
private final String rootUrl;

public MandrillMessagesApi(final String key, final String url) {
this.key = key;
this.rootUrl = url;
}

public MandrillMessagesApi(final String key) {
this.key = key;
this(key, MandrillApi.rootUrl);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.io.IOException;
import java.util.HashMap;

import com.microtripit.mandrillapp.lutung.MandrillApi;
import com.microtripit.mandrillapp.lutung.model.MandrillApiError;
import com.microtripit.mandrillapp.lutung.model.MandrillHelperClasses.MandrillRejectsDeleted;
import com.microtripit.mandrillapp.lutung.model.MandrillHelperClasses.MandrillRejectsAdded;
Expand All @@ -16,11 +17,16 @@
* @since Mar 19, 2013
*/
public class MandrillRejectsApi {
private static final String rootUrl = MandrillUtil.rootUrl;
private final String key;
private final String rootUrl;

public MandrillRejectsApi(final String key, final String url) {
this.key = key;
this.rootUrl = url;
}

public MandrillRejectsApi(final String key) {
this.key = key;
this(key, MandrillApi.rootUrl);
}

public Boolean add(final String email, final String comment,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.io.IOException;
import java.util.HashMap;

import com.microtripit.mandrillapp.lutung.MandrillApi;
import com.microtripit.mandrillapp.lutung.model.MandrillApiError;
import com.microtripit.mandrillapp.lutung.view.MandrillDomain;
import com.microtripit.mandrillapp.lutung.view.MandrillDomain.MandrillDomainVerificationInfo;
Expand All @@ -17,11 +18,16 @@
* @since Mar 19, 2013
*/
public class MandrillSendersApi {
private static final String rootUrl = MandrillUtil.rootUrl;
private final String key;
private final String rootUrl;

public MandrillSendersApi(final String key, final String url) {
this.key = key;
this.rootUrl = url;
}

public MandrillSendersApi(final String key) {
this.key = key;
this(key, MandrillApi.rootUrl);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,21 @@
import java.io.IOException;
import java.util.HashMap;

import com.microtripit.mandrillapp.lutung.MandrillApi;
import com.microtripit.mandrillapp.lutung.model.MandrillApiError;
import com.microtripit.mandrillapp.lutung.view.MandrillSubaccountInfo;

public class MandrillSubaccountsApi {
private static final String rootUrl = MandrillUtil.rootUrl;
private final String key;
private final String rootUrl;

public MandrillSubaccountsApi(final String key, final String url) {
this.key = key;
this.rootUrl = url;
}

public MandrillSubaccountsApi(final String key) {
this.key = key;
this(key, MandrillApi.rootUrl);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.io.IOException;
import java.util.HashMap;

import com.microtripit.mandrillapp.lutung.MandrillApi;
import com.microtripit.mandrillapp.lutung.model.MandrillApiError;
import com.microtripit.mandrillapp.lutung.view.MandrillTag;
import com.microtripit.mandrillapp.lutung.view.MandrillTimeSeries;
Expand All @@ -15,11 +16,16 @@
* @since Mar 19, 2013
*/
public class MandrillTagsApi {
private static final String rootUrl = MandrillUtil.rootUrl;
private final String key;
private final String rootUrl;

public MandrillTagsApi(final String key, final String url) {
this.key = key;
this.rootUrl = url;
}

public MandrillTagsApi(final String key) {
this.key = key;
this(key, MandrillApi.rootUrl);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.HashMap;
import java.util.Map;

import com.microtripit.mandrillapp.lutung.MandrillApi;
import com.microtripit.mandrillapp.lutung.model.MandrillApiError;
import com.microtripit.mandrillapp.lutung.model.MandrillContentWrapper;
import com.microtripit.mandrillapp.lutung.model.MandrillHelperClasses.MandrillRenderTemplateResponse;
Expand All @@ -19,11 +20,16 @@
* @since Mar 19, 2013
*/
public class MandrillTemplatesApi {
private static final String rootUrl = MandrillUtil.rootUrl;
private final String key;
private final String rootUrl;

public MandrillTemplatesApi(final String key) {
public MandrillTemplatesApi(final String key, final String url) {
this.key = key;
this.rootUrl = url;
}

public MandrillTemplatesApi(final String key) {
this(key, MandrillApi.rootUrl);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.io.IOException;
import java.util.HashMap;

import com.microtripit.mandrillapp.lutung.MandrillApi;
import com.microtripit.mandrillapp.lutung.model.MandrillApiError;
import com.microtripit.mandrillapp.lutung.view.MandrillTimeSeries;
import com.microtripit.mandrillapp.lutung.view.MandrillUrl;
Expand All @@ -15,11 +16,16 @@
* @since Mar 19, 2013
*/
public class MandrillUrlsApi {
private static final String rootUrl = MandrillUtil.rootUrl;
private final String key;
private final String rootUrl;

public MandrillUrlsApi(final String key, final String url) {
this.key = key;
this.rootUrl = url;
}

public MandrillUrlsApi(final String key) {
this.key = key;
this(key, MandrillApi.rootUrl);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import java.io.IOException;

import com.microtripit.mandrillapp.lutung.MandrillApi;
import com.microtripit.mandrillapp.lutung.model.MandrillApiError;
import com.microtripit.mandrillapp.lutung.view.MandrillSender;
import com.microtripit.mandrillapp.lutung.view.MandrillUserInfo;
Expand All @@ -15,11 +16,16 @@
* @since Mar 19, 2013
*/
public class MandrillUsersApi {
private static final String rootUrl = MandrillUtil.rootUrl;
private final String key;
private final String rootUrl;

public MandrillUsersApi(final String key, final String url) {
this.key = key;
this.rootUrl = url;
}

public MandrillUsersApi(final String key) {
this.key = key;
this(key, MandrillApi.rootUrl);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
* @since Mar 19, 2013
*/
final class MandrillUtil {
protected static final String rootUrl = "https://mandrillapp.com/api/1.0/";

/**
* @param key
* @return
Expand Down
Loading