Skip to content

Commit

Permalink
webhook endpoint added
Browse files Browse the repository at this point in the history
  • Loading branch information
ibalosh committed Nov 5, 2019
1 parent 27a0b1b commit 35a4e34
Show file tree
Hide file tree
Showing 17 changed files with 413 additions and 8 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
</developers>

<properties>
<postmark.version>1.2.1</postmark.version>
<postmark.version>1.2.2</postmark.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<jackson.minimum.version>2.9.7</jackson.minimum.version>
<jackson.version>2.9.9</jackson.version>
<jackson.version>2.10.0</jackson.version>
<junit.jupiter.version>5.0.0-M4</junit.jupiter.version>
<junit.platform.version>1.0.0-M4</junit.platform.version>
</properties>
Expand Down
35 changes: 35 additions & 0 deletions src/main/java/com/wildbit/java/postmark/client/ApiClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import com.wildbit.java.postmark.client.data.model.stats.*;
import com.wildbit.java.postmark.client.data.model.templates.*;
import com.wildbit.java.postmark.client.data.model.triggers.*;
import com.wildbit.java.postmark.client.data.model.webhooks.Webhook;
import com.wildbit.java.postmark.client.data.model.webhooks.Webhooks;
import com.wildbit.java.postmark.client.exception.PostmarkException;

