Skip to content

Commit 876cd3a

Browse files
author
Vitalii.Chornobryvyi
committed
release 1.1.1
1 parent 99660a1 commit 876cd3a

File tree

6 files changed

+99
-5
lines changed

6 files changed

+99
-5
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ All _notable_ changes to this project will be documented in this file.
55
The format is based on _[Keep a Changelog][keepachangelog]_, and this project
66
adheres to _[Semantic Versioning][semver]_.
77

8+
## [1.1.1] (released: 2023-12-12)
9+
### Updated
10+
- add ability for primary accounts to make API calls on behalf of their subaccounts, e.g. sending messages, managing mailing lists, etc.
11+
812
## [1.1.0] (released: 2023-10-23)
913
### Updated
1014
- add ability to get the first / last / next / previous page data.
@@ -63,7 +67,8 @@ adheres to _[Semantic Versioning][semver]_.
6367
- Add Import a list of bounces from CSV file API
6468

6569

66-
[1.1.0]: https://github.com/mailgun/mailgun-java/compare/release/1.0.8...release/1.1.0
70+
[1.1.1]: https://github.com/mailgun/mailgun-java/compare/release/1.1.0...release/1.1.1
71+
[1.1.0]: https://github.com/mailgun/mailgun-java/compare/release/1.0.9...release/1.1.0
6772
[1.0.9]: https://github.com/mailgun/mailgun-java/compare/release/1.0.8...release/1.0.9
6873
[1.0.8]: https://github.com/mailgun/mailgun-java/compare/release/1.0.7...release/1.0.8
6974
[1.0.7]: https://github.com/mailgun/mailgun-java/compare/release/1.0.6...release/1.0.7

README.md

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ Add the following to your `pom.xml`:
7676
<dependency>
7777
<groupId>com.mailgun</groupId>
7878
<artifactId>mailgun-java</artifactId>
79-
<version>1.1.0</version>
79+
<version>1.1.1</version>
8080
</dependency>
8181
...
8282
</dependencies>
@@ -85,7 +85,7 @@ Add the following to your `pom.xml`:
8585
Gradle Groovy DSL .
8686

8787
```xml
88-
implementation 'com.mailgun:mailgun-java:1.1.0'
88+
implementation 'com.mailgun:mailgun-java:1.1.1'
8989
```
9090

9191

