Skip to content
This repository was archived by the owner on May 16, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -162,5 +162,11 @@
<artifactId>gson</artifactId>
<version>${gson.version}</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.4</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
44 changes: 4 additions & 40 deletions src/main/java/net/gpedro/integrations/slack/SlackAction.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package net.gpedro.integrations.slack;

import com.google.gson.JsonObject;
import lombok.Data;
import lombok.experimental.Accessors;

/**
* @author Galimov Ruslan
*/
@Data
@Accessors(chain = true)
public class SlackAction {

private static final String NAME = "name";
Expand Down Expand Up @@ -32,46 +36,6 @@ public SlackAction(String name, String text, SlackActionType type, String value)
this.value = value;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getText() {
return text;
}

public void setText(String text) {
this.text = text;
}

public SlackActionType getType() {
return type;
}

public void setType(SlackActionType type) {
this.type = type;
}

public String getValue() {
return value;
}

public void setValue(String value) {
this.value = value;
}

public SlackActionStyle getStyle() {
return style;
}

public void setStyle(SlackActionStyle style) {
this.style = style;
}

public JsonObject toJson() {
final JsonObject data = new JsonObject();
data.addProperty(NAME, name);
Expand Down
100 changes: 4 additions & 96 deletions src/main/java/net/gpedro/integrations/slack/SlackAttachment.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;
import lombok.Data;
import lombok.experimental.Accessors;

/**
* Represents an attachment in a slack webhook JSON message.
Expand All @@ -17,6 +19,8 @@
* @author David Webb
* @author Galimov Ruslan
*/
@Data
@Accessors(chain = true)
public class SlackAttachment {

private static final String HEX_REGEX = "^([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$";
Expand Down Expand Up @@ -148,102 +152,6 @@ public SlackAttachment setColor(String color) {
return this;
}

public SlackAttachment setFallback(String fallback) {
this.fallback = fallback;

return this;
}

public SlackAttachment setCallbackId(String callbackId) {
this.callbackId = callbackId;

return this;
}

public SlackAttachment setFields(List<SlackField> fields) {
this.fields = fields;

return this;
}

public SlackAttachment setPretext(String pretext) {
this.pretext = pretext;

return this;
}

public SlackAttachment setText(String text) {
this.text = text;

return this;
}

public SlackAttachment setAuthorName(String authorName) {
this.authorName = authorName;

return this;
}

public SlackAttachment setAuthorLink(String authorLink) {
this.authorLink = authorLink;

return this;
}

public SlackAttachment setAuthorIcon(String authorIcon) {
this.authorIcon = authorIcon;

return this;
}

public SlackAttachment setTitle(String title) {
this.title = title;

return this;
}

public SlackAttachment setTitleLink(String titleLink) {
this.titleLink = titleLink;

return this;
}

public SlackAttachment setImageUrl(String imageUrl) {
this.imageUrl = imageUrl;

return this;
}

public SlackAttachment setThumbUrl(String thumbUrl) {
this.thumbUrl = thumbUrl;

return this;
}

public SlackAttachment setTimestamp(Long timestamp) {
this.timestamp = timestamp;

return this;
}

public SlackAttachment setTimestamp(Date date) {
this.timestamp = date.getTime() / 1000;

return this;
}

public SlackAttachment setFooter(String footer) {
this.footer = footer;

return this;
}

public SlackAttachment setFooterIcon(String footerIcon) {
this.footerIcon = footerIcon;

return this;
}

public JsonObject toJson() {
JsonObject data = new JsonObject();

Expand Down
63 changes: 4 additions & 59 deletions src/main/java/net/gpedro/integrations/slack/SlackField.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@

import java.util.ArrayList;
import java.util.List;
import lombok.Data;
import lombok.experimental.Accessors;

@Data
@Accessors(chain = true)
public class SlackField {

private static final String TITLE = "title";
Expand All @@ -33,10 +37,6 @@ public void addAllowedMarkdown(String field) {
}
}

public boolean isShorten() {
return shorten;
}

private JsonArray prepareMarkdown() {
JsonArray data = new JsonArray();
for (String item : this.allowMarkdown) {
Expand All @@ -46,27 +46,6 @@ private JsonArray prepareMarkdown() {
return data;
}

public void setAllowedMarkdown(ArrayList<String> allowMarkdown) {
if (allowMarkdown != null) {
this.allowMarkdown = allowMarkdown;
}
}

public SlackField setShorten(boolean shorten) {
this.shorten = shorten;
return this;
}

public SlackField setTitle(String title) {
this.title = title;
return this;
}

public SlackField setValue(String value) {
this.value = value;
return this;
}

public JsonObject toJson() {
final JsonObject data = new JsonObject();
data.addProperty(TITLE, title);
Expand All @@ -78,38 +57,4 @@ public JsonObject toJson() {

return data;
}

@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;

final SlackField that = (SlackField) o;

if (shorten != that.shorten)
return false;
if (allowMarkdown != null ? !allowMarkdown.equals(that.allowMarkdown) : that.allowMarkdown != null)
return false;
if (title != null ? !title.equals(that.title) : that.title != null)
return false;
return !(value != null ? !value.equals(that.value) : that.value != null);

}

@Override
public int hashCode() {
int result = allowMarkdown != null ? allowMarkdown.hashCode() : 0;
result = 31 * result + (shorten ? 1 : 0);
result = 31 * result + (title != null ? title.hashCode() : 0);
result = 31 * result + (value != null ? value.hashCode() : 0);
return result;
}

@Override
public String toString() {
return "SlackField{" + "allowMarkdown=" + allowMarkdown + ", shorten=" + shorten + ", title='" + title + '\''
+ ", value='" + value + '\'' + '}';
}
}
76 changes: 4 additions & 72 deletions src/main/java/net/gpedro/integrations/slack/SlackMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@

import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import lombok.Data;
import lombok.experimental.Accessors;

@Data
@Accessors(chain = true)
public class SlackMessage {

private static final String CHANNEL = "channel";
Expand Down Expand Up @@ -115,12 +119,6 @@ public SlackMessage removeAttachment(int index) {
return this;
}

public SlackMessage setAttachments(List<SlackAttachment> attach) {
this.attach = attach;

return this;
}

public SlackMessage setChannel(String channel) {
if (channel != null) {
this.channel = channel;
Expand Down Expand Up @@ -159,70 +157,4 @@ public SlackMessage setUsername(String username) {

return this;
}

public SlackMessage setUnfurlMedia(boolean unfurlMedia) {
this.unfurlMedia = unfurlMedia;

return this;
}

public SlackMessage setUnfurlLinks(boolean unfurlLinks) {
this.unfurlLinks = unfurlLinks;

return this;
}

public SlackMessage setLinkNames(boolean linkNames) {
this.linkNames = linkNames;

return this;
}

@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;

final SlackMessage that = (SlackMessage) o;

if (unfurlMedia != that.unfurlMedia)
return false;
if (unfurlLinks != that.unfurlLinks)
return false;
if (linkNames != that.linkNames)
return false;
if (attach != null ? !attach.equals(that.attach) : that.attach != null)
return false;
if (channel != null ? !channel.equals(that.channel) : that.channel != null)
return false;
if (icon != null ? !icon.equals(that.icon) : that.icon != null)
return false;
if (text != null ? !text.equals(that.text) : that.text != null)
return false;

return !(username != null ? !username.equals(that.username) : that.username != null);

}

@Override
public int hashCode() {
int result = attach != null ? attach.hashCode() : 0;
result = 31 * result + (channel != null ? channel.hashCode() : 0);
result = 31 * result + (icon != null ? icon.hashCode() : 0);
result = 31 * result + (text != null ? text.hashCode() : 0);
result = 31 * result + (username != null ? username.hashCode() : 0);
result = 31 * result + (unfurlMedia ? 1 : 0);
result = 31 * result + (unfurlLinks ? 1 : 0);
result = 31 * result + (linkNames ? 1 : 0);
return result;
}

@Override
public String toString() {
return "SlackMessage{" + "attach=" + attach + ", channel='" + channel + '\'' + ", icon='" + icon + '\''
+ ", slackMessage=" + slackMessage + ", text='" + text + '\'' + ", username='" + username + '\''
+ ", unfurlMedia=" + unfurlMedia + ", unfurlLinks=" + unfurlLinks + ", linkNames=" + linkNames + '}';
}
}