import javax.ws.rs.core.MultivaluedMap;
Expand All @@ -38,6 +40,7 @@ public class ApiClient extends BaseApiClient {
private final String triggerTagsEndpoint = "/triggers/tags/";
private final String triggerInboundRulesEndpoint = "/triggers/inboundRules/";
private final String sendingEndpoint = "/email/";
private final String webhooksEndpoint = "/webhooks/";

public ApiClient(String baseUrl, MultivaluedMap<String, Object> headers) {
super(baseUrl,headers);
Expand Down Expand Up @@ -384,4 +387,36 @@ public InboundRules getInboundRules(Parameters parameters) throws PostmarkExcept
return dataHandler.fromJson(response, InboundRules.class);
}

/*
Webhooks endpoints
*/

public Webhooks getWebhooks() throws PostmarkException, IOException {
return getWebhooks(Parameters.init());
}

public Webhooks getWebhooks(Parameters parameters) throws PostmarkException, IOException {
String response = execute(HttpClient.REQUEST_TYPES.GET, getEndpointUrl(webhooksEndpoint + parameters));
return dataHandler.fromJson(response, Webhooks.class);
}

public Webhook getWebhook(Integer id) throws PostmarkException, IOException {
String response = execute(HttpClient.REQUEST_TYPES.GET, getEndpointUrl(webhooksEndpoint + id));
return dataHandler.fromJson(response, Webhook.class);
}

public Webhook createWebhook(Webhook data) throws PostmarkException, IOException {
String response = execute(HttpClient.REQUEST_TYPES.POST, getEndpointUrl(webhooksEndpoint), data);
return dataHandler.fromJson(response, Webhook.class);
}

public Webhook setWebhook(Integer id, Webhook data) throws PostmarkException, IOException {
String response = execute(HttpClient.REQUEST_TYPES.PUT, getEndpointUrl(webhooksEndpoint + id), data);
return dataHandler.fromJson(response, Webhook.class);
}

public String deleteWebhook(Integer id) throws PostmarkException, IOException {
return execute(HttpClient.REQUEST_TYPES.DELETE, getEndpointUrl(webhooksEndpoint + id));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public <T> T fromJson(String response, Class<T> valueType) throws IOException {
* @return String object converted to requested object
* @throws IOException in case converting String to Object fails
*/
public <T> T fromJson(String response, TypeReference valueType) throws IOException {
public <T> T fromJson(String response, TypeReference<T> valueType) throws IOException {
return this.mapper.readValue(response, valueType);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.wildbit.java.postmark.client.data.model.webhooks;

public class HttpAuth {
private String username;
private String password;

public HttpAuth() {
}

public HttpAuth(String username, String password) {
this.username = username;
this.password = password;
}

public String getUsername() {
return username;
}

public void setUsername(String username) {
this.username = username;
}

public String getPassword() {
return password;
}

public void setPassword(String password) {
this.password = password;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package com.wildbit.java.postmark.client.data.model.webhooks;

import com.wildbit.java.postmark.client.data.model.message.Header;

import java.util.ArrayList;
import java.util.List;

public class Webhook {
private Integer id;
private String url;
private HttpAuth httpAuth;
private List<Header> httpHeaders;
private String messageStream;
private WebhookTriggers triggers;

public Webhook() {
}

public Webhook(String url) {
this.url = url;
}

public Webhook(String url, WebhookTriggers triggers) {
this.url = url;
this.triggers = triggers;
}

public Webhook(String url, HttpAuth httpAuth, WebhookTriggers triggers) {
this.url = url;
this.triggers = triggers;
this.httpAuth = httpAuth;
}

public Webhook(String url, HttpAuth httpAuth, WebhookTriggers triggers, List<Header> httpHeaders) {
this.url = url;
this.triggers = triggers;
this.httpAuth = httpAuth;
this.httpHeaders = httpHeaders;
}

public void addHeader(String name, String value) {
if (this.httpHeaders == null) {
setHttpHeaders(new ArrayList<>());
}
this.httpHeaders.add(new Header(name,value));
}

public void clearHeaders() {
if (this.httpHeaders != null) {
this.httpHeaders.clear();
}
}

public Integer getId() {
return id;
}

public void setId(Integer id) {
this.id = id;
}

public String getUrl() {
return url;
}

public void setUrl(String url) {
this.url = url;
}

public HttpAuth getHttpAuth() {
return httpAuth;
}

public void setHttpAuth(HttpAuth httpAuth) {
this.httpAuth = httpAuth;
}

public List<Header> getHttpHeaders() {
return httpHeaders;
}

public void setHttpHeaders(List<Header> httpHeaders) {
this.httpHeaders = httpHeaders;
}

public String getMessageStream() {
return messageStream;
}

public void setMessageStream(String messageStream) {
this.messageStream = messageStream;
}

public WebhookTriggers getTriggers() {
return triggers;
}

public void setTriggers(WebhookTriggers triggers) {
this.triggers = triggers;
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package com.wildbit.java.postmark.client.data.model.webhooks;

import com.wildbit.java.postmark.client.data.model.webhooks.triggers.*;

public class WebhookTriggers {
private OpenWebhookTrigger open;
private WebhookTrigger click;
private WebhookTrigger delivery;
private BounceWebhookTrigger bounce;
private SpamWebhookTrigger spamComplaint;

public WebhookTriggers() {
this.open = new OpenWebhookTrigger(false);
this.click = new WebhookTrigger(false);
this.delivery = new WebhookTrigger(false);
this.bounce = new BounceWebhookTrigger(false);
this.spamComplaint = new SpamWebhookTrigger(false);
}

public WebhookTriggers(boolean openEnabled, boolean clickEnabled) {
this.open = new OpenWebhookTrigger(openEnabled);
this.click = new WebhookTrigger(clickEnabled);
}

public WebhookTriggers(boolean openEnabled, boolean clickEnabled,
boolean bounceEnabled) {
this.open = new OpenWebhookTrigger(openEnabled);
this.click = new WebhookTrigger(clickEnabled);
this.bounce = new BounceWebhookTrigger(bounceEnabled);
}

public WebhookTriggers(boolean openEnabled, boolean clickEnabled,
boolean bounceEnabled, boolean spamComplaintEnabled, boolean deliveryEnabled) {
this.open = new OpenWebhookTrigger(openEnabled);
this.click = new WebhookTrigger(clickEnabled);
this.delivery = new WebhookTrigger(deliveryEnabled);
this.bounce = new BounceWebhookTrigger(bounceEnabled);
this.spamComplaint = new SpamWebhookTrigger(spamComplaintEnabled);
}

public WebhookTriggers(OpenWebhookTrigger open, WebhookTrigger click, WebhookTrigger delivery,
BounceWebhookTrigger bounce, SpamWebhookTrigger spamComplaint) {
this.open = open;
this.click = click;
this.delivery = delivery;
this.bounce = bounce;
this.spamComplaint = spamComplaint;
}

public OpenWebhookTrigger getOpen() {
return open;
}

public void setOpen(OpenWebhookTrigger open) {
this.open = open;
}

public WebhookTrigger getClick() {
return click;
}

public void setClick(WebhookTrigger click) {
this.click = click;
}

public WebhookTrigger getDelivery() {
return delivery;
}

public void setDelivery(WebhookTrigger delivery) {
this.delivery = delivery;
}

public BounceWebhookTrigger getBounce() {
return bounce;
}

public void setBounce(BounceWebhookTrigger bounce) {
this.bounce = bounce;
}

public SpamWebhookTrigger getSpamComplaint() {
return spamComplaint;
}

public void setSpamComplaint(SpamWebhookTrigger spamComplaint) {
this.spamComplaint = spamComplaint;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.wildbit.java.postmark.client.data.model.webhooks;

import java.util.List;

public class Webhooks {
private List<Webhook> webhooks;

public List<Webhook> getWebhooks() {
return webhooks;
}

public void setWebhooks(List<Webhook> webhooks) {
this.webhooks = webhooks;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.wildbit.java.postmark.client.data.model.webhooks;
package com.wildbit.java.postmark.client.data.model.webhooks.sent_payload;

import com.wildbit.java.postmark.client.data.model.bounces.Bounce;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.wildbit.java.postmark.client.data.model.webhooks;
package com.wildbit.java.postmark.client.data.model.webhooks.sent_payload;

import com.wildbit.java.postmark.client.data.model.messages.OutboundMessageClick;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.wildbit.java.postmark.client.data.model.webhooks;
package com.wildbit.java.postmark.client.data.model.webhooks.sent_payload;

import java.util.Date;
import java.util.HashMap;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.wildbit.java.postmark.client.data.model.webhooks;
package com.wildbit.java.postmark.client.data.model.webhooks.sent_payload;

import com.wildbit.java.postmark.client.data.model.messages.InboundMessageDetails;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.wildbit.java.postmark.client.data.model.webhooks;
package com.wildbit.java.postmark.client.data.model.webhooks.sent_payload;

import com.wildbit.java.postmark.client.data.model.messages.OutboundMessageOpen;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.wildbit.java.postmark.client.data.model.webhooks.triggers;

public class BounceWebhookTrigger extends WebhookTrigger {
private boolean includeContent;

public BounceWebhookTrigger() {
super();
}

public BounceWebhookTrigger(boolean enabled) {
super(enabled);
}

public BounceWebhookTrigger(boolean enabled, boolean includeContent) {
super(enabled);
this.includeContent = includeContent;
}

public boolean isIncludeContent() {
return includeContent;
}

public void setIncludeContent(boolean includeContent) {
this.includeContent = includeContent;
}
}
Loading

0 comments on commit 35a4e34

Please sign in to comment.