19
19
import java .io .IOException ;
20
20
21
21
import org .apache .http .HttpResponse ;
22
- import org .apache .http .client .HttpClient ;
23
22
import org .apache .http .HttpEntity ;
24
23
import org .apache .http .entity .mime .MultipartEntityBuilder ;
25
24
import org .apache .http .client .methods .HttpPost ;
26
- import org .apache .http .impl .client .DefaultHttpClient ;
25
+ import org .apache .http .impl .client .HttpClientBuilder ;
26
+ import org .apache .http .impl .client .CloseableHttpClient ;
27
27
import org .apache .http .util .EntityUtils ;
28
28
29
29
30
30
public class SendGrid {
31
+ private static final String VERSION = "1.0.1" ;
32
+ private static final String USER_AGENT = "sendgrid/" + VERSION + ";java" ;
33
+
31
34
private static final String PARAM_TO = "to[%d]" ;
32
35
private static final String PARAM_TONAME = "toname[%d]" ;
33
36
private static final String PARAM_FROM = "from" ;
@@ -46,14 +49,14 @@ public class SendGrid {
46
49
private String url ;
47
50
private String port ;
48
51
private String endpoint ;
49
- private HttpClient client ;
52
+ private CloseableHttpClient client ;
50
53
51
54
public SendGrid (String username , String password ) {
52
55
this .username = username ;
53
56
this .password = password ;
54
57
this .url = "https://api.sendgrid.com" ;
55
58
this .endpoint = "/api/mail.send.json" ;
56
- this .client = new DefaultHttpClient ();
59
+ this .client = HttpClientBuilder . create (). setUserAgent ( USER_AGENT ). build ();
57
60
}
58
61
59
62
public SendGrid setUrl (String url ) {
@@ -66,6 +69,15 @@ public SendGrid setEndpoint(String endpoint) {
66
69
return this ;
67
70
}
68
71
72
+ public String getVersion () {
73
+ return VERSION ;
74
+ }
75
+
76
+ public SendGrid setClient (CloseableHttpClient client ) {
77
+ this .client = client ;
78
+ return this ;
79
+ }
80
+
69
81
public HttpEntity buildBody (Email email ) {
70
82
MultipartEntityBuilder builder = MultipartEntityBuilder .create ();
71
83
0 commit comments