Skip to content

Commit d2bccb2

Browse files
committed
Merge branch 'javaism' of github.com:sendgrid/sendgrid-java into javaism
2 parents ddd7e47 + 119c784 commit d2bccb2

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

build.gradle

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ apply plugin: 'maven'
1717
apply plugin: 'signing'
1818

1919
group = 'com.sendgrid'
20-
version = "1.0.0"
20+
version = "1.0.1"
2121
ext.packaging = 'jar'
2222
sourceCompatibility = 1.6
2323

@@ -142,7 +142,6 @@ uploadArchives {
142142

143143
artifacts {
144144
archives fatJar
145-
146145
archives jar
147146
archives javadocJar
148147
archives sourcesJar

src/main/java/com/sendgrid/SendGrid.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,18 @@
1919
import java.io.IOException;
2020

2121
import org.apache.http.HttpResponse;
22-
import org.apache.http.client.HttpClient;
2322
import org.apache.http.HttpEntity;
2423
import org.apache.http.entity.mime.MultipartEntityBuilder;
2524
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;
2727
import org.apache.http.util.EntityUtils;
2828

2929

3030
public 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

Comments
 (0)