/
MandrillWhitelistsApi.java
93 lines (76 loc) · 2.86 KB
/
MandrillWhitelistsApi.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
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.model.MandrillHelperClasses.EmailClass;
import com.microtripit.mandrillapp.lutung.view.MandrillWhitelistEntry;
public class MandrillWhitelistsApi {
private final String key;
private final String rootUrl;
public MandrillWhitelistsApi(final String key, final String url) {
this.key = key;
this.rootUrl = url;
}
public MandrillWhitelistsApi(final String key) {
this(key, MandrillApi.rootUrl);
}
/**
* <p>Adds an email to your email rejection whitelist. If the
* address is currently on your blacklist, that blacklist
* entry will be removed automatically.</p>
* @param email An email address to add to the whitelist.
* @return If the operation succeeded.
* @throws MandrillApiError Mandrill API Error
* @throws IOException IO Error
*/
public Boolean add(final String email)
throws MandrillApiError, IOException {
final HashMap<String,Object> params = MandrillUtil.paramsWithKey(key);
params.put("email", email);
return MandrillUtil.query(rootUrl+ "whitelists/add.json",
params, WhitelistsAddResponse.class).getWhether();
}
/**
* <p>Retrieves your email rejection whitelist. You can provide
* an email address or search prefix to limit the results.
* Returns up to 1000 results.</p>
* @param email An optional email address or prefix to search by.
* @return Information for each whitelist entry.
* @throws MandrillApiError Mandrill API Error
* @throws IOException IO Error
*/
public MandrillWhitelistEntry[] list(final String email)
throws MandrillApiError, IOException {
final HashMap<String,Object> params = MandrillUtil.paramsWithKey(key);
params.put("email", email);
return MandrillUtil.query(rootUrl+ "whitelists/list.json",
params, MandrillWhitelistEntry[].class);
}
/**
* <p>Removes an email address from the whitelist.</p>
* @param email The email address to remove from the whitelist.
* @return Whether the address was deleted successfully.
* @throws MandrillApiError Mandrill API Error
* @throws IOException IO Error
*/
public Boolean delete(final String email)
throws MandrillApiError, IOException {
final HashMap<String,Object> params = MandrillUtil.paramsWithKey(key);
params.put("email", email);
return MandrillUtil.query(rootUrl+ "whitelists/delete.json",
params, WhitelistsDeleteResponse.class).getDeleted();
}
public static class WhitelistsAddResponse extends EmailClass {
private Boolean whether;
public Boolean getWhether() {
return whether;
}
}
public static class WhitelistsDeleteResponse {
private Boolean deleted;
public Boolean getDeleted() {
return deleted;
}
}
}