com.mailgun.model.webhooks.WebhookRequest Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mailgun-java Show documentation
Show all versions of mailgun-java Show documentation
The Mailgun SDK for Java enables Java developers to work with Mailgun API
efficiently.
The newest version!
package com.mailgun.model.webhooks;
import com.mailgun.enums.WebhookName;
import feign.form.FormProperty;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Singular;
import lombok.ToString;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import java.util.Set;
import static com.mailgun.util.Constants.FIELD_CANNOT_BE_NULL_OR_EMPTY;
/**
*
* Webhook request.
*
*
* @see Webhooks
*/
@Getter
@ToString
@EqualsAndHashCode
@Builder
public class WebhookRequest {
/**
*
* Name of the webhook.
*
*/
@FormProperty("id")
String webhookName;
/**
*
* URLs for the webhook event.
* Only up to 3 URLs are supported.
*
*/
@Singular
@FormProperty("url")
Set urls;
public static WebhookRequestBuilder builder() {
return new CustomWebhookRequestBuilder();
}
private static class CustomWebhookRequestBuilder extends WebhookRequestBuilder {
public WebhookRequest build() {
if (CollectionUtils.isEmpty(super.urls)) {
throw new IllegalArgumentException(String.format(FIELD_CANNOT_BE_NULL_OR_EMPTY, "url(s)"));
}
super.urls.stream()
.filter(StringUtils::isNotBlank)
.findFirst()
.orElseThrow(() -> new IllegalArgumentException(String.format(FIELD_CANNOT_BE_NULL_OR_EMPTY, "url(s)")));
return super.build();
}
}
public static class WebhookRequestBuilder {
/**
*
* Name of the webhook.
*
*
* Note: When adding a CLICKED
or OPENED
webhook, ensure that you also have tracking enabled.
*
*
* @param webhookName Name of the webhook {@link WebhookName}.
* @return Returns a reference to this object.
*/
public WebhookRequest.WebhookRequestBuilder webhookName(WebhookName webhookName) {
this.webhookName = webhookName.getValue();
return this;
}
}
}