All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.mailgun.interceptors.MailgunRequestInterceptor Maven / Gradle / Ivy

Go to download

The Mailgun SDK for Java enables Java developers to work with Mailgun API efficiently.

The newest version!
package com.mailgun.interceptors;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

import feign.RequestInterceptor;
import feign.RequestTemplate;
import feign.form.FormProperty;

/**
 * 

* Implementation of the {@link RequestInterceptor} *

*

* for a creating: *

*
    *
  • * {@link FormProperty} with allowed prefixes such as: {@code t:, o:, h:, v:} with the followed by any arbitrary value *
  • *
  • * request header in format: {@code .addHeader(headerName, headerValue)} *
  • *
* @author Vitalii Chornobryvyi */ public class MailgunRequestInterceptor implements RequestInterceptor { private final Map> headers; private final Map> properties; private MailgunRequestInterceptor(Map> headers, Map> properties) { this.headers = headers; this.properties = properties; } public static Builder builder() { return new Builder(); } @Override public void apply(RequestTemplate requestTemplate) { requestTemplate.headers(headers); requestTemplate.queries(properties); } public static class Builder { private final Map> headers = new HashMap<>(); private final Map> properties = new HashMap<>(); public Builder addHeader(String headerName, String headerValue) { headers.computeIfAbsent(headerName, key -> new ArrayList<>()).add(headerValue); return this; } public Builder addProperty(String propertyName, String propertyValue) { properties.computeIfAbsent(propertyName, key -> new ArrayList<>()).add(propertyValue); return this; } public MailgunRequestInterceptor build() { return new MailgunRequestInterceptor(headers, properties); } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy