1919import java .io .IOException ;
2020
2121import org .apache .http .HttpResponse ;
22- import org .apache .http .client .HttpClient ;
2322import org .apache .http .HttpEntity ;
2423import org .apache .http .entity .mime .MultipartEntityBuilder ;
2524import 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 ;
2727import org .apache .http .util .EntityUtils ;
2828
2929
3030public class SendGrid {
31+ private static final String VERSION = "1.0.1" ;
32+ private static final String USER_AGENT = "sendgrid/" + VERSION + ";java" ;
33+
3134 private static final String PARAM_TO = "to[%d]" ;
3235 private static final String PARAM_TONAME = "toname[%d]" ;
3336 private static final String PARAM_FROM = "from" ;
@@ -46,14 +49,14 @@ public class SendGrid {
4649 private String url ;
4750 private String port ;
4851 private String endpoint ;
49- private HttpClient client ;
52+ private CloseableHttpClient client ;
5053
5154 public SendGrid (String username , String password ) {
5255 this .username = username ;
5356 this .password = password ;
5457 this .url = "https://api.sendgrid.com" ;
5558 this .endpoint = "/api/mail.send.json" ;
56- this .client = new DefaultHttpClient ();
59+ this .client = HttpClientBuilder . create (). setUserAgent ( USER_AGENT ). build ();
5760 }
5861
5962 public SendGrid setUrl (String url ) {
@@ -66,6 +69,15 @@ public SendGrid setEndpoint(String endpoint) {
6669 return this ;
6770 }
6871
72+ public String getVersion () {
73+ return VERSION ;
74+ }
75+
76+ public SendGrid setClient (CloseableHttpClient client ) {
77+ this .client = client ;
78+ return this ;
79+ }
80+
6981 public HttpEntity buildBody (Email email ) {
7082 MultipartEntityBuilder builder = MultipartEntityBuilder .create ();
7183
0 commit comments