@@ -154,6 +154,22 @@ You can specify your own logLevel, retryer, logger, errorDecoder, options.
154154
.options(new Request.Options(10, TimeUnit.SECONDS, 60, TimeUnit.SECONDS, true))
155155
```
156156

157+
#### Mailgun client configuration with request interceptor for all API calls
158+
159+
You can add your multiple custom:
160+
161+
1) request header in format: ```(headerName, headerValue)```
162+
2) form property with allowed prefixes such as: ```t:, o:, h:, v:``` with the followed by any arbitrary value.
163+
```java
164+
MailgunMessagesApi mailgunMessagesApi = MailgunClient.config(API_KEY)
165+
.createApiWithRequestInterceptor(MailgunMessagesApi.class,
166+
MailgunRequestInterceptor.builder()
167+
.addHeader(HEADER_ON_BEHALF_OF, SUBACCOUNT_ACCOUNT_ID)
168+
.addProperty("h:X-My-Header", "my_custom_header")
169+
.build()
170+
);
171+
```
172+
157173
#### Mailgun client configuration example for the [Mailgun sending emails API](https://documentation.mailgun.com/en/latest/api-sending.html)
158174

159175
```java
@@ -655,7 +671,7 @@ You can send email(s) with your own custom dynamic form property with allowed pr
655671
```java
656672
MailgunMessagesApi mailgunMessagesApi = MailgunClient.config(PRIVATE_API_KEY)
657673
.createApiWithRequestInterceptor(MailgunMessagesApi.class,
658-
FormPropertyRequestInterceptor.builder()
674+
MailgunRequestInterceptor.builder()
659675
.addProperty("h:Sender", EmailUtil.nameWithEmail(SENDER_NAME, SENDER_EMAIL))
660676
.addProperty("h:X-My-Header", "my_custom_header")
661677
.build()

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>com.mailgun</groupId>
88
<artifactId>mailgun-java</artifactId>
9-
<version>1.1.0</version>
9+
<version>1.1.1</version>
1010
<packaging>jar</packaging>
1111

1212
<name>${project.groupId}:${project.artifactId}</name>

src/main/java/com/mailgun/form/FormPropertyRequestInterceptor.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.mailgun.form;
22

3+
import com.mailgun.interceptors.MailgunRequestInterceptor;
4+
35
import java.util.ArrayList;
46
import java.util.Collection;
57
import java.util.HashMap;
@@ -15,7 +17,10 @@
1517
* with allowed prefixes such as: {@code t:, o:, h:, v:} with the followed by any arbitrary value
1618
* </p>
1719
* @author Vitalii Chornobryvyi
20+
* @deprecated This class is deprecated and will be replaced by {@link MailgunRequestInterceptor} after 1st of the March 2024.
21+
* Please consider migrating to the new class for future updates.
1822
*/
23+
@Deprecated
1924
public class FormPropertyRequestInterceptor implements RequestInterceptor {
2025
private final Map<String, Collection<String>> properties;
2126

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package com.mailgun.interceptors;
2+
3+
import java.util.ArrayList;
4+
import java.util.Collection;
5+
import java.util.HashMap;
6+
import java.util.Map;
7+
8+
import feign.RequestInterceptor;
9+
import feign.RequestTemplate;
10+
import feign.form.FormProperty;
11+
12+
/**
13+
* <h3>
14+
* Implementation of the {@link RequestInterceptor}
15+
* </h3>
16+
* <p>
17+
* for a creating:
18+
* </p>
19+
* <ul>
20+
* <li>
21+
* {@link FormProperty} with allowed prefixes such as: {@code t:, o:, h:, v:} with the followed by any arbitrary value
22+
* </li>
23+
* <li>
24+
* request header in format: {@code .addHeader(headerName, headerValue)}
25+
* </li>
26+
* </ul>
27+
* @author Vitalii Chornobryvyi
28+
*/
29+
public class MailgunRequestInterceptor implements RequestInterceptor {
30+
private final Map<String, Collection<String>> headers;
31+
private final Map<String, Collection<String>> properties;
32+
33+
private MailgunRequestInterceptor(Map<String, Collection<String>> headers, Map<String, Collection<String>> properties) {
34+
this.headers = headers;
35+
this.properties = properties;
36+
}
37+
38+
public static Builder builder() {
39+
return new Builder();
40+
}
41+
42+
@Override
43+
public void apply(RequestTemplate requestTemplate) {
44+
requestTemplate.headers(headers);
45+
requestTemplate.queries(properties);
46+
}
47+
48+
public static class Builder {
49+
private final Map<String, Collection<String>> headers = new HashMap<>();
50+
private final Map<String, Collection<String>> properties = new HashMap<>();
51+
52+
public Builder addHeader(String headerName, String headerValue) {
53+
headers.computeIfAbsent(headerName, key -> new ArrayList<>()).add(headerValue);
54+
return this;
55+
}
56+
57+
public Builder addProperty(String propertyName, String propertyValue) {
58+
properties.computeIfAbsent(propertyName, key -> new ArrayList<>()).add(propertyValue);
59+
return this;
60+
}
61+
62+
public MailgunRequestInterceptor build() {
63+
return new MailgunRequestInterceptor(headers, properties);
64+
}
65+
}
66+
}

src/main/java/com/mailgun/util/Constants.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ public class Constants {
1010

1111
public static final String ENGLISH = "en";
1212

13+
public static final String HEADER_ON_BEHALF_OF = "X-Mailgun-On-Behalf-Of";
14+
1315
// "Z" ==> "+0900"
1416
public static final String RFC_2822_DATE_TIME_PATTERN_TIME_ZONE_NUMERIC = "EEE, dd MMM yyyy HH:mm:ss Z";
1517
// "z" ==> "UTC"

0 commit comments

Comments
 (0)