com.mailgun.client.MailgunClient Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mailgun-java Show documentation
Show all versions of mailgun-java Show documentation
The Mailgun SDK for Java enables Java developers to work with Mailgun API
efficiently.
The newest version!
package com.mailgun.client;
import java.util.concurrent.Executors;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.mailgun.api.MailgunApi;
import com.mailgun.form.FormEncoder;
import com.mailgun.util.ConsoleLogger;
import com.mailgun.util.MailgunApiUtil;
import com.mailgun.util.ObjectMapperUtil;
import feign.AsyncClient;
import feign.AsyncFeign;
import feign.Client;
import feign.Feign;
import feign.Logger;
import feign.Request;
import feign.RequestInterceptor;
import feign.Retryer;
import feign.auth.BasicAuthRequestInterceptor;
import feign.codec.ErrorDecoder;
import feign.jackson.JacksonDecoder;
import feign.jackson.JacksonEncoder;
import feign.querymap.FieldQueryMapEncoder;
import lombok.experimental.UtilityClass;
import static com.mailgun.util.Constants.DEFAULT_BASE_URL_US_REGION;
/**
*
* Client for accessing Mailgun API
*
*
* @see API Reference
*/
@UtilityClass
public class MailgunClient {
private static final ObjectMapper OBJECT_MAPPER = ObjectMapperUtil.getObjectMapper();
private static final FormEncoder ENCODER = new FormEncoder(new JacksonEncoder(OBJECT_MAPPER));
private static final JacksonDecoder DECODER = new JacksonDecoder(OBJECT_MAPPER);
private static final FieldQueryMapEncoder QUERY_MAP_ENCODER = new FieldQueryMapEncoder();
/**
*
* Create {@link MailgunClientBuilder} with the default configuration.
*
*
* @param baseUrl base URL
* @param apiKey primary account API key
* @return {@link MailgunClientBuilder} with the default configuration
*/
public MailgunClientBuilder config(String baseUrl, String apiKey) {
return new MailgunClientBuilder(baseUrl, apiKey);
}
/**
*
* Create {@link MailgunClientBuilder} with the default configuration.
*
*
* @param apiKey primary account API key
* @return {@link MailgunClientBuilder} with the default configuration
*/
public MailgunClientBuilder config(String apiKey) {
return new MailgunClientBuilder(apiKey);
}
public static class MailgunClientBuilder {
private Logger.Level logLevel = Logger.Level.BASIC;
private Retryer retryer = new Retryer.Default();
private Logger logger = new ConsoleLogger();
private ErrorDecoder errorDecoder = new ErrorDecoder.Default();
private Request.Options options = new Request.Options();
private AsyncClient