Skip to content

Commit a183530

Browse files
author
Chris Wilson
committed
Changes RestConnection to use Endpoint instead of a path string
1 parent 26feacf commit a183530

17 files changed

+267
-92
lines changed

libs/sparkpost-lib/src/main/java/com/sparkpost/resources/Endpoint.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55

66
/**
77
* Used internally to the SparkPost Library to write URL queries.
8-
*
9-
* @author grava
108
*/
119
public class Endpoint {
1210

libs/sparkpost-lib/src/main/java/com/sparkpost/resources/ResourceMetrics.java

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class ResourceMetrics {
2020

2121
public static Response getDiscoverabilityLinks(IRestConnection conn) throws SparkPostException {
2222
Endpoint ep = new Endpoint("metrics/");
23-
return conn.get(ep.toString());
23+
return conn.get(ep);
2424
}
2525

2626
public static DeliverabiltyMetricsResponse getDeliverabilityMetricsSummary(
@@ -36,7 +36,7 @@ public static DeliverabiltyMetricsResponse getDeliverabilityMetricsSummary(
3636
Endpoint ep = new Endpoint("metrics/deliverability");
3737
ep.addCommonParams(from, to, domains, campaigns, templates, metrics, timezone, null, null);
3838

39-
Response response = conn.get(ep.toString());
39+
Response response = conn.get(ep);
4040
DeliverabiltyMetricsResponse newResponse = DeliverabiltyMetricsResponse.decode(response, DeliverabiltyMetricsResponse.class);
4141

4242
return newResponse;
@@ -57,7 +57,7 @@ public static DeliverabiltyMetricsResponse getDeliverabilityMetricsByDomain(
5757
Endpoint ep = new Endpoint("metrics/deliverability/domain");
5858
ep.addCommonParams(from, to, domains, campaigns, templates, metrics, timezone, limit, orderBy);
5959

60-
Response response = conn.get(ep.toString());
60+
Response response = conn.get(ep);
6161
DeliverabiltyMetricsResponse newResponse = DeliverabiltyMetricsResponse.decode(response, DeliverabiltyMetricsResponse.class);
6262

6363
return newResponse;
@@ -79,7 +79,7 @@ public static DeliverabiltyMetricsResponse getDeliverabilityMetricsByCampaign(
7979
Endpoint ep = new Endpoint("metrics/deliverability/campaign");
8080
ep.addCommonParams(from, to, domains, campaigns, templates, metrics, timezone, limit, orderBy);
8181

82-
Response response = conn.get(ep.toString());
82+
Response response = conn.get(ep);
8383
DeliverabiltyMetricsResponse newResponse = DeliverabiltyMetricsResponse.decode(response, DeliverabiltyMetricsResponse.class);
8484

8585
return newResponse;
@@ -101,7 +101,7 @@ public static DeliverabiltyMetricsResponse getDeliverabilityMetricsByTemplate(
101101
Endpoint ep = new Endpoint("metrics/deliverability/template");
102102
ep.addCommonParams(from, to, domains, campaigns, templates, metrics, timezone, limit, orderBy);
103103

104-
Response response = conn.get(ep.toString());
104+
Response response = conn.get(ep);
105105
DeliverabiltyMetricsResponse newResponse = DeliverabiltyMetricsResponse.decode(response, DeliverabiltyMetricsResponse.class);
106106

107107
return newResponse;
@@ -122,7 +122,7 @@ public static DeliverabiltyMetricsResponse getDeliverabilityMetricsByWatchedDoma
122122
Endpoint ep = new Endpoint("metrics/deliverability/watched-domain");
123123
ep.addCommonParams(from, to, domains, campaigns, templates, metrics, timezone, limit, orderBy);
124124

125-
Response response = conn.get(ep.toString());
125+
Response response = conn.get(ep);
126126
DeliverabiltyMetricsResponse newResponse = DeliverabiltyMetricsResponse.decode(response, DeliverabiltyMetricsResponse.class);
127127

128128
return newResponse;
@@ -144,7 +144,7 @@ public static DeliverabiltyMetricsResponse getTimeSeriesMetrics(
144144
ep.addParam("precision", precision);
145145
ep.addCommonParams(from, to, domains, campaigns, templates, metrics, timezone, null, null);
146146

147-
Response response = conn.get(ep.toString());
147+
Response response = conn.get(ep);
148148
DeliverabiltyMetricsResponse newResponse = DeliverabiltyMetricsResponse.decode(response, DeliverabiltyMetricsResponse.class);
149149

150150
return newResponse;
@@ -165,7 +165,7 @@ public static DeliverabiltyMetricsResponse getBounceReasonMetrics(
165165

166166
ep.addCommonParams(from, to, domains, campaigns, templates, metrics, timezone, limit, null);
167167

168-
Response response = conn.get(ep.toString());
168+
Response response = conn.get(ep);
169169
DeliverabiltyMetricsResponse newResponse = DeliverabiltyMetricsResponse.decode(response, DeliverabiltyMetricsResponse.class);
170170

171171
return newResponse;
@@ -186,7 +186,7 @@ public static DeliverabiltyMetricsResponse getBounceReasonMetricsByDomain(
186186

187187
ep.addCommonParams(from, to, domains, campaigns, templates, metrics, timezone, limit, null);
188188

189-
Response response = conn.get(ep.toString());
189+
Response response = conn.get(ep);
190190
DeliverabiltyMetricsResponse newResponse = DeliverabiltyMetricsResponse.decode(response, DeliverabiltyMetricsResponse.class);
191191

192192
return newResponse;
@@ -207,7 +207,7 @@ public static DeliverabiltyMetricsResponse getBounceClassificationMetrics(
207207

208208
ep.addCommonParams(from, to, domains, campaigns, templates, metrics, timezone, limit, null);
209209

210-
Response response = conn.get(ep.toString());
210+
Response response = conn.get(ep);
211211
DeliverabiltyMetricsResponse newResponse = DeliverabiltyMetricsResponse.decode(response, DeliverabiltyMetricsResponse.class);
212212

213213
return newResponse;
@@ -227,7 +227,7 @@ public static DeliverabiltyMetricsResponse getRejectionReasonMetrics(
227227

228228
ep.addCommonParams(from, to, domains, campaigns, templates, null, timezone, limit, null);
229229

230-
Response response = conn.get(ep.toString());
230+
Response response = conn.get(ep);
231231
DeliverabiltyMetricsResponse newResponse = DeliverabiltyMetricsResponse.decode(response, DeliverabiltyMetricsResponse.class);
232232

233233
return newResponse;
@@ -247,7 +247,7 @@ public static DeliverabiltyMetricsResponse getRejectionReasonMetricsByDomain(
247247

248248
ep.addCommonParams(from, to, domains, campaigns, templates, null, timezone, limit, null);
249249

250-
Response response = conn.get(ep.toString());
250+
Response response = conn.get(ep);
251251
DeliverabiltyMetricsResponse newResponse = DeliverabiltyMetricsResponse.decode(response, DeliverabiltyMetricsResponse.class);
252252

253253
return newResponse;
@@ -267,7 +267,7 @@ public static DeliverabiltyMetricsResponse getDelayReasonMetrics(
267267

268268
ep.addCommonParams(from, to, domains, campaigns, templates, null, timezone, limit, null);
269269

270-
Response response = conn.get(ep.toString());
270+
Response response = conn.get(ep);
271271
DeliverabiltyMetricsResponse newResponse = DeliverabiltyMetricsResponse.decode(response, DeliverabiltyMetricsResponse.class);
272272

273273
return newResponse;
@@ -287,7 +287,7 @@ public static DeliverabiltyMetricsResponse getDelayReasonMetricsByDomain(
287287

288288
ep.addCommonParams(from, to, domains, campaigns, templates, null, timezone, limit, null);
289289

290-
Response response = conn.get(ep.toString());
290+
Response response = conn.get(ep);
291291
DeliverabiltyMetricsResponse newResponse = DeliverabiltyMetricsResponse.decode(response, DeliverabiltyMetricsResponse.class);
292292

293293
return newResponse;
@@ -307,7 +307,7 @@ public static DeliverabiltyMetricsResponse getEngagementDetails(
307307

308308
ep.addCommonParams(from, to, null, campaigns, templates, metrics, timezone, limit, null);
309309

310-
Response response = conn.get(ep.toString());
310+
Response response = conn.get(ep);
311311
DeliverabiltyMetricsResponse newResponse = DeliverabiltyMetricsResponse.decode(response, DeliverabiltyMetricsResponse.class);
312312

313313
return newResponse;
@@ -325,7 +325,7 @@ public static DeliverabiltyMetricsResponse getDeliveriesByAttempt(
325325
Endpoint ep = new Endpoint("metrics/deliverability/attempt");
326326
ep.addCommonParams(from, to, domains, campaigns, templates, null, timezone, null, null);
327327

328-
Response response = conn.get(ep.toString());
328+
Response response = conn.get(ep);
329329
DeliverabiltyMetricsResponse newResponse = DeliverabiltyMetricsResponse.decode(response, DeliverabiltyMetricsResponse.class);
330330

331331
return newResponse;
@@ -337,7 +337,7 @@ public static CampaignListResponse getCampaignsList(IRestConnection conn, String
337337
ep.addParam("match", match);
338338
ep.addParam("limit", limit);
339339

340-
Response response = conn.get(ep.toString());
340+
Response response = conn.get(ep);
341341
CampaignListResponse newResponse = CampaignListResponse.decode(response, CampaignListResponse.class);
342342

343343
return newResponse;
@@ -349,7 +349,7 @@ public static DomainListResponse getDomainsList(IRestConnection conn, String mat
349349
ep.addParam("match", match);
350350
ep.addParam("limit", limit);
351351

352-
Response response = conn.get(ep.toString());
352+
Response response = conn.get(ep);
353353
DomainListResponse newResponse = DomainListResponse.decode(response, DomainListResponse.class);
354354

355355
return newResponse;

libs/sparkpost-lib/src/main/java/com/sparkpost/resources/ResourceRecipientLists.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,29 +24,29 @@ public static Response create(IRestConnection conn, Integer maxNumberOfRecipient
2424
String json = recipientList.toJson();
2525
Endpoint ep = new Endpoint("recipient-lists");
2626
ep.addParam("num_rcpt_errors", maxNumberOfRecipientErrors);
27-
Response response = conn.post(ep.toString(), json);
27+
Response response = conn.post(ep, json);
2828
return response;
2929
}
3030

3131
public static RecipientListRetrieveResponse retrieve(IRestConnection conn, String recipientListId, Boolean showRecipients) throws SparkPostException {
3232
Endpoint ep = new Endpoint("recipient-lists/" + recipientListId);
3333
ep.addParam("show_recipients", showRecipients);
34-
Response response = conn.get(ep.toString());
34+
Response response = conn.get(ep);
3535

3636
RecipientListRetrieveResponse retrieveResponse = RecipientListRetrieveResponse.decode(response, RecipientListRetrieveResponse.class);
3737
return retrieveResponse;
3838
}
3939

4040
public static RecipientListsListAllResponse listAll(IRestConnection conn) throws SparkPostException {
4141
Endpoint ep = new Endpoint("recipient-lists");
42-
Response response = conn.get(ep.toString());
42+
Response response = conn.get(ep);
4343
RecipientListsListAllResponse listResponse = RecipientListsListAllResponse.decode(response, RecipientListsListAllResponse.class);
4444
return listResponse;
4545
}
4646

4747
public static Response delete(IRestConnection conn, String recipientListId) throws SparkPostException {
4848
Endpoint ep = new Endpoint("recipient-lists/" + recipientListId);
49-
Response response = conn.delete(ep.toString());
49+
Response response = conn.delete(ep);
5050
return response;
5151
}
5252
}

libs/sparkpost-lib/src/main/java/com/sparkpost/resources/ResourceSendingDomains.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,36 +23,36 @@ public static Response create(IRestConnection conn, SendingDomain domain) throws
2323

2424
String json = domain.toJson();
2525
Endpoint ep = new Endpoint("sending-domains");
26-
Response response = conn.post(ep.toString(), json);
26+
Response response = conn.post(ep, json);
2727
return response;
2828
}
2929

3030
public static Response retrieve(IRestConnection conn, String domainName) throws SparkPostException {
3131

3232
Endpoint ep = new Endpoint("sending-domains/" + domainName);
33-
Response response = conn.get(ep.toString());
33+
Response response = conn.get(ep);
3434
return response;
3535
}
3636

3737
public static Response list(IRestConnection conn) throws SparkPostException {
3838
Endpoint ep = new Endpoint("sending-domains/");
39-
Response response = conn.get(ep.toString());
39+
Response response = conn.get(ep);
4040
return response;
4141
}
4242

4343
public static Response update(IRestConnection conn, String domainName, SendingDomain domain) throws SparkPostException {
4444

4545
String json = domain.toJson();
4646
Endpoint ep = new Endpoint("sending-domains/" + domainName);
47-
Response response = conn.put(ep.toString(), json);
47+
Response response = conn.put(ep, json);
4848
return response;
4949
}
5050

5151
public static Response verify(IRestConnection conn, String domainName, VerifyAttributes verify) throws SparkPostException {
5252

5353
String json = verify.toJson();
5454
Endpoint ep = new Endpoint("sending-domains/" + domainName + "/verify");
55-
Response response = conn.post(ep.toString(), json);
55+
Response response = conn.post(ep, json);
5656
return response;
5757
}
5858
}

libs/sparkpost-lib/src/main/java/com/sparkpost/resources/ResourceSuppressionList.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ public static Response insertOrUpdate(IRestConnection conn, String email, final
2626

2727
String json = copy.toJson();
2828
Endpoint ep = new Endpoint("suppression-list/" + email);
29-
Response response = conn.put(ep.toString(), json);
29+
Response response = conn.put(ep, json);
3030
return response;
3131
}
3232

3333
public static Response insertOrUpdateBulk(IRestConnection conn, SuppressionList suppressionList) throws SparkPostException {
3434

3535
String json = suppressionList.toJson();
3636
Endpoint ep = new Endpoint("suppression-list/");
37-
return conn.put(ep.toString(), json);
37+
return conn.put(ep, json);
3838
}
3939

4040
public static Response search(IRestConnection conn, String to, String from, String types, String limit) throws SparkPostException {
@@ -44,20 +44,20 @@ public static Response search(IRestConnection conn, String to, String from, Stri
4444
ep.addParam("from", from);
4545
ep.addParam("types", types);
4646
ep.addParam("limit", limit);
47-
Response response = conn.get(ep.toString());
47+
Response response = conn.get(ep);
4848
return response;
4949
}
5050

5151
public static Response check(IRestConnection conn, String email) throws SparkPostException {
5252

5353
Endpoint ep = new Endpoint("suppression-list/" + email);
54-
Response response = conn.get(ep.toString());
54+
Response response = conn.get(ep);
5555
return response;
5656
}
5757

5858
public static Response remove(IRestConnection conn, String email) throws SparkPostException {
5959
Endpoint ep = new Endpoint("suppression-list/" + email);
60-
Response response = conn.delete(ep.toString());
60+
Response response = conn.delete(ep);
6161
return response;
6262
}
6363
}

libs/sparkpost-lib/src/main/java/com/sparkpost/resources/ResourceTemplates.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public static TemplateCreateResponse create(IRestConnection conn, TemplateAttrib
2525

2626
String json = tpl.toJson();
2727
Endpoint ep = new Endpoint("templates");
28-
Response response = conn.post(ep.toString(), json);
28+
Response response = conn.post(ep, json);
2929
TemplateCreateResponse createResponse = TemplateCreateResponse.decode(response, TemplateCreateResponse.class);
3030
return createResponse;
3131
}
@@ -34,15 +34,15 @@ public static TemplateRetrieveResponse retrieve(IRestConnection conn, String id,
3434

3535
Endpoint ep = new Endpoint("templates/" + id);
3636
ep.addParam("draft", draft);
37-
Response response = conn.get(ep.toString());
37+
Response response = conn.get(ep);
3838

3939
TemplateRetrieveResponse templateResponse = (TemplateRetrieveResponse) TemplateItemResponse.decode(response, TemplateRetrieveResponse.class);
4040
return templateResponse;
4141
}
4242

4343
public static TemplateListResponse listAll(IRestConnection conn) throws SparkPostException {
4444
Endpoint ep = new Endpoint("templates/");
45-
Response response = conn.get(ep.toString());
45+
Response response = conn.get(ep);
4646
TemplateListResponse listResponse = (TemplateListResponse) TemplateListResponse.decode(response, TemplateListResponse.class);
4747
return listResponse;
4848
}
@@ -52,7 +52,7 @@ public static Response update(IRestConnection conn, String id, Boolean updatePub
5252
Endpoint ep = new Endpoint("templates/" + id);
5353
ep.addParam("update_published", updatePublished);
5454
String json = tpl.toJson();
55-
Response response = conn.put(ep.toString(), json);
55+
Response response = conn.put(ep, json);
5656
return response;
5757
}
5858

@@ -61,14 +61,14 @@ public static TemplatePreviewResponse preview(IRestConnection conn, String id, B
6161
Endpoint ep = new Endpoint("templates/" + id + "/preview");
6262
ep.addParam("draft", draft);
6363
String json = subst.toJson();
64-
Response response = conn.post(ep.toString(), json);
64+
Response response = conn.post(ep, json);
6565
TemplatePreviewResponse newResponse = TemplatePreviewResponse.decode(response, TemplatePreviewResponse.class);
6666
return newResponse;
6767
}
6868

6969
public static Response delete(IRestConnection conn, String id) throws SparkPostException {
7070
Endpoint ep = new Endpoint("templates/" + id);
71-
Response response = conn.delete(ep.toString());
71+
Response response = conn.delete(ep);
7272
// Delete response is an empty dictionary so no need to deserialize the JSON object.
7373
return response;
7474
}

libs/sparkpost-lib/src/main/java/com/sparkpost/resources/ResourceTransmissions.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,15 @@ private static <T extends TransmissionBase> TransmissionCreateResponse createTra
4040
Endpoint ep = new Endpoint("transmissions");
4141
ep.addParam("num_rcpt_errors", numRcptErrors);
4242
String json = trans.toJson();
43-
Response response = conn.post(ep.toString(), json);
43+
Response response = conn.post(ep, json);
4444

4545
TransmissionCreateResponse newResult = TransmissionCreateResponse.decode(response, TransmissionCreateResponse.class);
4646
return newResult;
4747
}
4848

4949
public static TransmissionRetrieveResults retrieve(IRestConnection conn, String id) throws SparkPostException {
5050
Endpoint ep = new Endpoint("transmissions/" + id);
51-
Response response = conn.get(ep.toString());
51+
Response response = conn.get(ep);
5252

5353
TransmissionRetrieveResults newResult = TransmissionRetrieveResults.decode(response, TransmissionRetrieveResults.class);
5454
return newResult;
@@ -59,7 +59,7 @@ public static TransmissionListResponse list(IRestConnection conn, String campaig
5959
Endpoint ep = new Endpoint("transmissions");
6060
ep.addParam("campaign_id", campaignId);
6161
ep.addParam("template_id", templateId);
62-
Response response = conn.get(ep.toString());
62+
Response response = conn.get(ep);
6363

6464
TransmissionListResponse transmissionResponse = TransmissionListResponse.decode(response, TransmissionListResponse.class);
6565
return transmissionResponse;

0 commit comments

Comments
 (0)