com.microtripit.mandrillapp.lutung.controller.MandrillSendersApi Maven / Gradle / Ivy
Show all versions of lutung Show documentation
/**
*
*/
package com.microtripit.mandrillapp.lutung.controller;
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;
import com.microtripit.mandrillapp.lutung.view.MandrillSender;
import com.microtripit.mandrillapp.lutung.view.MandrillTimeSeries;
/**
* @author rschreijer
* @since Mar 19, 2013
*/
public class MandrillSendersApi {
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, MandrillApi.rootUrl);
}
/**
* Get the senders that have tried to use this account.
* @return An array of {@link MandrillSender} objects, one
* for each sending addresses used by the account.
* @throws MandrillApiError Mandrill API Error
* @throws IOException IO Error
*/
public MandrillSender[] list()
throws MandrillApiError, IOException {
return MandrillUtil.query(
rootUrl+ "senders/list.json",
MandrillUtil.paramsWithKey(key),
MandrillSender[].class);
}
/**
* Get the sender domains that have been added to this account.
* @return An array of sender domain data, one for each
* sending domain used by the account.
* @throws MandrillApiError Mandrill API Error
* @throws IOException IO Error
*/
public MandrillDomain[] domains()
throws MandrillApiError, IOException {
return MandrillUtil.query(
rootUrl+ "senders/domains.json",
MandrillUtil.paramsWithKey(key),
MandrillDomain[].class);
}
/**
* Adds a sender domain to your account. Sender domains
* are added automatically as you send, but you can use
* this call to add them ahead of time.
* @param domain A domain name.
* @return Information about the domain.
* @throws MandrillApiError Mandrill API Error
* @throws IOException IO Error
*/
public MandrillDomain addDomain(final String domain)
throws MandrillApiError, IOException {
final HashMap params = MandrillUtil.paramsWithKey(key);
params.put("domain", domain);
return MandrillUtil.query(rootUrl+ "senders/add-domain.json",
params, MandrillDomain.class);
}
/**
* Checks the SPF and DKIM settings for a domain. If you
* haven't already added this domain to your account,
* it will be added automatically.
* @param domain A domain name.
* @return Information about the sender domain.
* @throws MandrillApiError Mandrill API Error
* @throws IOException IO Error
*/
public MandrillDomain checkDomain(final String domain)
throws MandrillApiError, IOException {
final HashMap params = MandrillUtil.paramsWithKey(key);
params.put("domain", domain);
return MandrillUtil.query(rootUrl+ "senders/check-domain.json",
params, MandrillDomain.class);
}
/**
* Sends a verification email in order to verify ownership
* of a domain. Domain verification is an optional step to
* confirm ownership of a domain. Once a domain has been verified
* in a Mandrill account, other accounts may not have their
* messages signed by that domain unless they also verify the
* domain. This prevents other Mandrill accounts from sending
* mail signed by your domain.
* @param domain A domain name at which you can receive email.
* @param mailbox A mailbox at the domain where the verification
* email should be sent.
* @return Info about the verification email that was sent.
* @throws MandrillApiError Mandrill API Error
* @throws IOException IO Error
*/
public MandrillDomainVerificationInfo verifyDomain(
final String domain, final String mailbox)
throws MandrillApiError, IOException {
final HashMap params = MandrillUtil.paramsWithKey(key);
params.put("domain", domain);
params.put("mailbox", mailbox);
return MandrillUtil.query(rootUrl+ "senders/verify-domain.json",
params, MandrillDomainVerificationInfo.class);
}
/**
* Get more detailed information about a single sender,
* including aggregates of recent stats.
* @param address The email address of the sender.
* @return The detailed information on the sender.
* @throws MandrillApiError Mandrill API Error
* @throws IOException IO Error
*/
public MandrillSender info(final String address)
throws MandrillApiError, IOException {
final HashMap params = MandrillUtil.paramsWithKey(key);
params.put("address", address);
return MandrillUtil.query(rootUrl+ "senders/info.json",
params, MandrillSender.class);
}
/**
* Get the recent history (hourly stats for
* the last 30 days) for a sender.
* @param address The email address of the sender.
* @return An array of history information.
* @throws MandrillApiError Mandrill API Error
* @throws IOException IO Error
*/
public MandrillTimeSeries[] timeSeries(final String address)
throws MandrillApiError, IOException {
final HashMap params = MandrillUtil.paramsWithKey(key);
params.put("address", address);
return MandrillUtil.query(rootUrl+ "senders/time-series.json",
params, MandrillTimeSeries[].class);
}
}