Skip to content

Commit 5fdec2c

Browse files
Merge pull request #140 from mailjet/refactor-exceptions
Refactors exception flow, adds integration tests, adds API version constant and contacts resource
2 parents 597181c + b312913 commit 5fdec2c

27 files changed

Lines changed: 615 additions & 278 deletions

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
language: java
2-
script: mvn test
2+
script: mvn verify
33
notifications:
44
slack:
55
secure: IMaSW3IgweT0HwDPo67iGwS/e7WD78y52Gz5m+VMbsiaryVRnetzttD+swerZ6DvvJe8vlpW+718a+/d9epG9oA63mbZ/kXPlAsPToqHN0/HH5QIlUfaupJeP4srXkqsnK+VnSw8cGxh9Ks5IE/cUvTLRGxKOP/qk7Gc3Sb55Kg=

README.md

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -93,18 +93,19 @@ import com.mailjet.client.MailjetClient;
9393
import com.mailjet.client.MailjetRequest;
9494
import com.mailjet.client.MailjetResponse;
9595
import com.mailjet.client.ClientOptions;
96+
import com.mailjet.client.resource.ApiVersion;
9697
import com.mailjet.client.resource.Emailv31;
9798
import org.json.JSONArray;
9899
import org.json.JSONObject;
99100
public class MyClass {
100101
/**
101102
* Run:
102103
*/
103-
public static void main(String[] args) throws MailjetException, MailjetSocketTimeoutException {
104+
public static void main(String[] args) throws MailjetException {
104105
MailjetClient client;
105106
MailjetRequest request;
106107
MailjetResponse response;
107-
client = new MailjetClient(System.getenv("MJ_APIKEY_PUBLIC"), System.getenv("MJ_APIKEY_PRIVATE"), new ClientOptions("v3.1"));
108+
client = new MailjetClient(System.getenv("MJ_APIKEY_PUBLIC"), System.getenv("MJ_APIKEY_PRIVATE"), new ClientOptions(ApiVersion.V3));
108109
request = new MailjetRequest(Emailv31.resource)
109110
.property(Emailv31.MESSAGES, new JSONArray()
110111
.put(new JSONObject()
@@ -130,7 +131,7 @@ public class MyClass {
130131
To instantiate the library you can use the following constructor:
131132

132133
```java
133-
MailjetClient client = new MailjetClient(System.getenv("MJ_APIKEY_PUBLIC"), System.getenv("MJ_APIKEY_PRIVATE"), new ClientOptions("v3","https://api.us.mailjet.com"));
134+
MailjetClient client = new MailjetClient(System.getenv("MJ_APIKEY_PUBLIC"), System.getenv("MJ_APIKEY_PRIVATE"), new ClientOptions(ApiVersion.V3, "https://api.us.mailjet.com"));
134135
```
135136

136137
- `$MJ_APIKEY_PUBLIC` : public Mailjet API key
@@ -151,7 +152,7 @@ Since most Email API endpoints are located under `v3`, it is set as the default
151152

152153
``` java
153154

154-
MailjetClient client = new MailjetClient(System.getenv("MJ_APIKEY_PUBLIC"), System.getenv("MJ_APIKEY_PRIVATE"), new ClientOptions("v3.1"));
155+
MailjetClient client = new MailjetClient(System.getenv("MJ_APIKEY_PUBLIC"), System.getenv("MJ_APIKEY_PRIVATE"), new ClientOptions(ApiVersion.V3_1));
155156

156157
```
157158

@@ -162,7 +163,7 @@ For additional information refer to our [API Reference](https://dev.preprod.mail
162163
The default base domain name for the Mailjet API is api.mailjet.com. You can modify this base URL by adding a different URL in `ClientOptions`:
163164

164165
```java
165-
MailjetClient client = new MailjetClient(System.getenv("MJ_APIKEY_PUBLIC"), System.getenv("MJ_APIKEY_PRIVATE"), new ClientOptions("v3","https://api.us.mailjet.com"));
166+
MailjetClient client = new MailjetClient(System.getenv("MJ_APIKEY_PUBLIC"), System.getenv("MJ_APIKEY_PRIVATE"), new ClientOptions(ApiVersion.V3, "https://api.us.mailjet.com"));
166167
```
167168

168169
If your account has been moved to Mailjet's **US architecture**, the URL you need to add is `https://api.us.mailjet.com`.
@@ -213,7 +214,7 @@ public class MyClass {
213214
/**
214215
* Create a contact
215216
*/
216-
public static void main(String[] args) throws MailjetException, MailjetSocketTimeoutException {
217+
public static void main(String[] args) throws MailjetException {
217218
MailjetClient client;
218219
MailjetRequest request;
219220
MailjetResponse response;
@@ -246,7 +247,7 @@ public class MyClass {
246247
/**
247248
* Create : Manage a contact subscription to a list
248249
*/
249-
public static void main(String[] args) throws MailjetException, MailjetSocketTimeoutException {
250+
public static void main(String[] args) throws MailjetException {
250251
MailjetClient client;
251252
MailjetRequest request;
252253
MailjetResponse response;
@@ -287,7 +288,7 @@ public class MyClass {
287288
/**
288289
* Run :
289290
*/
290-
public static void main(String[] args) throws MailjetException, MailjetSocketTimeoutException {
291+
public static void main(String[] args) throws MailjetException {
291292
MailjetClient client;
292293
MailjetRequest request;
293294
MailjetResponse response;
@@ -319,7 +320,7 @@ public class MyClass {
319320
/**
320321
* Run :
321322
*/
322-
public static void main(String[] args) throws MailjetException, MailjetSocketTimeoutException {
323+
public static void main(String[] args) throws MailjetException {
323324
MailjetClient client;
324325
MailjetRequest request;
325326
MailjetResponse response;
@@ -353,7 +354,7 @@ public class MyClass {
353354
/**
354355
* Run :
355356
*/
356-
public static void main(String[] args) throws MailjetException, MailjetSocketTimeoutException {
357+
public static void main(String[] args) throws MailjetException {
357358
MailjetClient client;
358359
MailjetRequest request;
359360
MailjetResponse response;
@@ -387,7 +388,7 @@ public class MyClass {
387388
/**
388389
* Modify : Modify the static custom contact data
389390
*/
390-
public static void main(String[] args) throws MailjetException, MailjetSocketTimeoutException {
391+
public static void main(String[] args) throws MailjetException {
391392
MailjetClient client;
392393
MailjetRequest request;
393394
MailjetResponse response;
@@ -427,7 +428,7 @@ public class MyClass {
427428
/**
428429
* Delete a Template
429430
*/
430-
public static void main(String[] args) throws MailjetException, MailjetSocketTimeoutException {
431+
public static void main(String[] args) throws MailjetException {
431432
MailjetClient client;
432433
MailjetRequest request;
433434
MailjetResponse response;
@@ -447,7 +448,7 @@ public class MyClass {
447448
Authentication for the SMS API endpoints is done using a bearer token. The bearer token is generated in the [SMS section](https://app.mailjet.com/sms) of your Mailjet account.
448449

449450
```java
450-
MailjetClient client = new MailjetClient(System.getenv("MJ_TOKEN"), new ClientOptions("v4"));
451+
MailjetClient client = new MailjetClient(System.getenv("MJ_TOKEN"), new ClientOptions(ApiVersion.V4));
451452
```
452453

453454
### Example request
@@ -461,7 +462,7 @@ MailjetRequest request;
461462
MailjetResponse response;
462463

463464
// Note how we set the version to v4 using ClientOptions and use an already generated token
464-
MailjetClient client = new MailjetClient(System.getenv("MJ_TOKEN"), new ClientOptions("v4"));
465+
MailjetClient client = new MailjetClient(System.getenv("MJ_TOKEN"), new ClientOptions(ApiVersion.V4));
465466

466467
request = new MailjetRequest(Send.resource)
467468
.property(Send.From, "MJPilot")
@@ -484,11 +485,11 @@ public class MyClass {
484485
/**
485486
* Run:
486487
*/
487-
public static void main(String[] args) throws MailjetException, MailjetSocketTimeoutException {
488+
public static void main(String[] args) throws MailjetException {
488489
MailjetClient client;
489490
MailjetRequest request;
490491
MailjetResponse response;
491-
client = new MailjetClient(System.getenv("MJ_TOKEN"), new ClientOptions("v4"));
492+
client = new MailjetClient(System.getenv("MJ_TOKEN"), new ClientOptions(ApiVersion.V4));
492493
request = new MailjetRequest(SmsSend.resource)
493494
.property(SmsSend.FROM, "MJPilot")
494495
.property(SmsSend.TO, "+33600000000")

pom.xml

Lines changed: 97 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!--Schema definition-->
3-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
45
<modelVersion>4.0.0</modelVersion>
56
<!--General configuration -->
67
<groupId>com.mailjet</groupId>
@@ -12,14 +13,14 @@
1213
<url>https://github.com/mailjet/mailjet-apiv3-java/</url>
1314
<!--Distribution-->
1415
<distributionManagement>
15-
<snapshotRepository>
16-
<id>ossrh-snapshot</id>
17-
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
18-
</snapshotRepository>
19-
<repository>
20-
<id>ossrh</id>
21-
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
22-
</repository>
16+
<snapshotRepository>
17+
<id>ossrh-snapshot</id>
18+
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
19+
</snapshotRepository>
20+
<repository>
21+
<id>ossrh</id>
22+
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
23+
</repository>
2324
</distributionManagement>
2425
<!--Source Control Management-->
2526
<scm>
@@ -58,9 +59,9 @@
5859
<version>0.89</version>
5960
</dependency>
6061
<dependency>
61-
<groupId>org.json</groupId>
62-
<artifactId>json</artifactId>
63-
<version>20190722</version>
62+
<groupId>org.json</groupId>
63+
<artifactId>json</artifactId>
64+
<version>20190722</version>
6465
</dependency>
6566
<dependency>
6667
<groupId>junit</groupId>
@@ -80,52 +81,37 @@
8081
<plugins>
8182
<!--Maven Release Plugin-->
8283
<plugin>
83-
<groupId>org.apache.maven.plugins</groupId>
84-
<artifactId>maven-release-plugin</artifactId>
85-
<version>2.5.3</version>
86-
<dependencies>
87-
<dependency>
88-
<groupId>org.apache.maven.plugins</groupId>
89-
<artifactId>maven-scm-plugin</artifactId>
90-
<version>1.8.1</version>
91-
</dependency>
92-
</dependencies>
93-
<configuration>
94-
<pushChanges>false</pushChanges>
95-
<checkModificationExcludes>
96-
<checkModificationExclude>pom.xml</checkModificationExclude>
97-
</checkModificationExcludes>
98-
<autoVersionSubmodules>true</autoVersionSubmodules>
99-
<goals>deploy</goals>
100-
<releaseProfiles>release</releaseProfiles>
101-
</configuration>
84+
<groupId>org.apache.maven.plugins</groupId>
85+
<artifactId>maven-release-plugin</artifactId>
86+
<version>2.5.3</version>
87+
<dependencies>
88+
<dependency>
89+
<groupId>org.apache.maven.plugins</groupId>
90+
<artifactId>maven-scm-plugin</artifactId>
91+
<version>1.8.1</version>
92+
</dependency>
93+
</dependencies>
94+
<configuration>
95+
<pushChanges>false</pushChanges>
96+
<checkModificationExcludes>
97+
<checkModificationExclude>pom.xml</checkModificationExclude>
98+
</checkModificationExcludes>
99+
<autoVersionSubmodules>true</autoVersionSubmodules>
100+
<goals>deploy</goals>
101+
<releaseProfiles>release</releaseProfiles>
102+
</configuration>
102103
</plugin>
103104
<!--Sona Type Plugin-->
104105
<plugin>
105-
<groupId>org.sonatype.plugins</groupId>
106-
<artifactId>nexus-staging-maven-plugin</artifactId>
107-
<version>1.6.8</version>
108-
<extensions>true</extensions>
109-
<configuration>
110-
<serverId>ossrh</serverId>
111-
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
112-
<autoReleaseAfterClose>true</autoReleaseAfterClose>
113-
</configuration>
114-
</plugin>
115-
<!--GPG Plugin-->
116-
<plugin>
117-
<groupId>org.apache.maven.plugins</groupId>
118-
<artifactId>maven-gpg-plugin</artifactId>
119-
<version>1.6</version>
120-
<executions>
121-
<execution>
122-
<id>sign-artifacts</id>
123-
<phase>verify</phase>
124-
<goals>
125-
<goal>sign</goal>
126-
</goals>
127-
</execution>
128-
</executions>
106+
<groupId>org.sonatype.plugins</groupId>
107+
<artifactId>nexus-staging-maven-plugin</artifactId>
108+
<version>1.6.8</version>
109+
<extensions>true</extensions>
110+
<configuration>
111+
<serverId>ossrh</serverId>
112+
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
113+
<autoReleaseAfterClose>true</autoReleaseAfterClose>
114+
</configuration>
129115
</plugin>
130116
<!--Source Plugin-->
131117
<plugin>
@@ -147,7 +133,8 @@
147133
<artifactId>maven-javadoc-plugin</artifactId>
148134
<version>3.2.0</version>
149135
<configuration>
150-
<doclint>none</doclint>
136+
<source>8</source>
137+
<detectJavaApiLink>false</detectJavaApiLink>
151138
</configuration>
152139
<executions>
153140
<execution>
@@ -158,6 +145,60 @@
158145
</execution>
159146
</executions>
160147
</plugin>
148+
<!--FailSage Plugin-->
149+
<plugin>
150+
<groupId>org.apache.maven.plugins</groupId>
151+
<artifactId>maven-failsafe-plugin</artifactId>
152+
<version>2.22.2</version>
153+
<executions>
154+
<execution>
155+
<goals>
156+
<goal>integration-test</goal>
157+
<goal>verify</goal>
158+
</goals>
159+
</execution>
160+
</executions>
161+
</plugin>
162+
<!--Compiler Plugin-->
163+
<plugin>
164+
<groupId>org.apache.maven.plugins</groupId>
165+
<artifactId>maven-compiler-plugin</artifactId>
166+
<version>3.8.1</version>
167+
<configuration>
168+
<source>8</source>
169+
<target>8</target>
170+
</configuration>
171+
</plugin>
161172
</plugins>
162173
</build>
174+
<profiles>
175+
<profile>
176+
<id>release</id>
177+
<activation>
178+
<property>
179+
<name>performRelease</name>
180+
<value>true</value>
181+
</property>
182+
</activation>
183+
<build>
184+
<plugins>
185+
<!--GPG Plugin-->
186+
<plugin>
187+
<groupId>org.apache.maven.plugins</groupId>
188+
<artifactId>maven-gpg-plugin</artifactId>
189+
<version>1.6</version>
190+
<executions>
191+
<execution>
192+
<id>sign-artifacts</id>
193+
<phase>verify</phase>
194+
<goals>
195+
<goal>sign</goal>
196+
</goals>
197+
</execution>
198+
</executions>
199+
</plugin>
200+
</plugins>
201+
</build>
202+
</profile>
203+
</profiles>
163204
</project>

src/main/java/com/mailjet/client/ClientOptions.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@
55

66
package com.mailjet.client;
77

8+
import com.mailjet.client.resource.ApiVersion;
9+
810
/**
911
*
1012
* @author Guillaume Badi
1113
*/
1214
public class ClientOptions {
1315

1416
private static String defaultBaseURL = "https://api.mailjet.com";
15-
private static String defaultVersion = "v3";
17+
private static String defaultVersion = ApiVersion.V3;
1618
private static Integer defaultTimeout = 8000;
1719

1820
private String baseUrl;

0 commit comments

Comments
 (0)