Skip to content

Commit 9de3a84

Browse files
author
Chris Wilson
committed
Adds ability to set sub account
1 parent e9d1796 commit 9de3a84

File tree

4 files changed

+42
-0
lines changed

4 files changed

+42
-0
lines changed

libs/sparkpost-lib/src/main/java/com/sparkpost/model/WebhookDescription.java

+3
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,8 @@ public class WebhookDescription extends Base {
3838
value = "Restrict which inbound messages will be relayed to the target",
3939
sample = {"\"match\": { \"protocol\": \"SMTP\", \"domain\": \"replies.customer.example\" }"})
4040
private Match match;
41+
42+
@Description(value = "Describes status of the webhook")
43+
private Boolean active;
4144

4245
}

libs/sparkpost-lib/src/main/java/com/sparkpost/transport/IRestConnection.java

+10
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,22 @@ public interface IRestConnection {
1111

1212
String SPC_US_ENDPOINT = "https://api.sparkpost.com/api/v1";
1313

14+
String SUBACCOUNT_HEADER = "X-MSYS-SUBACCOUNT";
15+
1416
/**
1517
* Default endpoint to use for connections :
1618
* https://api.sparkpost.com/api/v1
1719
*/
1820
String defaultApiEndpoint = SPC_US_ENDPOINT;
1921

22+
/**
23+
* @param key
24+
* The HTTP header key
25+
* @param value
26+
* The HTTP header value
27+
*/
28+
void addHeader(String key, String value);
29+
2030
/**
2131
* Perform an HTTP GET request. This method throws an exception if the
2232
* server returns anything else than a 200.

libs/sparkpost-lib/src/main/java/com/sparkpost/transport/RestConnection.java

+19
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
import java.net.MalformedURLException;
1111
import java.net.ProtocolException;
1212
import java.net.URL;
13+
import java.util.HashMap;
14+
import java.util.Map;
15+
import java.util.Map.Entry;
16+
import java.util.Set;
1317

1418
import org.apache.commons.codec.binary.Base64;
1519
import org.apache.commons.lang3.StringUtils;
@@ -48,6 +52,8 @@ public class RestConnection implements IRestConnection {
4852
@Getter
4953
private final String baseUrl;
5054

55+
private final Map<String, String> extraHeaders = new HashMap<String, String>();
56+
5157
/**
5258
* Supported HTTP methods
5359
*/
@@ -417,6 +423,13 @@ private Response doHttpMethod(Endpoint endpoint, Method method, String data, Res
417423
String path = endpoint.toString();
418424
response.setRequest(path);
419425
conn = createConnectionObject(path, method);
426+
427+
// Add additional request headers
428+
Set<Entry<String, String>> entrySet = this.extraHeaders.entrySet();
429+
for (Entry<String, String> entry : entrySet) {
430+
conn.setRequestProperty(entry.getKey(), entry.getValue());
431+
}
432+
420433
sendRequest(conn, data, response);
421434
receiveResponse(conn, response);
422435

@@ -538,4 +551,10 @@ public Response delete(Endpoint endpoint) throws SparkPostException {
538551
Response response = new Response();
539552
return doHttpMethod(endpoint, Method.DELETE, null, response);
540553
}
554+
555+
@Override
556+
public void addHeader(String key, String value) {
557+
this.extraHeaders.put(key, value);
558+
559+
}
541560
}

libs/sparkpost-lib/src/test/java/com/sparkpost/testhelpers/StubRestConnection.java

+10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11

22
package com.sparkpost.testhelpers;
33

4+
import java.util.HashMap;
5+
import java.util.Map;
6+
47
import com.sparkpost.exception.SparkPostException;
58
import com.sparkpost.model.responses.Response;
69
import com.sparkpost.resources.Endpoint;
@@ -11,6 +14,8 @@ public class StubRestConnection implements IRestConnection {
1114
private String path;
1215

1316
private Endpoint endpoint;
17+
18+
private final Map<String, String> extraHeaders = new HashMap<String, String>();
1419

1520
private String json;
1621

@@ -144,4 +149,9 @@ public boolean wasDelete() {
144149
return this.wasDelete;
145150
}
146151

152+
@Override
153+
public void addHeader(String key, String value) {
154+
this.extraHeaders.put(key, value);
155+
156+
}
147157
}

0 commit comments

Comments
 (0)